简体   繁体   English

OpenCV cvDrawContours与drawContours

[英]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. 我是在Visual Studio上使用OpenCV的新手,最近我重新安装了VS2012,使其可以在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. 我正在尝试通过鼠标单击顶点并将其推到CvSeq *来计算指定的区域面积,以与ContourArea()函数一起使用。

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. 我目前正在尝试将空CvSeq *解析为自定义鼠标回调函数的最后一个参数,以便可以添加由x和y坐标形成的CvPoint。 However, whenever I try to access the CvSeq* contour afterwards, I get an error. 但是,以后每次尝试访问CvSeq *轮廓时,都会出现错误。 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. 我得到了正确的cout消息,但是在尝试使用CvSeq *绘制轮廓时遇到了这样的错误:opencvtest.exe中0x75E3812F的未处理异常:Microsoft C ++异常:内存位置0x001FF990的cv :: Exception。

What is the problem here? 这里有什么问题? Would I be better off trying to use Vector> instead of CvSeq? 我会尝试使用Vector>而不是CvSeq更好吗?

  • cvDrawContours() is from the old, deprecated c-api, you should not use it, or any of those old cv* functions. cvDrawContours()是从旧的,过时C-API,你应该使用它,或者任何的那些老品种*功能。

  • drawContours is from the current c++ api, use it with cv::Mat, functions from the cv:: namespace. drawContours来自当前的c ++ api,与cv :: Mat和cv ::名称空间中的函数一起使用。


also, stop worrying about CvSeq* or IplImage*. 另外,不要再担心CvSeq *或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?" “尝试使用vector<vector<Point>>代替CvSeq更好吗?” - yes. -是的


also, when in doubt, have a look at the samples and the docs 另外,如有疑问,请查看示例文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM