繁体   English   中英

在opencv中使用findContours时出错

[英]Error while using findContours in opencv

我想使用findContours处理黑白图像。

Mat frame= imread(argv[1]);
cvtColor(frame, frame, CV_BGR2GRAY);
threshold(frame,frame, 150, 255, THRESH_BINARY);
vector<vector<Point2f>> contours;
findContours(frame.clone(), contours, noArray(), CV_RETR_EXTERNAL, 
CV_CHAIN_APPROX_SIMPLE , Point(0, 0));

但是我得到以下异常:

OpenCV错误:断言失败(mtype == type0 ||((((((mtype)&((512-1)<< 3))>> 3)+ 1)==(((((type0)&((512 -在创建文件/ home / nvidia / opencv / modules / core / src / matrix的过程中-1)<< 3))>> 3)+ 1)&&(((1 << type0)&fixedDepthMask)!= 0)) cpp,在抛出'cv :: Exception'what()实例之后调用第2578行终止:/home/nvidia/opencv/modules/core/src/matrix.cpp:2578:error:(-215)mtype == type0 || (((((mtype)&((512-1)<< 3))>> 3)+ 1)==(((((type0)&((512-1)<< 3))>> 3)函数创建中的+ 1)&&(((1 << type0)&fixedDepthMask)!= 0)。

用于查找轮廓的图像:

在此处输入图片说明

任何有关如何解决此问题的指针将不胜感激。 谢谢。

我运行了您的代码,发现了问题。 您应该使用cv::Point2f来存储轮廓,而您应该使用cv::Point 只需将第四行编辑为:

vector<vector<Point>> contours

暂无
暂无

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

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