gpt4 book ai didi

c++ - OpenCV cvDrawContours 与 drawContours

转载 作者:太空宇宙 更新时间:2023-11-03 22:05:27 24 4
gpt4 key购买 nike

我是在 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++ 异常:内存位置 0x001FF990 处的 cv::Exception。

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

最佳答案

  • cvDrawContours() 来自旧的、已弃用的 c-api,您应该使用它,或任何那些旧的 cv* 函数。

  • drawContours 来自当前的 c++ api,与 cv::Mat 一起使用,来自 cv::命名空间的函数。


另外,不要再担心 CvSeq* 或 IplImage*。如果您看到任何包含此类神秘内容的代码,请继续。

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


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

关于c++ - OpenCV cvDrawContours 与 drawContours,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25327724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com