Finding midpoints of polygons with more than 4 sides (for road lane line detection)

Hello everyone,
I’m currently working on road lane line detection (how original :roll_eyes:) and in order to detect the lines and the dotted line I use findContours and then approxPolyDP to obtain polygons. After that I find the midpoints of near horizontal segments.

Here’s the result with images:
Original image
framesave

Image with polygons and midpoints
polysave

That was the easy part, because now if I use an image with a turn, I will get polygons with more than 4 segments

Original image
framesave2

Image with polygons (ignore the false positives)
polysavee

I did a simple drawing to show you what I would like to obtain in that case, because I struggle to express it with words:
idea

It’s about finding the “inner midpoints”, because the goal is to link the points to draw a line
idea2

I hope it is clear enough, if not I’ll make sure to update with more informations.

Thank you.

don’t even approximate these things. or extract contours.

those contours will not behave like you want them to. the corners of the left and right edge won’t line up as nicely as you want them to.

I would work with the connected components themselves, labeled and with stats of course.

those lane markings are supposed to be nearly vertical, so I’d scan them row by row (pixels), find the left and right edge, calculate the midpoint for that row. that’ll give a center line with lots of points in it, but exactly one per pixel row.

1 Like