我试图用C绘制图像的轮廓 . 它给出了错误:
cv :: cvarrTOMat中的Bad Arguement(未知数组类型) .
所以我切换到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;
}
2 回答
您必须将输入图像初始化为
drawContours
:此外,
findContours
需要二进制图像,而不是灰度图像 . 您可以添加类似于的内容:在调用
findContours
以二进制化dst2
之前 .这不是绘制轮廓的方法 . 请按照这段代码运行 .