Ask Your Question
0

drawCountours with fixed points not working

asked 2017-04-26 03:48:31 -0500

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

edit retag flag offensive close merge delete

Comments

hmm, works for me, both on linux and win(mingw). can't find anything wrong with your code.

berak gravatar imageberak ( 2017-04-26 04:04:52 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-04-26 05:38:53 -0500

Okay, apparently I have to wait until tomorrow to answer my own question. That's why I'm posting a comment and the official answer will follow tomorrow.

I solved the problem by looking at the OpenCV libraries I linked to my build. I was using the "release" libraries for a debug build in Visual Studio. This worked fine until now so I did not notice my mistake.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-04-26 03:48:31 -0500

Seen: 99 times

Last updated: Apr 26 '17