How to identify lane lines through computer vision

For various reasons, the tweets were not updated last month, so I would like to apologize for this tweet.

Today is how to identify lane lines through computer vision. In fact, there are various ways to identify lane lines. This time is based on the Matlab implementation, the implementation of the Python version will be updated in a few days, although the language used is different, but the principle is the same.

Pretreatment

The video images obtained by the camera are affected by the surrounding environment, and there is a lot of useless information and various noise interference. In order to accurately detect the road line, the image must be preprocessed. First, the original color image is converted into a gray image by grayscale processing, and then a Gaussian filter smoothing process is performed using a template of size 5*5 to reduce noise interference. The specific operation of Gaussian filtering is to scan each pixel in the image with a template (or convolution, mask), and replace the value of the center pixel of the template with the weighted average gray value of the pixels in the neighborhood determined by the template.

If a 3×3 template is used, the calculation formula is as follows

g(x,y)={f(x-1,y-1)+f(x-1,y+1)+f(x+1,y-1)+f(x+1,y+1 )+[f(x-1,y)+f(x,y-1)+f(x+1,y)+f(x,y+1)]*2+f(x,y)*4 }/16;

Where f(x, y) is the gray value of the (x, y) point in the image, and g(x, y) is the value after the point is Gaussian filtered.

Since the sky does not have a region of interest for the lane, the picture is divided to divide the region of interest into a triangular region. Figure 1.

Figure 1

The preprocessing code is as follows:

% read in RGB image

I=imread('IMG00061.jpg');

% converts RGB images to grayscale

I=rgb2gray(I);

% Gaussian filter smoothing

Sigma = 1;

gausFilter =fspecial('gaussian', [5,5], sigma);

Gaus= imfilter(I, gausFilter, 'replicate');

% get the width and height of the picture

[h, w]=size(I);

%k is the slope of the line

% find the region of interest of the image

k = 1.3;

For y=1:h

For x=1:w

If y < x*k + hk*w || y < -k*x +h

I(y, x) = 0;

End

End

End

Edge detection

Since the gray level of the lane line is brighter than the road surface, the edge of the lane can be detected by edge detection. In edge detection, I used the 'Sobel' operator. Technically, it is a discrete difference operator that is used to calculate the approximation of the gray level of the image brightness function. Using this operator at any point in the image will produce the corresponding gray vector or its normal vector

The Sobel convolution factor is:

The operator consists of two sets of 3x3 matrices, which are horizontal and vertical, respectively, and are planarly convolved with the image to obtain lateral and longitudinal luminance difference approximations. If A represents the original image, Gx and Gy represent the gray value of the image detected by the lateral and longitudinal edges, respectively, and the formula is as follows:

How to identify lane lines through computer vision

The horizontal and vertical gray values ​​of each pixel of the image are combined by the following formula to calculate the size of the gray level of the point:

Usually, to increase efficiency, use an approximation that does not open the square:

The results obtained are shown in Figure 2:

figure 2

Hough transform line detection

Hough transform can be performed on the image with the binary image of edge detection. Hough transform is one of the classical methods in image transformation. It is mainly used to separate geometric shapes (such as straight lines) with certain features from the image. , round, etc.). The principle of Hough transform is to transform the points on a particular graph into a set of parameter spaces, and find a solution corresponding to the maximum value according to the cumulative result of the parameter space points, then the solution corresponds to the parameters of the geometry to be searched ( For example, a straight line, then you will get the slope k of the line and the constant b, the circle will get the center and radius, etc.). After the Hough transform, a graph of ρ and θ as shown in Fig. 3 can be obtained.

image 3

The brightest points in the figure are peaks, and there is a high probability that there is a straight line in the peak. You can select a set of candidate peaks and then determine the starting and ending points of the line. The function houghlines performs this task with the default syntax:

Lines = houghlines(f, theta,rho, peaks)

Or use the full syntax form:

Lines = houghlines(...,'FillGap', val1, 'MinLength', val2)

Among them, theta and rho are the output from the function hough, and the peaks are the output of the function houghpeaks.

effect

For the sake of beauty and effect, I have extended the detected line segments. The effect is shown in Figure 4.

Figure 4

The complete code is as follows:

Clear

Close all

% read in RGB image

I=imread('IMG00061.jpg');

% converts RGB images to grayscale

I=rgb2gray(I);

% Gaussian filter smoothing

Sigma = 1;

gausFilter = fspecial('gaussian', [5,5], sigma);

Gaus= imfilter(I, gausFilter, 'replicate');

% get the width and height of the picture

[h, w]=size(I);

%k is the slope of the line

% Cut the map to find the region of interest of the image

k = 1.3;

For y=1:h

For x=1:w

If y < x*k + hk*w || y < -k*x + h

I(y, x) = 0;

End

End

End

Imshow(I)

%Use Sobel operator for edge detection

BW = edge(I,'sobel');

% Hough transform

[H,T,R] = hough(BW);

Imshow(H,[],'XData',T,'YData',R, 'InitialMagnification','fit');

Xlabel('heta'), ylabel('ho');

Axis on, axis normal, hold on;

% find the peak of the Hough transform

P = houghpeaks(H,2);

% Hough transform detection and connection line

Lines = houghlines(BW,T,R,P);

Figure;

Imshow(I); hold on

% draw line

For k = 1:length(lines)

P1 = lines(k).point1;

P2 = lines(k).point2;

Syms slope b

[b, slope] = solve(slope*p1(1)-p1(2)+b, slope*p2(1)-p2(2)+b);

Plot([(hb)/slope, (0.4*hb)/slope], [h, 0.4*h], 'g-', 'LineWidth', 3);

End

The image used in the code:

How to identify lane lines through computer vision

12mm Metal Push Button Switch

12mm LED Metal Push Button Switch


Yeswitch 12mm Metal Pushbutton switch is CUL & CE certified, it offering a rating of 2A/36VDC. Additional features include IP65 rating, with Momentary and Self-Locking operation function and a long operating life of up to 1,000,000 life cycles (Momentary) and 500,000 (Self-Locking)

The 12mm series LED Metal Switches require 12mm panel cut-out size. LED pattern options include Dot, E-ring and Power Logo and Many LED color options are available.



Specification:

RATING

2A/36VDC

SWITCH COMBINATION

1NO

OPERATION TYPE

Momentary/Self-locking

MECHANICAL LIFE

Momentary 500,000 cycles

Self-lock 500,000cycles

ELECTRICAL LIFE

50,000 make-and-break cycles at full load

PANEL THICKNESS

1-6mm

INGRESS PROTECTION

IP65, IK08/(Stainless)



Metal Pushbutton switch



Our Advantages

From the purchase of raw materials to the finished product, all production process (product development/plating/mold and equipment processing/ metalpressing/ plasticinjection/semi-automatic and fully automated equipment assembly, etc.) are completed in the factory. Our metal pressing and plastic injection own the advantages of 100% self-made mold, from a single form to the various forms of application. And we continuously keep innovation and enhance the technology in order to collaborate with our customers to design the most sophisticated products. Yeswitch Electronics Co., Ltd., whether in production base or in quality assurance department in the head office, have professional equipment and technical personnel. In addition to the annual new product development, product improvement and testing are performed as annual plan to ensure that listed products maintain in best quality. Therefore, our long-term customers/partners, get the best quality of the switches.

Anti Vandal Switch


Push On Push Off Switch


Illuminated Push Button Switch



LED metal pushbutton, Waterproof Metal Switch, UL metal switch

YESWITCH ELECTRONICS CO., LTD. , https://www.yeswitches.com