首页 文章

OpenCV cvDrawContours vs drawContours

提问于
浏览
0

我是Visual Studio上使用OpenCV的新手,我最近重新安装了我的VS2012以使用OpenCV 2.4.2使其工作 .

我试图通过鼠标单击顶点并将它们推送到CvSeq *来计算指定区域的区域,以与contourArea()函数一起使用 .

我目前正在尝试解析一个空的CvSeq *作为我的自定义鼠标回调函数的最后一个参数,以便我可以添加由x和y坐标组成的CvPoint . 但是,每当我尝试访问CvSeq *轮廓后,我都会收到错误 . 所以在下面的代码片段中:

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

我得到了正确的cout消息,但是当尝试使用CvSeq *绘制轮廓时出现这样的错误:opencvtest.exe中的0x75E3812F处的未处理异常:Microsoft C异常:cv ::内存位置0x001FF990处的异常 .

这里有什么问题?尝试使用Vector>而不是CvSeq会更好吗?

1 回答

  • 3
    • cvDrawContours()来自旧的,不推荐使用的c-api,你不应该使用它,或任何那些旧的cv *函数 .

    • drawContours来自当前的c api,与cv :: Mat一起使用,来自cv :: namespace的函数 .


    另外,不要再担心CvSeq *或IplImage *了 . 如果你看到任何代码包含这样的奥术, - 继续前进 .

    “尝试使用 vector<vector<Point>> 而不是CvSeq会更好吗?” - 是的


    另外,如有疑问,请查看samplesdocs

相关问题