【问题标题】:OpenCV C++ drawContours ErrorOpenCV C++ drawContours 错误
【发布时间】:2019-02-01 00:30:55
【问题描述】:
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 个点)

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    drawContours 的输入应该是 vector&lt;vector&lt;Point&gt; &gt; 。 这是您的代码的小修改。

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

    【讨论】:

      猜你喜欢
      • 2016-09-12
      • 1970-01-01
      • 2019-09-15
      • 1970-01-01
      • 2017-08-20
      • 2015-08-05
      • 2015-10-07
      • 2016-06-24
      • 2018-10-28
      相关资源
      最近更新 更多