OpenCV c++ 断言失败调用绘制轮廓
OpenCV c++ assertion failed call drawContours
我试图找到最大的正方形并将其绘制在原始图像上。
当我打电话时
drawContours(input,(screenCnt),-1,Scalar(255,0,0),3);
发生以下错误:
E/cv::error(): OpenCV 错误: 断言失败 (i <0) in cv::Mat cv::InputArray::getMat(int) const, file /build/master_pack-android/opencv/modules/core/src/matrix.cpp, line 1260
年
我在Github和Google上找到了很多东西,但我找不到任何相关的解决方案。
你能帮助知道如何解决它的人吗?
这是我的代码。(C++)
bool compareContourAreas(vector<Point> contour1, vector<Point> contour2){
double i = fabs(contourArea(Mat(contour1)));
double j = fabs(contourArea(Mat(contour2)));
return ( i < j );
}
Mat &input = *(Mat *) matAddrInput;
Mat &result = *(Mat *) matAddrResult;
Mat gray;
Mat edge;
resize(input,input, cv::Size(), 0.75, 0.75);
cvtColor(input,gray,CV_RGB2GRAY);
GaussianBlur(gray,gray,Size(3,3),0);
Canny(gray,edge,100,200,3, false);
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
findContours(edge,contours,hierarchy,CV_RETR_LIST,CHAIN_APPROX_SIMPLE);
sort(contours.begin(),contours.end(),compareContourAreas);
vector<Point> approx;
vector<Point> screenCnt;
for(size_t i = 0; i < contours.size(); i++){
approxPolyDP((Mat(contours[i])),approx,arcLength(Mat(contours[i]),true) * 0.02, true);
if(approx.size() == 4){
screenCnt = approx;
break;
}
}
if(screenCnt.size() != 0){
drawContours(input,(screenCnt),-1,Scalar(255,0,0),3); << error
}
drawContours
需要输入一个轮廓数组,而不仅仅是单个轮廓。您可以在调用中直接创建数组,例如:
drawContours(input, std::vector<std::vector<cv::Point>>{screenCnt},-1,Scalar(255,0,0),3);
相关文章:
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 无法使用VAO和EBO(openGL)绘制多个对象
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 使用GDI(C )的轮廓绘制文字
- OpenCV c++ 断言失败调用绘制轮廓
- 使用绘制轮廓绘制点的序列
- 图像绘制使用NDK显示轮廓
- 使用模具缓冲区绘制三维模型的轮廓
- 使用 OpenCV C++绘制最大轮廓的凸包
- OpenCV 3.1 绘制轮廓 '(-215) npoints > 0'
- 绘制轮廓,同时删除较小的区域
- OpenCV如何在C++中从网络摄像头(跟踪)绘制2个最大对象的轮廓
- 实现图像轮廓绘制的基本思想
- 绘制从二值图像中检索到的轮廓
- 打开cv绘制轮廓
- OpenCV 2.4.8和VS2013绘制轮廓崩溃