开发者

Prominent lines not detected by Hough Transform

After running Canny edge detector on an image i'm getting clear lines. But the Hough line function seems to be missing out on pretty prominent lines when run on the Canny edgemap image. I'm keeping only vertical and horizontal Hough lines (a tolerance of 15 degrees). Lots of extra lines are coming up but clearly visible lines bounding the rectangles are not being picked up.

Here's the snippet:

cvCanny( img, canny, 0, 100, 3 );
lines = cvHoughLines2( canny, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 35, 20, 10 );

The main intention is to detect the rectangular boxes that denote the nodes of the linked list. However the squares.c sample program will detect only perfect rectangles, not if an arrowhead is touching the rectangle boundary.

Could you please explain the sort of changes to Hough line function which will help 开发者_Python百科me get hough lines corresponding to clearly visible lines in Canny edge image?

Prominent lines not detected by Hough Transform



(Added: a preprocessing step, suggested by shernshiou.)

Preprocessing steps:

  1. Thresholding the image,
  2. Use connected-component
  3. From the connected-component results, detect and remove the small objects - the sets of four-digits below and in the middle of each box.

(Remark. The thresholding step is simply a preprocessing step required by connected-component.)


If you want to detect only perfectly horizontal and vertical lines, my suggestion is to perform horizontal and vertical edge enhancement (via convolution) before Hough transform.

This will make the true lines more likely to "peak" in the Hough-projection, and increases the chance of the line being picked up by OpenCV.

The steps would be:

  1. Compute Canny edge image from input
  2. Apply horizontal Sobel filtering on Canny edge image
  3. Apply Hough line detection on horizontally-enhanced edge image.
  4. Apply vertical Sobel filtering on Canny edge image. (Note: use step 1's result, not step 2's)
  5. Apply Hough line detection on vertically-enhanced edge image.
  6. Combine the horizontal and vertical lines and present the result.


You did read the documentation did you?

I have a few options for you:

  1. The lines you miss (most notably the leftmost vertical line on the rightmost box in the image) are rather short. Try lowering the threshold (5th input variable of cvHoughLines2). This threshold is just the number of pixels that must lie on the line. From the image I'd guess that there are indeed less than 35 pixels on the lines you miss.
  2. The 6th input variable indicates the minimum line length. I assume this is in pixels, so with the 5th parameter you require 35 pixels on the line, yet you search for lines 20 pixels or longer. The way you set this variable it is non-functional. Lower the 5th variable, raise this one if you are finding to many useless short lines.
  3. Lower the 7th parameter to disallow large gaps in your lines. This will eliminate some of the slanted lines.

In short, try it again with different values for parameters 5,6 and 7.

I'd try some lower values of parameters 5 and 7, and a similar or slightly higher value for 6. Because of 2 above 5 should always be lower than or equal to 6 to have an effect. 7 should at least equal the difference between 5 and 6 if 5 is lower.


Normally people do not use hough line straight away from the box. The normal practice involves pre-processing image (e.g. change the luminance, change the colour, sharpen the image...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜