I'm new to image processing and I'm working on detecting lines in a document image. I read the theory of Hough line transform but I can't see why I must use Canny before calling that function in opencv like being said in many tutorials. What's the point of finding edges in this case? The fact is that if I don't use Canny or threshold before HoughLines() the results will be very messy. I hope someone will explain for me the reason why.
2 of the tutorials I've read:
First of all, to detect lines you need to work on a boolean
matrix image (or binary), I mean: the color is black or white, there's no grayscale.
HoughLines()
's requirement to work properly is to have this kind of image as input. That's the reason you have to use Canny
or Treshold
, to convert the colored image matrix into a boolean one.
Hough transformation
A line in one picture is actually an edge. Hough transform scans the whole image and using a transformation that converts all white pixel cartesian coordinates in polar coordinates; the black pixels are left out. So you won't be able to get a line if you first don't detect edges, because HoughLines()
don't know how to behave when there's a grayscale.