Ask Your Question
2

Hough transformation on given points

asked 2012-10-08 13:31:14 -0600

melongex gravatar image

Hi guys!

For some measurements I want to perform with OpenCV the canny algorithm in HoughLines seems just be too slow. However, I can also use a much easier approach for finding edges. Namely, I create search rays and then, take a profile across those ray, searching for maxima. The benefit of doing so is that I can set the resolution of the search rays: For rough searching it's just enough to have those rays each few pixels or so.

http://imageshack.us/a/img87/7904/searchrays.png

(Obviously, a plain houghlines would do it for this image, so please no comments about that) As you see in the image, I find points around edges (blue dots). However, now I want to find good candidates for lines for these points. Unfortunately, HoughLines NEEDS a greyscale image as input rather than taking points with x,y coordinates.

Is there any solution to find hough lines for an array of 2d points within opencv (I rather not implement my own hough transformation)?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
4

answered 2012-10-08 17:18:50 -0600

HugoRune gravatar image

updated 2012-10-11 17:17:20 -0600

(You probably know this, but just in case: The HoughLines function will not do canny edge detection on its own, you need to supply it with an edge image as input. It will take a grayscale input, but it will simply tread every nonzero pixel as an edge. (The HoughCircles function unfortunately works totally different))

If you want to do a fast hough transform for your detected blue dots, one way would be to call houghLines with a new matrix where every pixel is zero except for your detected dots. This should be very fast, since the speed of the hough transform almost solely depends on the number of edge pixels.

Unfortunately I do not think there is much more you can configure with the native houghLines function (but a basic hough transform for lines is not hard to implement)

If most of your detected edge pixels are on the line you seek, you could do a cv::lineFit

alternative ideas to speed up houghLines:

  • you could downscale your image first before canny edge detection and subsequent houghLines,
  • you could blur before canny (to decrease the number of edge pixels)
  • you could use higher canny thresholds (to decrease the number of edge pixels)

edit: as requested here are my suggestions for dealing with 5 megapixel images:

  • downscale the image to the point where your lines are still visible but smaller-scale features vanish. This will improve speed as well as robustness.
  • choose lower resolution for rho and theta. As low as possible, since this too improves robustness.
  • if you need higher resolution after all, use the hough transform on the downscaled image to identify the regions of interest, map these regions to your full-size image, then cut them out and do a more detailed analysis on just these edges.

Having a big but almost black image should be no problem for the hough transform. Checking whether a pixel is zero is a very fast operation, the only time-consuming work happens for edge pixels. The most time-consuming part might be allocating the matrix; if so, reuse the same matrix for multiple images.

edit flag offensive delete link more

Comments

"If most of your detected edge pixels are on the line you seek, you could do a cv::lineFit" I really wouldn't advise this in this case, it's very non-robust to outliers (this robustness is the whole point of using a voting scheme like Hough lines)

Leszek gravatar imageLeszek ( 2012-10-08 17:37:11 -0600 )edit

that is true. The CV_DIST_L1 and CV_DIST_HUBER parameters should be a little more robust than the standard CV_NORM_L2 (No idea about the other ones) and if the linefit is mostly correct you can further improve accuracy by iteratively doing a linefit, removing the points with the greatest error, then doing a linefit with the remaining points. But this problem is really a job for the hough transform, and the best way is to roll your own hough or make use of the inbuild one.

HugoRune gravatar imageHugoRune ( 2012-10-09 01:46:06 -0600 )edit

Thanks a lot for your ideas! I'll try if it is fast enough if I do it like this. Cheers!

melongex gravatar imagemelongex ( 2012-10-12 11:45:51 -0600 )edit
0

answered 2012-10-11 11:58:39 -0600

melongex gravatar image

I already tried creating a new matrix and putting my dots there, I didn't feel so good about doing this. I already have the dots, so it simply makes no sense for doing a for loop on an almost empty matrix. For small images it is okay of course, but for a 10 megapixel image it is probably not a so good idea. Of course ai could simply write my own line hough, but as this transformation is pretty common, I was hoping for a fast and robust implementation, which I could simply use. I already thought about a simple line regression, but I indeed want to use the linehough first to kill dots, which a too great distance from the 'best' line, and do the line regression afterwards.

So, do you know any solution? How are you detecting lines in large images in real time (for me the opencv implementation is already slow at about 5 megapixel)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-10-08 13:31:14 -0600

Seen: 2,674 times

Last updated: Oct 11 '12