Lane Boundary Detection Using Open CV

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Lane Boundary detection using Canny algorithm

Rafael Valencia-Ramos1[0000−0002−1036−1817] and Ronny


Cortez1[0000−0001−7705−1293]

Yachay Tech University, Urcuqui, ECU

Abstract. This article proposes a lane detection method based at the


combination between, Canny algorithm and the Hough transform. First,
the area of interest is extracted from the image of the road, cutting
out unnecessary scenes by removing sections with irrelevant information.
Subsequently, the image undergoes two modifications in the color model,
first it is transformed to an HSV model, the result of which is transformed
into a gray scale in order to highlight the yellow colors in the image.
Then the gray scale image is blurred before being used in Canny’s edge
detection algorithm with which we get the edges of the image. Finally,
the Hough transform with restriction in the polar angle is used in order
to identify only lines that meet an inclination of approximately 45o .
Experiments show that lane detection using the proposed method shows
very good values in one of the three metrics that were used.

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.

Fig. 1: Images from dataset collected in some sections of Jiqing, China

4 Method

The proposed method structure is shown in Figure 2. In the following sections,


each phase will be explained with detail.
The algorithm works principally with an image converted to a grayscale. To
detect edges it is necessary to smooth the image since, in presence of noise, the
image will hinder the correct edge detection. Hence, a Gaussian filter is applied
to make the edge detection more accurate. Then the edge detector was used
to produce an edge image by using canny filter with an specific thresholding
to obtain the edges. After that, information of the edged image is used by the
Hough transform to perform the lane detection.

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

treat it and minimize the processing time. Therefore, it is important to convert


the image into grayscale.

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

After grayscale conversion, we use thresholding to binarize the image We get


those pixels that can be white lanes depending if they are within the threshold
range.
Mask of yellow and white pixels

In order to obtain a better segmentation of the lanes,it has to be performed a


masking take into account the upper and lower values to be able to detect pixels
in yellow and white colors.

2. Canny Edge detection

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

Noise in an image can cause false edge detection, so it is necessary to apply a


filter to reduce any noise as a first stage. For Canny’s algorithm, a Gaussian
filter it is applied using a simple mask.

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.

The convoluted image is given as [3]:


f1 (x, y) = G(x, y) ∗ f (x, y)

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

Non-maximum suppression is a technique used in many computer vision algo-


rithms. It consists of eliminating those pixels that compared to its neighbors,
they have a smaller magnitude [2]. The process on this stage is developed on the
following way:

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.

On the other hand, we do not consider a region of interest in order to detect


all the lane boundaries present at the highway. The proposed method is robust in
terms of detecting the white and yellow lanes on the road, however the presence
of cars, shadows, variations in illumination or different road conditions produces
difficulties for the detection.

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.

5.1 Hardware Description

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)

5.2 Software Description

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.

Open CV To handle the images, we use Open CV library. It is a machine vision


free library, originally developed by Intel. Open CV stands for Open Computer
Vision. This library allows us to perform, motion detection, object recognition,
3D reconstruction from images, among others, this library is compatible with
python and C.
Bash script Bash Script was used to perform the automatizing of the test. It
allowed us read N images with different names and store the output in a specific
folder that contain all outputs images.

5.3 Implementation and parameter settings

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

RGB Yellow color (255,255,0)


Lower yellow (Hue+10, 100, 100)
Pre processing
Uper yellow (Hue-10, 255, 255)
Threshold 200
Low threshold 12
Low threshold ratio 0,03
Canny edge detection
High threshold 31
High threshold ratio 0,07
Rho 1
Theta pi/80
Hough Transform
Min line gap 30
Max line gap 50

6 Results and discussion

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

(d) Frame 2 (e) Ground Truth (f) Result

(g) Frame 3 (h) Ground Truth (i) Result

(j) Frame 4 (k) Ground Truth (l) Result

(m) Frame 5 (n) Ground Truth (o) 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.

Experiment 2: Highway lanes detection In Figure 4 we can observe the


result of 10 frames processing using our algorithm. In the images 5a, 5b, 4c and
4j we can observe a correct detection of the lane way. In some parts of the image
we can see small sections of the line that are not detected correctly. However,
the direction of the road can be easily distinguished. In the images 4d, 4e, 4f and
4g, we can observe that exist noise, this is due to the fact that there are cars on
the road that are white or that contain some part of the color white. The noise
is generated since the white colors are highlighted in the threshold procedure,
so it is interpreted that the car or part of the car it is a lane of the way. In the
images 4h and 4i, we can see a noise, due to the lane protectors that have a
white shade due to light.

(a) Result 1 (b) Result 2 (c) Result 3

(d) Result 4 (e) Result 5 (f) Result 6

(g) Result 7 (h) Result 8 (i) Result 9

(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:

TP = number of correctly predicted lane points


TN = number of correctly predicted points which are not part of the lane
FP = number of incorrectly predicted lane points.
FN = number of incorrectly predicted points which are not part of the lane

Results of the evaluation metric are showed in Table 1 and Figure 3.

(a) Sensitivity and Miss Rate (b) Specificity

Fig. 5: Graphics based on quantitative results


Table 2 shows the metrics of the results obtained by the firsT experiment.
In this case, based on the sensitivity results, the use of a region of interest
was relevant in the lane recognition, however, despite there is a high number of
correct pixels detected, several pixels that not correspond to the lane segment
also were wrongly detected by the algorithm.

Conlusion

In conclusion, the lane detection method based on the combination of Canny’s


algorithm and the Hough transform, has drawbacks or detection failures when
the general scene of the image contains colors similar to those of the lines dividing
the lane. On the other hand, the metric that evaluates sensitivity presents good
general results. Based on this, we can conclude that the method works correctly
with images that do not present scenarios where white or yellow predominate,
typical colors of the lines that divide the lane.
References

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.

You might also like