2

I'm using Canny() Function in OpenCV as below

Mat detected_edges = GetImage...;
Canny( detected_edges, detected_edges, 20, 20*3, kernel_size );

My problem is the result of this function only a black-white image, I want to get the set of edges that detected.

On OpenCV docs wrote

The function finds edges in the input image image and marks them in the output map edges using the Canny algorithm. The smallest value between threshold1 and threshold2 is used for edge linking. The largest value is used to find initial segments of strong edges.

But I don't know how to extract lines from the result image, someone can help me.

UPDATE The image that I used to test below, this image include the result of Canny function

enter image description here

BenMorel
  • 34,448
  • 50
  • 182
  • 322
TTGroup
  • 3,575
  • 10
  • 47
  • 79

4 Answers4

4

As berak's answer points out, you can use findContours and the Hough transform to find lines after performing Canny edge detection.

However I wanted to add that it may be beneficial to do a bit of image processing before performing Canny edge detection and finding lines. For example you seem to be getting a lot of unwanted outlines on the floor and there are also white 'specs' found around your Canny result.

Smoothing the image will help, as well as perhaps using a mean shift algorithm to segment your image by colour. There may be other novel ways of processing your image that you might want to explore.

DevGoldm
  • 828
  • 12
  • 28
3

depending on the shape you're trying to retrieve,

berak
  • 39,159
  • 9
  • 91
  • 89
2

Canny algorithm is not aware of actual shape of edges. These fancy one-pixel wide lines are actually peaks of simple edge-detection Sobel operator, extracted with non-maxima suppression. Canny doesn't connect pixels into chains or segments. It may internally form connected components to apply hysteresis thresholding, but this is implementation details.

You have to do it on your own, see berak's answer for possible routines.

Mikhail
  • 20,685
  • 7
  • 70
  • 146
2

As berak said, you can try and use findContours to find connected components after the edge detection. There's another stackoverflow question about that here: connected components in OpenCV

Here is an example: http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html

Note that in this case they are using it to draw, but you can use it for whatever purpose you choose.

Community
  • 1
  • 1
ZenBowman
  • 21
  • 2