2012-07-22 73 views
2

我正在使用opencv 2.4.2庫檢測邊緣並在圖像上查找四邊形形狀。寄託都打算順利,直到我得到了這些編譯錯誤'cvFindContours'未在此範圍內聲明,opencv 2.4.2,編譯錯誤

../src/GoodFeaturesToDetect.cpp:198:109: error: ‘cvFindContours’ was not declared in this scope 
../src/GoodFeaturesToDetect.cpp:203:106: error: ‘cvContourPerimeter’ was not declared in this scope 
../src/GoodFeaturesToDetect.cpp:203:114: error: ‘cvApproxPoly’ was not declared in this scope 
../src/GoodFeaturesToDetect.cpp:206:64: error: ‘cvContourArea’ was not declared in this scope 

這裏是我的頭:

#include <opencv2/core/core.hpp> 
#include "opencv2/imgproc/imgproc.hpp" 
#include "opencv2/highgui/highgui.hpp" 
#include <stdlib.h> 
#include <iostream> 
#include <stdio.h> 
#include <stdlib.h> 

using namespace cv; 
using namespace std; 

void DrawLine(Mat img, Point start, Point end); 
vector<Point2f> FindCornersUsingGoodFeaturesToTrack(Mat toTrack); 
void ConnectPointsWithLine(Mat img,vector<Point2f> corners); 
void DrawQuad(Mat img, Point a, Point b, Point c, Point d); 
void DetectAndDrawQuads(Mat img); 

這裏是調用該函數(或多個)

void DetectAndDrawQuads(Mat img){ 
     CvSeq* contours; 
     CvSeq* result; 
     CvMemStorage *storage=cvCreateMemStorage(0); 
     Mat gray; 
     cvtColor(img,gray,CV_BGR2GRAY); 
     cvFindContours(&gray,storage, &contours, sizeof(CvContour),CV_RETR_LIST,CV_CHAIN_APPROX_SIMPLE, Point(0,0)); 

     //Loop through all the contours discovered 
     //Figure out which ones form a quad 
     while(contours){ 
      result=cvApproxPoly(contours, sizeof(CvContour),storage, CV_POLY_APPROX_DP,cvContourPerimeter(contours)*0.02,0); 

     if(result->total=4 && fabs(cvContourArea(result, CV_WHOLE_SEQ)) > 20){ 
      CvPoint *pt[4]; 
      for(int i=0; i<4; i++) 
       pt[i]=(CvPoint*) cvGetSeqElem(result,i); 

      DrawQuad(gray,*pt[0],*pt[1],*pt[2],*pt[3]); 

     } 
     contours = contours->h_next; 
     } 

} 

DetectAndDrawQuads獲取方法從main()調用..

這裏是鏈接庫

opencv_contrib opencv_flann opencv_legacy opencv_calib3d opencv_ml opencv_imgproc opencv_highgui opencv_objdetect opencv_core opencv_features2d 

我在Eclipse CDT的(Helois)工作

我將不勝感激任何提示。謝謝。

回答

0

事實證明,我打電話的方法來自openCv 2.0。如OpenCV 2.4.2中所述,我必須更改cvFindContours以查找Contours(...),cvApproxPoly以approxPolyDP等等。

+0

該方法仍然可用,但是,它更好地使用它們的C++等價物。 – Mohammad 2012-07-23 04:57:40

+0

它們被移動到opencv_legacy模塊。將其標題和鏈接包含到傳統庫中,並且可以工作。但是最好用C++替換它們。 – Sam 2012-07-23 05:39:52

1

首先,你應該使用#include <>作爲opencv標題(比如你的第一行,而不是第二行和第三行)。

cv(如cvFindContours)開頭的方法來自舊版本的opencv C接口,並且與較新的C++接口分開。例如cvFindContouropencv2/imgproc/imgproc_c.h中定義,而不在opencv2/imgproc/imgproc.hpp中(注意_c.h部分)。

在附註中,您已包含stdlib.h兩次。