【问题标题】:Error while using findContours in opencv在opencv中使用findContours时出错
【发布时间】:2018-10-15 19:10:23
【问题描述】:

我想使用 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) + 1) == ((((type0) & ((512 - 1) > 3) + 1) && ((1 > 3) + 1) == ((((type0) & ((512 - 1) > 3) + 1) && ((1

用于查找轮廓的图像:

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

【问题讨论】:

    标签: c++ opencv mat opencv-contour


    【解决方案1】:

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

    vector<vector<Point>> contours
    

    【讨论】:

    • 感谢您的回复,从 Point2f 更改为 Point 解决了问题。
    • 很高兴听到!也许批准答案?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-31
    • 2016-07-06
    • 1970-01-01
    • 2018-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多