Howon Lee
Howon Lee

Reputation: 13

OpenCV cvDrawContours vs drawContours

I am new to using OpenCV on Visual Studio, and I have recently reinstalled my VS2012 to get it to work using OpenCV 2.4.2.

I am trying to calculate the area of region specified by mouse-clicking the vertices and pushing them to CvSeq*, to use with contourArea() function.

I am currently trying to parse in an empty CvSeq* as the last parameter of my custom mouse callback function so that I can add the CvPoint formed of x and y coordinates. However, whenever I try to access the CvSeq* contour afterwards, I get an error. So in the following snippet of the code:

void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{

    CvSeq* contour = (CvSeq*)userdata;
    CvPoint cur;
     if  ( event == EVENT_LBUTTONDOWN )
     {
          cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ") saved as point" << endl;
          // save x,y as a contour point
          cur = cvPoint(x,y);
          cvSeqPush(contour, &cur);
...

I get the correct cout messages, but get an error like this when trying to draw contour using that CvSeq* : Unhandled exception at at 0x75E3812F in opencvtest.exe: Microsoft C++ exception: cv::Exception at memory location 0x001FF990.

What is the problem here? Would I be better off trying to use Vector> instead of CvSeq?

Upvotes: 1

Views: 1934

Answers (1)

berak
berak

Reputation: 39796

  • cvDrawContours() is from the old, deprecated c-api, you should not use it, or any of those old cv* functions.

  • drawContours is from the current c++ api, use it with cv::Mat, functions from the cv:: namespace.


also, stop worrying about CvSeq* or IplImage*. if you see any code that contains arcane stuff like that, - move on.

"Would I be better off trying to use vector<vector<Point>> instead of CvSeq?" - yes.


also, when in doubt, have a look at the samples and the docs

Upvotes: 4

Related Questions