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

Hi,
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 cvHoughLines2() with method parameter as CV_HOUGH_PROBABILISTIC. The image is attached: test1.bmp
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

hi pradeep,

i can’t see your attachment; but, i think you will have to count the line segments yourself. google ‘canny hysteresis trick’ for some ideas.

hth
d

Thanks Damian,
I am using cvcanny method from opencv. It gives me line segments.
The image contains 21-25 lines (hair) but the line segment value which I get i.e. lines->total = 237. This lines is of type cvSeq.
I am trying to find out a way to count the number of hair from this small line segments.

Thanks,
Pradeep

hi pradeep,

first, did you read anything about canny’s hysteresis trick? you could try changing the two values for hysteresis that you pass in to cvCanny, but it helps to understand how the hysteresis calculation works to actually make sense of the values you send in. set up a couple of keys to increment/decrement the values you pass in, that should help to join up some of the segments.

to get more accurate, you’re going to have to work it out yourself. probably the best way to start would be to extend all the line segments you find some way, and then walk from the end of a segment along its extension until you cross another segment’s extension, then connect these two segments into a continous line. this is likely going to lead to some false positives but it should be a start.

hope this helps,
d

Hi Damian,
Thanks again. I am getting the output image. (Pls see the attached image) after I apply cvCanny method and cvHoughLines2 methods from opencv. From the image I see that the edge detection is pretty accurate.
Now I need to find out some trick on getting the number of lines detected in this image. Internally it may have detected more than what is visible. But I want my application to match the number of hair/line that we can visually count.

Thanks,
Pradeep