Ask Your Question
0

drawContours throws exception

asked 2017-12-14 07:04:33 -0600

homes gravatar image

updated 2017-12-14 07:32:48 -0600

Hello, I use opencv3.3.1 from ros-kinetic When executing this code

            vector <vector <Point2i> > testContour;
            vector <Point2i> testedge;
            testedge.push_back(Point2i(240,240));
            testedge.push_back(Point2i(120,240));
            testedge.push_back(Point2i(120,120));
            testedge.push_back(Point2i(240,120));
            testContour.push_back(testedge);
            vector <Point2i> testedge2;
            testedge2.push_back(Point2i(200,200));
            testedge2.push_back(Point2i(100,200));
            testedge2.push_back(Point2i(100,100));
            testedge2.push_back(Point2i(200,100));
            testContour.push_back(testedge2);
    drawContours(image, testContour, -1,/*it->getColor()*/Scalar(255,255,255),CV_FILLED,LINE_8);

i get the following error:

OpenCV Error: Assertion failed (reader.ptr != __null) in cvDrawContours, file /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgproc/src/drawing.cpp, line 2603 terminate called after throwing an instance of 'cv::Exception' what(): /tmp/binarydeb/ros-kinetic-opencv3-3.3.1/modules/imgproc/src/drawing.cpp:2603: error: (-215) reader.ptr != __null in function cvDrawContours

now this only happens after updating the ros packages... before it ran fine.....

now i don't understand why exactly the reader.ptr() is __null, since my counturs vector is filled as u can see above, also google is quite emoty of that problem.

best regards, homes

edit: it works now with the testContour, but it doesn't appear to work with a dynamically filled Contour vector. Am I correct in my assumption, that this means i am trying to pass a undefined pointer to the drawContours function?

edit retag flag offensive close merge delete

Comments

probably you used undefined edgeVector

try

drawContours(image, testContour, -1,/*it->getColor()*/Scalar(255,255,255),CV_FILLED,LINE_8);
sturkmen gravatar imagesturkmen ( 2017-12-14 07:35:46 -0600 )edit

yep, that was one problem, but edgeVector is a dynamic generated vector<vector<point2i> > , it may be possible, that i'm passing point coordinates out of bounds of the matrix, i'm checking that right now. If that isn't the case i', clueless ...again. edit: the values of the points in the ContourVector are in range of the matrix.

homes gravatar imagehomes ( 2017-12-14 07:43:29 -0600 )edit

I have the same problem, did you find a solution to your problem?

Thanks!

jproberge gravatar imagejproberge ( 2018-03-21 13:09:00 -0600 )edit

@jproberge, please do not post answers here, if you have a question or comment, thank you !

(and read above again, it is anwered.)

berak gravatar imageberak ( 2018-03-21 13:12:01 -0600 )edit

@berak: please read above again, it is not fully answered yet, and thus the reason why I posted my comment in the first place. "[...] it doesn't appear to work with a dynamically filled Contour vector. Am I correct in my assumption, that this means i am trying to pass a undefined pointer to the drawContours function?". I have the exact same question and concern so please don't consider this as being a closed issue. If anyone has an answer to that question, I would be happy to hear it. Thanks.

jproberge gravatar imagejproberge ( 2018-03-22 13:51:43 -0600 )edit

@jproberge, rather ask a new question, with your own context. (i doubt, that you're using ROS here)

berak gravatar imageberak ( 2018-03-22 13:57:46 -0600 )edit

@berak: Hum... ok so listen, I'm using ros kinetic on Ubuntu 16.04 exactly like the OP. And guess what, I have exactly the same version of OpenCV (3.3.1). I have the exact same context than him. I use a camera and a UR10 robot on ROS and I face the exact same issue. Please stop making assumptions about stuff you have absolutely no idea about. Do you really want me to ask a new question? Because, I'm basically going to ask exactly the same question as the original poster. Thanks

jproberge gravatar imagejproberge ( 2018-03-22 14:14:47 -0600 )edit

@jproberge,

(3.3.1) -- outdated, probably none here can help you with specific problems related to that.

also silly as it is, ROS insists to install it's own (again outdated) opencv version, more problematic, than useful, ever.

exact same context than him

missing context above, code snippet not leading anywhere.

again, please ask your own question (and give your own, specific context ! instead of holping to solve it from here.

berak gravatar imageberak ( 2018-03-22 14:22:44 -0600 )edit

Wow, I'm really flabergasted. "Outdated" you say?? It's a version that was released not even 6 months ago!! And yet you think we should not ask questions about it? Do you imagine that everyone everywhere update their library as soon as there's a new release? As you said yourself, most of ros users have opencv 3.3.1, so should they not ask any questions? I still think you don't get the words "same exact context". You want a code snippet? I'm just gonna have to copy-paste the one from the OP then, if you'd like. Or change the name of the variables if you think that would be more acceptable! I'm gonna stop writing now, this is pointless.

Bottom line is, the original poster posted a question. It is not fully answered yet. If anyone has an answer that would be great ...(more)

jproberge gravatar imagejproberge ( 2018-03-22 14:38:01 -0600 )edit

bottom line here: please ask your own question. (reference the other, nonetheless, but we need to see your specific context)

(having said that, no ROS specific question was EVER succesfully answered from here. wrong forum to ask ?)

berak gravatar imageberak ( 2018-03-22 14:40:05 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-03-23 03:44:27 -0600

homes gravatar image

So I found the reason for my error or at least an workarround. It is possible to pass a vector<vector<point>>, where u can push-back the outer vector with an empty inner vector. Thus my safeguard working with the outer "if (! .empty)" did fail. If that's the case, you get above Error & thanks for the effort.

So my solution is to make sure there is no empty stuff passed to any those functions, mostly with if(!Vector.empty()). I know it is not an efficient or elegant solution, but it works. The alternative to the if-conditions would be to make sure there are no empty Vectors created in the first place, which sometimes is quite difficult.

I hope that helps.

Best regards homes

edit flag offensive delete link more

Comments

@homes : Thanks for your answer, I appreciate it a lot! That simple workaround is way better than what I had implemented previously to deal with this problem. I tested it and it works fine. Thank you :)

jproberge gravatar imagejproberge ( 2018-03-23 14:13:56 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-14 07:04:33 -0600

Seen: 6,248 times

Last updated: Mar 23 '18