Obtain polylines only from cv::findContours()?
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);
Unprocessed image:
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 I'm hoping for a skeletized version of the thick line in the threshold image. So just line line that describes that thick line.
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 !