Ask Your Question

Revision history [back]

drawCountours with fixed points not working

Hello Forum,

I need to create a simple mask for an arbitrarily shaped user defined region on interest. I thought using cv::drawContours should fit my purpose. However, I am unable to run my program.

Here is the sample code:

int QtBilderkennung::simpleFunction(){

cv::Mat Image(100, 100, CV_8UC1,cv::Scalar(0)); //Create an empty Mat

std::vector<std::vector<cv::Point>> MyCont;       //Vector for user defined points
std::vector<cv::Point> MyPoint;                          //Vector for contour drawing

//Insert some points for the contour here
MyPoint.push_back(cv::Point(1, 1));
MyPoint.push_back(cv::Point(50, 50));
MyPoint.push_back(cv::Point(70, 70));
MyPoint.push_back(cv::Point(1, 1));

//Add vector with contour to MyCont
MyCont.push_back(MyPoint);

cv::Scalar color(255);
// Draw the countour
cv::drawContours(Image, MyCont, 0, color);
return 0; }

The code compiles without any problems. When I run the function it generates a std::length_error in drawContours(). Hopefully somebody can help me since I can't find anything wrong with the code.

For further intomation I am using VisualStudio 2015 and OpenCV 3.2.(x86) compiled for msvc2015.

Best regards, mouthbag