Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 me get hough lines corresponding to clearly visible lines in Canny edge image?

hough

like image 688
AruniRC Avatar asked Jun 30 '11 05:06

AruniRC


1 Answers


(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.
like image 89
rwong Avatar answered Dec 05 '22 00:12

rwong