Skip to content

A simple algorithm to perform lane detection and turn prediction for a self driving car

License

Notifications You must be signed in to change notification settings

llDev-Rootll/Lane_Detection-Turn_Prediction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lane_Detection

This project outlines a simple algorithm to perform lane detection and turn prediction for a self driving car. This will attempt to replicate techniques used in lane departure and warning systems. The video used for this project can be found here.

Procedure

Lane Detection

  • Each frame of the video is read sequentially
  • Each image is undistorted by using the camera matrix and the distortion coefficients provided here.
  • The lane lines in the video are of two colors, yellow and white, therefore extraction of both is important.
  • The image is converted to the HSV color space and a mask for the yellow line is generated by using the threshold values for yellow.
  • Next, the original image is converted to grayscale and aggressive thresholding is performed. Finally the mask with the yellow line is added to this image.
  • Canny edge detection is used to extract edges from this image.

edges

  • A trapezoidal region of interest is then defined and the following operations are performed only withing this region of interest.
  • We then use probabilistic hough transform (ro=6, theta=3, threshold=35, minimum_line_length=40 and maximum_line_gap=150) to detect lines in the edge map.
  • Since this operation fits multiple lines for each edge we will now compute the optimal line for each left and right lane marker.
  • This is done by computing the average intercept and slope for all lines pertaining to the left and right lane marker respectively. The lines pertaining to these slopes and intercepts are considered to be the detected lane markers.
  • The center line of the lane is then computed by taking the average of the x and y co-ordinates of lane markers.
  • The OpenCV polyfill function is used to fill the lane on a blank image and a weighted sum of the lane mesh with the original image is used to overlay the lane mesh on the road.

lane_markers

Turn Prediction

  • Turn prediction is achieved by using the center line of the lane. Since the the center of the road keeps shifting in the video, a static point of reference cannot be used to infer whether the car is veering to the left or the right.
  • Hence, the x co-ordinate of the bottom most point of the center line is used as the dynamic point of reference.
  • The deviation of the top most point of the center line is used to determine whether the car is to turn left, right, or remain heading straight. Appropriate thresholds are set for the same.

c_img

The final result is show below.

lane_detect

Steps to run the program

Clone this repository and run the follow line in the terminal to run the lane detection and turn prediction algorithm for the given video.

cd ...<path_to_repository>/code/
python3 lane_detect.py

About

A simple algorithm to perform lane detection and turn prediction for a self driving car

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages