Tôi đang viết mã để phát hiện các đối tượng màu trong OpenCV 2.3. Tôi đã tìm thấy rất nhiều ví dụ về mã OpenCV không dùng nữa cho c-Inteface cũ.cvGetSpatialMoment() trong OpenCV 2.0+
Vì vậy, tôi đã sử dụng một số mã ví dụ và muốn thay đổi mã đó thành OpenCV 2.0+ Syntax. Đây là mã tôi sử dụng (nó không biên dịch!):
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 this is the first frame, we need to initialize it
if(!imgScribble)
{
imgScribble->copySize(frame); //cvCreateImage(cvGetSize(frame), 8, 3);
}
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);
// Holding the last and current ball positions
static int posX = 0;
static int posY = 0;
int lastX = posX;
int lastY = posY;
posX = moment10/area;
posY = moment01/area;
// We want to draw a line only if its a valid position
if(lastX>0 && lastY>0 && posX>0 && posY>0)
{
// Draw a yellow line from the previous point to the current point
cv::line(imgScribble, cv::Point(posX, posY), cv::Point(lastX, lastY), cv::Scalar(0,255,255), 5);
}
cv::add(frame, imgScribble, frame);
return frame;
}
Vấn đề là trình biên dịch phàn nàn về mã này:
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 bị phản đối và dự kiến cvMoments như tham số đầu tiên. Mỏ của tôi là cv :: Khoảnh khắc (mã OpenCV 2.0).
Bây giờ, vấn đề của tôi là không có cv :: GetSpatialMoments hoặc gì đó trong Cú pháp OpenCV 2.0 mới. Ít nhất tôi cũng không tìm được. Có ai có thể giúp tôi ngoài này không?
+1 Trả lời câu hỏi của bạn .... Bạn có thể thêm câu trả lời cho câu hỏi của mình ... Cảm ơn mọi cách tôi đang tìm kiếm ... – Wazzzy
@netsky: bạn có thể chuyển bản chỉnh sửa của mình thành câu trả lời không câu hỏi của bạn biến mất khỏi danh sách 'chưa được trả lời'? –
Ví dụ này rất hữu ích. Chia nhỏ mọi thứ xuống một cách độc đáo và giải thích tất cả mọi thứ http://opencv-srf.blogspot.com/2010/09/object-detection-using-color-seperation.html – hcwiley