Ask Your Question
0

line extration in opencv_contrib

asked Sep 8 '15

Sheng Liu gravatar image

updated Sep 8 '15

I need detect lines in a image. And I find the line_extraction methods in opencv_contrib. But related cpp files in opencv_contrib cannot be compiled correctly. What should I do? Apart from Hough Transfom, could you recommend some good methods to detect lines? Thanks.

Preview: (hide)

2 answers

Sort by » oldest newest most voted
5

answered Sep 8 '15

berak gravatar image

updated Sep 8 '15

did you mean the line_descriptor module in the contrib repo ? this is probably the wrong tool anyway, it's for feature2d extraction with lines, similar to ORB or SIFT.

if you just need line segments, you might try the LineSegmentDetector (which also delivers the base for above descriptor class) have a look at the sample, too !

Preview: (hide)

Comments

1

Thank you!

Sheng Liu gravatar imageSheng Liu (Sep 8 '15)edit

I bought a tank model in a supermarket. Now I intend to detect gun barrel by LineSegmentDetector. But I have two issues. Firstly the edge lines of the tank and other uncorrelated lines are all detected. It is difficult to distinguish the edge lines of gun barrel. Secondly the detection result of LineSegmentDetector are not stright lines but many short lines. Could you give me some advice?

Sheng Liu gravatar imageSheng Liu (Sep 13 '15)edit

"detection result of LineSegmentDetector are not stright lines but many short lines" - yes, that's true. so, maybe it's the wrong tool for your job. if you still want to detect lines, have a look at HoughLines which will compute 'inifinite' lines, or HoughLinesP which will result in segments, too, but at least longer ones.

then, there's some doubt, if finding lines it the right idea at all. maybe findContours ?

berak gravatar imageberak (Sep 13 '15)edit

Thanks for your help! The input of findContours is a binary image. Do you mean threshod the gray image? But the part of gun barrel may disappear in the process of threshoding.

Sheng Liu gravatar imageSheng Liu (Sep 13 '15)edit

The edge of gun barrel are two parallel lines. How about using HoughLines to detect lines of which slope are similar and distance satisfy a certain condition?

Sheng Liu gravatar imageSheng Liu (Sep 13 '15)edit

if your barrel has a clear contrast to the bg, threshold() will do fine. Sobel() and Canny() are alternative ways.

berak gravatar imageberak (Sep 13 '15)edit

Could you tell me how to adjust the parameters to make the LineSegmentDetector output stright lines or shorter lines?

Sheng Liu gravatar imageSheng Liu (Sep 14 '15)edit

sample runs fine even on vs2008 here, what was the problem on your side ?

i did not write the lsd code, but i guess, the main purpose of it is to find very short pieces (that allow to get a gradient /orientation from this) . i don't see any way to make them longer. again, you're probably looking at the wrong tool. (yes, it's far easier to use, than HuoghLines, but again, very restricted)

berak gravatar imageberak (Sep 14 '15)edit

After delete the Canny(image, image, 50, 200, 3); // Apply canny edge, I find the sample run well in VS13 but it cannot work well in VS12.

Sheng Liu gravatar imageSheng Liu (Sep 14 '15)edit

Thanks for your help!

Sheng Liu gravatar imageSheng Liu (Sep 14 '15)edit
1

answered Sep 16 '15

Sheng Liu gravatar image

updated Sep 16 '15

Thanks to berak and 逸风, I find the LineSegmentDetector provided by this have a better result than LineSegmentDetector. The former output straight lines!

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Sep 8 '15

Seen: 786 times

Last updated: Sep 16 '15