I am writing code to detect colored objects in OpenCV 2.3. I found many examples in legacy OpenCV code for the old c-Inteface.
So, I applied some code examples and want to change it to OpenCV 2.0+ Syntax. This is the code I'm using (it does not compile!):
cv::Mat ProcessorWidget::getTresholdImage(Mat &frame)
{
cv::Mat hsvImage;
hsvImage.copySize(frame);
cv::cvtColor(frame, hsvImage, CV_BGR2HSV);
cv::Mat threshedImage;
cv::threshold(frame, threshedImage, double(ui->hTSlider_Thresh->value()), double(ui->lTSlider_Max->value()), cv::THRESH_BINARY);
return threshedImage;
}
cv::Mat ProcessorWidget::trackColoredObject(Mat& frame)
{
if(!imgScribble)
{
imgScribble->copySize(frame);
}
cv::Mat yellowThreshedImage = getTresholdImage(frame);
cv::Moments *moments = (cv::Moments*)malloc(sizeof(cv::Moments));
cv::moments(yellowThreshedImage, moments);
double moment10 = cvGetSpatialMoment(moments, 1, 0);
double moment01 = cvGetSpatialMoment(moments, 0, 1);
double area = cvGetCentralMoment(moments, 0, 0);
static int posX = 0;
static int posY = 0;
int lastX = posX;
int lastY = posY;
posX = moment10/area;
posY = moment01/area;
if(lastX>0 && lastY>0 && posX>0 && posY>0)
{
cv::line(imgScribble, cv::Point(posX, posY), cv::Point(lastX, lastY), cv::Scalar(0,255,255), 5);
}
cv::add(frame, imgScribble, frame);
return frame;
}
The problem is that the compiler complains about this code:
double moment01 = cvGetSpatialMoment(moments, 0, 1);
Error: ../QtCV/processorwidget.cpp:122: error: cannot convert 'cv::Moments*' to 'CvMoments*' for argument '1' to 'double cvGetSpatialMoment(CvMoments*, int, int)'
cvGetSpatialMoments is deprecated and expects cvMoments as the first parameter. Mine - cv :: Moments (OpenCV 2.0 code).
Now my problem is that there is no cv :: GetSpatialMoments or something in the new OpenCV 2.0 syntax. At least I did not find it. Can anyone help me here?