OpenCV绘图轮廓不起作用
OpenCV drawContours not working
我正在尝试使用C++绘制图像的轮廓。它给出错误:
cv::cvarrTOMat中的参数错误(未知数组类型)。
所以我换了python,它在那里运行得很好。请帮我找出代码出了什么问题。
int main()
{
Mat src, dst,dst2,dst3;
src = imread("imagedata\result0.jpg", 1);
resize(src, dst, Size(), 0.09, 0.09, INTER_LINEAR);
string s = "cropped.jpg";
imwrite(s , dst);
cvtColor(dst, dst2, CV_RGB2GRAY);
imwrite("cropped2.jpg", dst2);
vector< vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(dst2, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
drawContours(dst3, contours, -1 , (128,255,0), 3);//, hierarchy);
imwrite("cropped3.jpg", dst3);
return 0;
}
您必须将输入图像初始化为drawContours
:
dst3 = dst.clone(); // initialize dst3
drawContours(dst3, contours, -1, (128, 255, 0), 3);
此外,findContours
期望的是二进制图像,而不是灰度图像。你可以添加类似的东西:
threshold(dst2, dst2, 127, 255, THRESH_BINARY);
然后调用CCD_ 3对CCD_。
这不是绘制轮廓的方法。请按照代码运行。
threshold(dst2, dst2, 100, 255, THRESH_BINARY);
findcontours()
for( int i = 0; i< contours.size(); i++ )
{
Scalar color = Scalar( 255,255,255);
drawContours( dst3, contours, i, color, 2, 8, hierarchy, 0, Point() );
}
namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
imshow( "Contours", drawing );
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- OpenCV绘图轮廓不起作用