Ask Your Question

cyril's profile - activity

2020-04-02 10:59:06 -0600 received badge  Famous Question (source)
2016-12-08 05:33:31 -0600 received badge  Notable Question (source)
2015-09-25 18:28:19 -0600 received badge  Student (source)
2015-07-27 12:39:18 -0600 received badge  Popular Question (source)
2012-12-28 09:42:30 -0600 asked a question How to draw an open (non-closed) contour using drawContours?

Hi

I try to draw an open contour (as std::vector<cv::Point>) with drawContour but it always closes the contour itself...

Here's a short sample app:

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char *argv[])
{
    std::vector<std::vector<cv::Point> > contour;
    contour.push_back(std::vector<cv::Point>());

    contour[0].push_back(cv::Point(10, 80));
    contour[0].push_back(cv::Point(80, 90));
    contour[0].push_back(cv::Point(50, 10));

    cv::Mat imgContour(cv::Size(100, 100), CV_8UC3);

    // this should now draw 3 connected points -> 2 lines in between.
    // but it draws a closed polygon over the 3 points??
    cv::drawContours(imgContour, contour, 0, cv::Scalar(255,0,0), 1, 8);

    cv::imshow("Contour", imgContour);

    cv::waitKey(0);

    return 0;
}

I am working with Qt Creator 2.4.1 (Qt 4.7.4 32bit) and OpenCV 2.3.0 under Windows 7 SP1.