Obtain polylines only from cv::findContours()?

asked 2018-05-31 04:36:45 -0600

sazr gravatar image

updated 2018-05-31 06:13:55 -0600

When I run cv::findContours() on my thresholded image I am getting the contours I want but the contours are polygons not polylines.

Is it possible to make cv::findContours() return contours as polylines not polygons? If not, is there an OpenCV way to convert polygons to polylines?

Below is my threshold image that I use for findContours and also the result - you can see the largest contour I found is a polygon but I am hoping it to be a polyline traversing the mountain ridge. I don't believe eroding the threshold image is the best way to obtain a polyline.

findContours(thresh, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

enter image description here enter image description here

Unprocessed image:

image description

edit retag flag offensive close merge delete

Comments

polyLines is a function, and i don't see any polygons here, only the outline of your thesholded region.

can you add an unprocessed image ?

maybe you could try thinning the thresholded image to a single line, or use a different edge detection

also: RidgeDetection

berak gravatar imageberak ( 2018-05-31 05:33:32 -0600 )edit

@berak I'm hoping for a skeletized version of the thick line in the threshold image. So just line line that describes that thick line.

sazr gravatar imagesazr ( 2018-05-31 05:49:21 -0600 )edit

so, try the thinning then. and maybe show us, how you got that "fat" line in the 1st place.

also note, that however thick your line is, findContours() will give you the outline of it, thatis: one line on top, and another at the bottom.

connectedComponents() might be a bettter way, to retrieve the thinned line, maybe.

i think, you want a ridge, not a contour !

berak gravatar imageberak ( 2018-05-31 06:16:18 -0600 )edit