Mat imgthreshold; Mat imgsrc = cv::imread("C:/Users/Dell/Pictures/Camera Roll/6.png",0); imshow("imgsrc", imgsrc); threshold(imgsrc, imgthreshold,50, 110, THRESH_BINARY); imshow("imgthreshold", imgthreshold); vector<vector<Point>> contours; findContours(imgthreshold, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); cv::Mat imgdraw = imgsrc.clone(); drawContours(imgdraw, contours, -1, (0, 0, 255),0); imshow("imgdraw", imgdraw); waitKey(0);为什么这块输出的是白色边框而不是红色
时间: 2024-03-15 22:45:55 浏览: 167
轻量级Mat和imread()/ imwrite()/ imshow()-C/C++开发
在绘制边框时,你应该传入一个 Scalar 类型的参数作为边框颜色,而不是一个元组或者一个数组。修改 drawContours 函数的第四个参数,将其改为 Scalar(0, 0, 255) 即可绘制红色边框,代码如下:
```c++
Mat imgthreshold;
Mat imgsrc = cv::imread("C:/Users/Dell/Pictures/Camera Roll/6.png",0);
imshow("imgsrc", imgsrc);
threshold(imgsrc, imgthreshold,50, 110, THRESH_BINARY);
imshow("imgthreshold", imgthreshold);
vector<vector<Point>> contours;
findContours(imgthreshold, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
cv::Mat imgdraw = imgsrc.clone();
drawContours(imgdraw, contours, -1, Scalar(0, 0, 255), 1); // 修改这里
imshow("imgdraw", imgdraw);
waitKey(0);
```
阅读全文