Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV From Canny edges to contours

I have a edge detected by Canny. And I want to extract contours of the edges.

I have checked the following post. OpenCV converting Canny edges to contours.

But it didn't deal with complex shape. e.g, circle with rectangle or circle with line.

cv::findContours() function has 2 issues. 1. Return closed contour for non closed edge, but I want non closed contour 2. Return 2 closed contours for closed edge(maybe one of the contours is for edge, and another one is for inner side of the edge, but I want one of the two.

Is there any way to solve this out? Thanks.

PS : I have uploaded the sample image.

Sample Image.

like image 204
Chris Avatar asked Sep 01 '25 05:09

Chris


1 Answers

It all depends on the parameters you choose while finding contours.

In OpenCV you can find contours using

contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

and draw them

cv2.drawContours(im, contours, -1, (0, 255, 0), -1) #---set the last parameter to -1

enter image description here

like image 133
Jeru Luke Avatar answered Sep 03 '25 21:09

Jeru Luke