Lane Boundary Detection Using Open CV
Lane Boundary Detection Using Open CV
Lane Boundary Detection Using Open CV
1 Introduction
Currently, the most widely used method of transportation around the world is
automobiles. From its creation to modern times, these have undergone a series
of changes and improvements according to the needs of the users. These changes
are related to the safety, comfort and efficiency they provide. The large number
of vehicles circulating simultaneously has been accompanied by an increase in
the number of annual traffic accidents, causing the issue of safety to be taken
much more into account. Among the most common causes of traffic accidents
we find: distractions, driver’s inexperience and drowsiness. All these factors can
be summarized in a single term; human error. One of the mechanisms designed
to reduce this error and minimize accidents is the lane change warning system.
This is a mechanism designed to warn the driver when the vehicle begins to drift
out of the lane. One of the most important components in this system is the
lane detection system, which is based on the contrast that exists between the
surface of the canine and the lines that define the lanes. In terms of digital image
processing, this system translates into an edge detection algorithm applied to
an input image. The edges of an image, on the other hand, can be defined as
transitions between two regions of significantly different gray levels that provide
valuable information about the image. This information can be used to carry out
some tasks, such as image segmentation, object recognition, among others. To
solve the edge detection problem, there are a large number of algorithms that
use different techniques or methods and it is difficult to establish a definitive
method to carry out this process. Among all the existing techniques there is
the canny algorithm which is a robust method widely used for the detection
of image edges. In this work, we propose a combination between two methods;
canny algorithm and the Hough transform, in order to generate a competent
edge detection algorithm against others that only use variations of the canny
algorithm. In order to measure the effectiveness of the proposed method, we are
going to use the metrics: sensitivity, specificity and miss rate.
This document is organized as follows. Section 2 describes the most relevant
related works. Materials and the data set are presented in section 3. Section 4,
is about the method that was be used. In section 5 we present the experimental
setup. Finally in section 6, we talk about the obtained results.
2 Related Works
In the last years, different works have been performed and showed different re-
sults in the searching of a efficient method for lane boundaries detection. X. Li
et al [6] has proposed detect the vertical straight lanes of interest using Hough
transform and a straight line end filtering through a simulation by least square
method. The proposed approach is the implementation of the canny algorithm
on a pre-processed image, with a subsequent delimitation of the region of in-
terest. To finally find the straight line segment of the image using the Hough
transform and a filtered and simulated by least square method. Combining the
linear equation and mark the lane line. A. Singh [7] has proposed has proposed
states that for vehicles to be able to drive by themselves, they need to under-
stand their surrounding, to navigate their way in streets, pause at stop signs and
traffic lights to avoid hitting obstacles. The proposed approach use OpenCV li-
brary and its functions such as the Canny Function through to perform the edge
detection and Hough transform to detected the straight lines in the image. Ad-
ditionally, Singh use a mask of zero intensity to mapped the region of interest
to delimit the image. R. Johan et al [8] has developed an algorithm using canny
edge detector and Hough transform capable to be mounted on a Raspberry Pi.
The algorithm was designed to perform the lane detection with real time im-
ages. Johan, used a camera mounted in the front of vehicle to collect the images.
The algorithm was developed on OpenCV and Python. First of all canny edge
detector and hough transform were implemented on MATLAB, and tested with
a recorded videos. The algorithm successfully detected lane on different videos.
After testing on MATLAB algorithms were implemented on raspberry pi using
openCV and python. Raspberry Pi with camera was mounted on front of ve-
hicle and tested. The algorithms were successfully detected lanes on real time
streaming[8]. G. Deng and Y. Wu [9] has proposed a lane detection method based
on the constraint of a Hough Transform double edge extraction. The proposed
approach, perform a Hough transform based on polar angle and polar radius
constraints to obtain the double edges of the lane lines for straight lane line. For
the curves, the detection method of the straight lane line are searched in a lane
line characteristic diagram to later be fitted by a parabola. X. Yan and Y. Li.
[10] states that, lane detection is one important process in the vision-based vehi-
cle assist system and the complicated conditions of road make the correct edge
detection of lane become very challenging. Yan has proposed a method of lane
edge detection based on Canny algorithm along with Hough transform theory
and a division of the road image into three regions. They use the shape features
of lane marks, to determine the region with useful information and then perform
the lane edges detection only in this region.
3 Matherials
3.1 Dataset
The dataset [5] for this work is used for testing and evaluation of lane detection
algorithms, includes 40 video clips with a frame rate of 30 fps and video reso-
lution of 1920 x 1080. It is collected in some sections of Jiqing (Jinan-Qingdao)
expressway, China
We experimented the proposed technique in ten frames obtained from five
different videos randomly taken from the dataset. These images contain paved
highways which are totally and partially marked.
4 Method
1. Preprocessing
Conversion to grayscale
When the image is in grayscale, the white or yellow lines of the road image will
show a particularly high contrast, which will help to make the image easier to
Fig. 2: Proposed method
Conversion to HSV
Having the original image, the image display will be processed and explored in
another color space, such as HSV (Hue, Saturation and Value), which allows
better segmentation of yellow lines.
Thresholding
The lane boundaries are defined by a strong contrast between the surface and the
painted lines along the road. These sharp edges are edges in the image. There-
fore, edge detection is very important in determining the location of a lane’s
borders.
For our purposes, it is necessary the use of the Canny’s algorithm. Canny’s
algorithm consists of multiple stages, where the first takes the original image,
and the results of each stage are passed as input to the next, until the last one
that generates the final result. The stages are the following:
1. Image smoothing using Gaussian filter to eliminate the noise.
2. Gradient calculation using Sobel operator to highlight regions.
3. Non-maximum suppression to the gradient result.
4. Threshold hysteresis to track along the remaining pixels that have not been
suppressed in the third step. This process aims to reduce the possibility of
appearance of contours false.
Image smoothing
Gaussian filter can effectively suppress noise and smooth image and its function
is given as:
−(x2 +y 2 )
1
G(x, y) = 2πσ 2 e
2π 2
Once a suitable mask has been calculated, the Gaussian smoothing can be per-
formed using standard convolution methods.
Where, f (x, y) is the original image, and σ is the parameter of Gaussian filter
which controls the degree of denoising.
Gradient calculation
After applying the Gaussian filter to the original image to soften the image and
try to eliminate possible noise, the next step consists in applying a first deriva-
tive operator to the smoothed image to highlight certain regions of the image
with high first spatial derivatives.
Then, image is filtered with a Sobel kernel in both horizontal and vertical
direction to get first derivative in horizontal direction Gx and vertical direction
Gy [3].
Finally, the magnitude G and the slope θ of the gradient are calculated as
follow [3]:
q
G= G2x + G2y
G
θ = arctan ( Gxy )
Non-maximum suppression
Once we know which neighbors to look at, we compare the value of the
magnitude of each pixel with the magnitude of its neighbors in the direction of
the intensity gradient, which is the angle obtained in the previous stage. The
intensity value of the current pixel is set to 0. In the case that there are no pixels
in the edge direction having more intense values, then the value of the current
pixel is kept. It will only be considered as border that pixel whose magnitude
is greater than the magnitude of its neighbors. As result, we obtain the same
image with thinner edges [4].
Threshold hysteresis
The image obtained usually contains local maximums created by noise. To elim-
inate the noise we apply the threshold hysteresis. It consists of taking the image
obtained, taking the orientation of the image’s edge points and taking two thresh-
olds, the first one smaller than the second.
For each image point, the next unexplored edge point that is greater than
the second threshold must be located. From this point on, follow the chains of
local maximum connected in both directions perpendicular to the edge normal,
provided they are greater than the first threshold. This marks all the scanned
points and stores the list of all the points in the connected contour. In this way
it is possible to eliminate the Y-shaped joints of the segments that meet at a
point.
3. Lane Detection
Region of Interest
The next step is to determine region of interest (ROI) and discard any lines out-
side of this area. That is, given the processed image, a portion of it is determined
where it is desired that the lanes remain and that the rest be discarded.
Hough Transform
In order to detect the straight lines of interest and draw them on the image it
is necessary to apply The Hough Transform technique. The goal of the Hough
Transform is to find lines, identifying all the points that are found on them.
This is done by converting the current system denoted by the (x, y) axis to a
parametric one where the axes are (m, b). In this plane the lines are represented
as points, the points are presented as lines and the intersecting lines means that
the same point is on several lines.
5 Experimental setup
The experiments were performed in two different ways. On one hand, the lane
detection was limited a region of interest (ROI). In this case, the purpose was
detect just the lane boundary corresponding to the car location. Choosing an
appropriate ROI not only minimized the search area in images but also diminish
the interference from extraneous objects.
Some of our first and second experimental results where detected lane bound-
aries are superimposed onto the original images, are showed in Figure 1 and 2
respectively.
The test results were obtained in a machine with the next characteristics:
CPU(s) 4
Threads 2
Model Intel(R)Core(TM) i7-4510U CPU
HZ 2.00
Architecture x86 64 (Little Endian)
Python 3 For develop the project we use python, because it is dynamic, cross-
platform and interpreted language, that allows a more comfortable handling of
the images in the pre-processing and in the obtaining of the final result.
We have 2 executable files: Project.py and Auto.sh The first contain the algo-
rithm that perform the image processing, the second contain the automatizing
of it.
Auto.sh This file allows us to automatizing the process of testing. In the file
we define the folder of input that contain all images that would be processed,
and the folder where the output must be stored.
Project.py This file can be divided into 3 sections: pre processing, Canny ap-
plication, Hough application.
Parameters
Experiment 1: Car Lane Detection In Figure 1, are showed the results of the
first experiment. The first column contains five different elements corresponding
to the original images, the second one contains the ground truth corresponding
to the data set used for the experimental setup in which the lane boundaries are
marked with red color, and the last one shows the experimental results with the
lane boundaries marked with blue color. It can be seen in these results that the
algorithm accurately acquire the boundaries of the lane in which is the car. It
can also be observed that the detection of the pixels is limited to the defined
region. Data pixel that is not used was eliminated by the threshold segmentation
operation, before the Canny edge detection and Hough Transform. At the same
time, the wrong detection in the last image is produced due to a section in the
road that is not paved, which allows to deduce that the algorithm works just in
roads which are perfectly paved.
(a) Frame 1 (b) Ground Truth (c) Result
Fig. 3: Results of Experiment 1. The first column shows the original frames. Lanes
are marked with red and blue color for ground truth and results respectively.
(j) Result 10
Fig. 4: Results of Experiment 2. Detected lanes are marked with blue color.
6.1 Evaluation metric
To facilitate the evaluation of the performance, it is necessary the use of the cor-
responding evaluation metrics for our data set. We use sensitivity, specificity, and
miss rate (false negative rate) as the evaluation criterion of the first experiment.
The metrics are computed in the following way:
TP
Sensitivity = T P +F N
TN
Specificity = T N +F P
FN
Miss Rate = F N +T P
where:
Conlusion
1. Biswas, R., Sil, J. An Improved Canny Edge Detection Algorithm Based on Type-2
Fuzzy Sets. In: Procedia Technology, 2012.
2. Hosang, J., Benenson, R., Schiele, B. Learning non-maximun supression. In: ICCV,
2017.
3. Mokrzycki, W., Samko, M. New version of Canny edge detection algorithm. In
ICCVG: 2012.
4. OpenCV-Python Tutorials, https://opencv-python-tutroals.readthedocs.io. Last ac-
cessed 15 Apr 2020
5. Feng, Shengjia., Wang J, M.,Zhu D., Yuan C. Jiqing Expressway Dataset.
https://github.com/vonsj0210/Multi-Lane-Detection-Dataset-with-Ground-
Truth/blob/master/README.md. (2019)
6. X. Li, P. Yin, Y. Zhi, and C. Duan. (2020). Vertical Lane Line Detection Tech-
nology Based on Hough Transform. In IOP Conference Series: Earth and En-
vironmental Science (Vol. 440). IOP Publishing. https://doi.org/10.1088/1755-
1315/440/3/032126
7. A. Singh. (2019). Lane Detection for Autonomous Vehicles using OpenCV Library.
International Research Journal of Engineering and Technology (IRJET)
8. R. Jahan, P.Suman and D. Kumar. (2018) LANE DETECTION USING CANNY
EDGE DETECTION AND HOUGH TRANSFORM ON RASPBERRY PI. Inter-
national Journal of Advanced Research in Computer Science.
9. G. Deng and Y. Wu. (2018). Double Lane Line Edge Detection Method Based
on Constraint Conditions Hough Transform. 2018 17th International Symposium
on Distributed Computing and Applications for Business Engineering and Science
(DCABES), pp. 107-110, doi: 10.1109/DCABES.2018.00037.
10. X. Yan and Y. Li. (2017). A method of lane edge detection based on Canny al-
gorithm. Chinese Automation Congress (CAC), Jinan, 2017, pp. 2120-2124, doi:
10.1109/CAC.2017.8243122.