Engine
Engine

Reputation: 5422

how to "crop" the result of canny edges detector

I have a run the canny function and result look like this :

canny Result

I want to study the two regions "lines" so I want to crop them : like

what I want to do

by the way the "lines" can be on different positions: like 3rd

I'm not asking for code but only for ideas how can I do it thanks in advance !

Upvotes: 0

Views: 959

Answers (1)

HugoRune
HugoRune

Reputation: 13799

Scale your edge image down, and blur it, so that the edge pixels roughly form two thin continuous lines.
(you might want to do this scaling and blurring to the original image instead of the canny edge image, check what works best):

enter image description here

Then detect those lines with the hough transform

If your hough transform is reporting multiple matches per real line, you can either filter out matches that are close together, or scale your image down some more, or reduce the resolution parameters of the hough transform

Once you have the lines, remove every pixel with a distance-to-line > epsilon


Alternative suggestion:

Morphological closing: Dilate the edge image a few times, so that the edge pixels form a continuous blob. Erode the image a few times.

Detect the contours of this blob with cv::findcontours.

Simplify the contour with cv::approxPolyDP.

If you only want a bounding contour for both lines, your a done. Otherwise go through each contour segment, find the right-angle turn between two long segments to find where to split the contour, if you want to separate the lines.

Upvotes: 1

Related Questions