OpenCV C++ drawContours Error

OpenCV C++ drawContours Error

本文关键字:Error drawContours C++ OpenCV      更新时间:2023-10-16
Mat frame;
Mat frame2;
Mat output_frame;
Mat imgray;
Mat imgCanny;
vector<vector<Point> > contours;
vector<Point> approx;
Mat img = imread("abc.jpg");
cvtColor(img, imgray, COLOR_BGR2GRAY);
Canny(imgray, imgCanny, 10, 100, 3, false);
findContours(imgCanny, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
double eps = 0.1 * arcLength(contours[0], true);
approxPolyDP(contours[0], approx, 1, true);
drawContours(img, approx, 0, (0, 255, 0), 1);  // Here has Error..

我研究了OpenCV,但drawContours方法(?(很奇怪。

我的意思是其他drawContours已经完成(drawContours(img,contours,0,(0,255,0),1);(

drawContours(img, approx, 0, (0, 255, 0), 1);有错误。

为什么?

确认近似有数据(4点(

drawContours的输入应该vector<vector<Point> >。 这是对代码的微小修改。

Mat frame;
Mat frame2;
Mat output_frame;
Mat imgray;
Mat imgCanny;
vector<vector<Point> > contours;
vector<Point> approx;
Mat img = imread("abc.jpg");
cvtColor(img, imgray, COLOR_BGR2GRAY);
Canny(imgray, imgCanny, 10, 100, 3, false);
findContours(imgCanny, contours, RETR_TREE, CHAIN_APPROX_SIMPLE);
double eps = 0.1 * arcLength(contours[0], true);
approxPolyDP(contours[0], approx, 1, true);
vector<vector<Point> > approx_t;
approx_t.push_back(approx);
drawContours(img, approx_t, 0, (0, 255, 0), 1);
相关文章: