5
OpenCV 2.3で色付きオブジェクトを検出するためのコードを書いています。私は古いc-Intefaceの廃止予定のOpenCVコードで多くの例を見つけました。OpenCV 2.0以降のcvGetSpatialMoment()
私はいくつかのコード例を採用し、OpenCV 2.0+構文に変更したいと考えています。これは、(!それがコンパイルされません)私が使用するコードです:
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;
}
問題は、コンパイラはこのコード文句ということです:
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非推奨となり、最初のパラメータとしてcvMomentsを期待しています。私はcv :: Moments(OpenCV 2.0コード)です。
私の問題は、cv :: GetSpatialMomentsや新しいOpenCV 2.0の構文がないことです。少なくとも私は見つけられませんでした。誰でもここで私を助けることができますか?
+1あなたの質問への回答...あなたの質問への回答を追加することができます...私はそれを探していたすべての方法に感謝します.... – Wazzzy
@netsky:あなたは「未回答」リストから質問が消えますか? –
この例はとても役に立ちます。すべてを細かく分解し、すべて説明します http://opencv-srf.blogspot.com/2010/09/object-detection-using-color-seperation.html – hcwiley