2012-01-17 12 views
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の構文がないことです。少なくとも私は見つけられませんでした。誰でもここで私を助けることができますか?

+0

+1あなたの質問への回答...あなたの質問への回答を追加することができます...私はそれを探していたすべての方法に感謝します.... – Wazzzy

+0

@netsky:あなたは「未回答」リストから質問が消えますか? –

+1

この例はとても役に立ちます。すべてを細かく分解し、すべて説明します http://opencv-srf.blogspot.com/2010/09/object-detection-using-color-seperation.html – hcwiley

答えて

1

オリジナルポスターは逐語的に、実際の答えに変換質問に答える:


[OK]を、私はどこか別の答えが見つかりました:

cv::Moments ourMoment; //moments variable 
ourMoment=moments(image); //calculat all the moment of image 
double moment10=moment.m10; //extract spatial moment 10 
double moment01=moment.m01; //extract spatial moment 01 
double area=moment.m00; //extract central moment 00 

トリックを行います!

関連する問題