This program detects the lane on the images and video files. The main idea is using of small horizontal lines named by sensors
The source image (or video) may be taken from a DVR. For example:
An all image is not interesting for us. We need to take the part of image which contains only road and excludes sky and a car bonnet. It will be a trapezoidal area of the image:
Properties of this trapezoid, such as the horizon point position, are contained in the CameraProperties
static class
The RGB color model is not comfortable for lane detection. So, we convert the source image to HSV model:
Now we have to find contours on this image. The Canny detector is used for that in the project. Then on result binary image we find contours via OpenCV and filter small of them:
The sensor is a small horizontal line placed on the image. This line is the work area of the sensor. Each sensor try to find the lane in its work area. We put sensors onto the image and delete those which do not cover contours:
- Then we filter sensors by middle color in the work area, searching the light colors.
- Besides, the lane color differs from the road color, so we filter sensors also by difference between middle color inside sensor and middle color outside sensor
- The lane is the long lines in the image. So, there are many sensors covering the one lane line in the image. We filter sensors by existing other sensors near current one
Now we have many sensors placed on all image. We calculate for each sensor an angle from it to the horizon point. Then we group sensors by angles and distances for other sensors:
In the end we analyze the received groups by count of sensors in them and dispercy of angle. The most suitable groups we name to lane line and then draw line though these sensors:
This program well detects a bright lane in the morning and in the night, but has some problems with old and dirty lane. The algorithm is need to improving by making better sensors filtering and groupping