c++ - 在opencv中使用findContours时出错
问题描述
我想使用 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 - 1) << 3)) >> 3) + 1) && ((1 << type0) & fixedDepthMask) != 0)) 在创建文件/home/nvidia/opencv/modules/core/src/matrix。 cpp,第 2578 行终止在抛出“cv::Exception”实例后调用什么():/home/nvidia/opencv/modules/core/src/matrix.cpp:2578:错误:(-215)mtype == type0 || (((((mtype) & ((512 - 1) << 3)) >> 3) + 1) == ((((type0) & ((512 - 1) << 3)) >> 3) + 1) && ((1 << type0) & fixedDepthMask) != 0) 在函数创建中。
用于查找轮廓的图像:
.任何有关如何解决此问题的指示将不胜感激。谢谢。
解决方案
我运行了您的代码并发现了问题。您正在使用 acv::Point2f
来存储轮廓,而您应该使用cv::Point
. 只需将第 4 行编辑为:
vector<vector<Point>> contours
推荐阅读
- c# - 如何在 Visual Studio 中搜索数据库?(C#)
- reactjs - 如何在点击反应时获得随机数组元素值?
- c - 为什么我的主表在传递给函数时会被重置?
- r - 基于 strsplit 将 Data.Frame 重组为多行
- node.js - 如何删除原始事件的反应
- amazon-web-services - 如何为特定 CloudFormation 堆栈创建“aws.cloudformation”CloudWatch 事件类型?
- sql - SQL将具有相同节点的XML转换为数据集
- python - 这是否可以运行“root.after”无限循环而不会导致 Tkinter 窗口崩溃?
- python - 列表理解在 for 循环中的行为方式
- python - 无法在 postgresql 表 flask-sqlalchemy 中设置 uuid 主字段