Git Product home page Git Product logo

lane-line-detection's Introduction

Lane Line Detection

Detecting Lane lines is one of the most fundamental concepts for building a Self Driving Car. In this repository, I have used OpenCV to detect lane lines in a sample video sample obtained from a camera places on a car.

You need OpenCV to run this project on your local machine and it can be installed simply by a single command -
pip install opencv-python

Demo

How to run

  1. Download/Clone the repo.
  2. Make sure you have OpenCV installed for Python.(I recommend installing it on top of Anaconda Distribution)
  3. Execute the lanes.py script
python lanes.py
  1. Make changes accordingly to use any other video file you might want to.(You can also use a static image, I have commented the image code since video is more useful.)

Intuition behind Concepts

Every image is essentially a numpy array at the end of the day, with values containing pixel intensities, 0 denoting complete black(dark) and 1 denoting complete white(bright), considering a grayscale image.

1. Gaussian Blur

Used to reduce noise and smoothen out the image. We generally use a kernel of some specific size(say 5x5) and a deviation

Gradient

The above image shows a Strong gradient on the left and a Weak Gradient on the right.

Gradient : Change in brightness over a series of pixels.

2. Canny Edge Detection

As the name suggests, it is an algorithm to detect edges in our image. A change in intensity of pixels will give us an edge.

Small change will imply small change in intensity whereas a Large derivative is a large change.

cv2.Canny(image,low_threshold,high_threshhold)

If a gradient is larger than the high_threshold, then it is accepted as an edge pixel. If it is below the low_threshold, it is rejected. Always use a ratio of 1:3 or 1:2.

NOTE : Line 34 in the code is optional and can be omitted, since the Canny function automaticallyapplies a Gaussian Blur with a kernel of 5x5.

Example :

cv2.Canny(image,50,150)

3. Hough Transform

After we have successfully detected edges in our image, it's time to detect lane lines in our image, for which we can use the Hough transform.

Before that, we need to find the Region on interest in our image. For that, we use Matplotlib to get a fair enough idea about the coordinate values of the image.

Once we are done, we create a mask with a polygon over it as shown : Mask

0000 represents the black pixels and 11111111 represents the white pixels, denoting the polygon. Now, we apply the bitwise_and in the original image and the mask to obtain the masked_image, which essentially will contain only the region on interest.

Masked Image

Ultimate Result

Final Masked Image

Finally, now when we have only the Region of interest in our image, we will use Hough Transform to detect Straight lines in our image.

Equation of a straight line can be given as : y = mx + c, where 'm' is the slope and 'c' is the y-intercept.

We can transform every line from 2D Space(X vs Y) to the Hough Space(M vs C). Just remember that - A single point is 2D Space is represented by a line in Hough Space.

Ultimate Goal - Try to find a line that best describes our points.

lane-line-detection's People

Contributors

rbhatia46 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lane-line-detection's Issues

overflow error

when i process this program about 10 seconds, it returns

cv2.line(line_image,(x1,y1),(x2,y2),(255,0,0),10)
OverflowError: signed integer is less than mininum

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.