簡體   English   中英

OpenCV C ++ drawContours錯誤

[英]OpenCV C++ drawContours Error

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方法(?)很奇怪。

我的意思是完成了其他drawContoursdrawContours(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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM