2

I am working on detecting edges and finding quadrilateral shapes on image using opencv 2.4.2 libraries. Everthing was going smooth, until I got these compilation errors

../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

Here are my headers:

#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);

Here is the method that calls the function(s)

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 gets called from main()..

Here are the linked libraries

opencv_contrib opencv_flann opencv_legacy opencv_calib3d opencv_ml opencv_imgproc opencv_highgui opencv_objdetect opencv_core opencv_features2d

I am working on Eclipse CDT (Helois)

I would appreciate any hint. Thanks.

2 Answers 2

1

First, your should use #include <> for opencv headers (like your first line, in contrast to second and third lines).

Methods that start with cv like cvFindContours are from older opencv C interface and are separate from the newer C++ ones. for example cvFindContour is defined in opencv2/imgproc/imgproc_c.h and not in opencv2/imgproc/imgproc.hpp (note the _c.h part).

On a side note you've included stdlib.h twice.

0

It turns out that the methods I was calling are from openCv 2.0. I had to change cvFindContours to findContours(...), cvApproxPoly to approxPolyDP and so on as described in OpenCV 2.4.2.

2
  • The methods are still available, but yes, its better to use their c++ equivalents.
    – Mohammad
    Jul 23, 2012 at 4:57
  • They are moved to opencv_legacy module. Include its header and link to the legacy lib, and it will work. But it is better to replace them with the C++ counterparts.
    – Sam
    Jul 23, 2012 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.