How to detect curved lines with openCV

asked 2018-07-09 12:07:08 -0500

edapx gravatar image

Hello, I am trying to detect curved lines with openCV. I have an image, I apply blur to enhance the contrast and make the lines more visible, then I convert it to gray, and then I apply Canny edge detection. And Until here it works good

image description

From here, i need to identify the three lines. I use HoughTransformP for these purposes.

image description

And I use these parameters: threshold 20, rho 1.7, min Line length 0, max line gap 0

I I use an higher max line gap value, some lines are connected, but also artifacts appears when lines are close.

image description

Does anyone have suggestion about how to proceed?

edit retag flag offensive close merge delete


In my opinion this is already a hard task for a human when following the three lines on the right side. So it is even harder for a computer. Nevertheless the Canny image looks nice and I would have tried to separate the lines after that step using the findContours function with the mode CV_RETR_EXTERNAL. Perhaps you can then separate the three contours. Still, the intersection will be a problem.

Grillteller gravatar imageGrillteller ( 2018-07-10 04:49:31 -0500 )edit

Yes the canny edge detection works really good. I think that I am messing up something when i process the canny edge image and I try to figure out how to merge the two borders, without using any opencv functionality. The image that result from this process is given to the HougTransformP, but it has some "holes". Could you give me some more details to findContours and CV_RETR_EXTERNAL, also links to tutorial or specific documentation are really appreciated. Thanks

edapx gravatar imageedapx ( 2018-07-10 04:57:09 -0500 )edit

Here is a link to the function: I would apply findContours(Mat CannyImg, vector<vector<Point>> contours, RETR_EXTERNAL, CHAIN_APPROX_NONE). The function uses border following (Suzuki, S. and Abe, K., Topological Structural Analysis of Digitized Binary Images by Border Following. CVGIP 30 1, pp 32-46 (1985) which I think will be a problem with the intersecting lines on the right side but perhaps you have some further ideas to handle it :)

Grillteller gravatar imageGrillteller ( 2018-07-10 06:47:49 -0500 )edit