0
votes
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..

I studied about OpenCV, but the drawContours method(?) is strange.

I mean other drawContours is done (drawContours(img,contours,0,(0,255,0),1);)

But drawContours(img, approx, 0, (0, 255, 0), 1); has error.

Why?

I confirm that the approx has data (4 dot points)

1

1 Answers

0
votes

input of drawContours should be vector<vector<Point> > . here is minor modification of your code.

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);