开发者

How to count number of lines (Hough Trasnform) in OpenCV

开发者 https://www.devze.com 2022-12-16 06:08 出处:网络
I am successfully able to detect hair strands in an image as lines. I see that the output image detects each hair as line. I use cvHou开发者_JAVA技巧ghLines2() with method parameter as CV_HOUGH_PROBAB

I am successfully able to detect hair strands in an image as lines. I see that the output image detects each hair as line. I use cvHou开发者_JAVA技巧ghLines2() with method parameter as CV_HOUGH_PROBABILISTIC.

Now I want to count these lines. The output image shows 1 or 2 line over each hair. I see that each line is composed of small line segments. And so it is difficult to directly get their total number. Any suggestions on this?

Thanks, Pradeep


You may actually be better off using the Canny edge detector. From your description, it seems to have a few key advantages over the Hough transform:

  • responds to contours of arbitrary shape, not just straight lines;
  • performs noise reduction and non-maximum suppression to minimize the response; and
  • does a second detection with looser threshold to "trace" or "solidify" edges.

Given the right parameters, it may be able to uniquely detect each hair with a single, continuous line.

This is implemented in OpenCV in the cvCanny() function. Play around with the value of the threshold1 and threshold2 parameters (3rd and 4th arguments) to experiment with detection and tracing.

As for actually counting the lines, I'm not sure how best to approach this (Canny output is a somewhat different form from Hough transform output), but you might find it easier to work with unique, solid edges than with fragmented sets of line parameters.


The hough function should return a vector in OpenCV2 or a CvSeq in OpenCV1. You can easily get their length and iterate through them. See the sample code in the OpenCV documentation for more details.

0

精彩评论

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