Git Product home page Git Product logo

lane-detector's Introduction

Lane-Detector

An OpenCV implementation of road lane detection written in Python.

Usage

This project requires

  • matplotlib
  • cv2

To run, clone this repository and use

python laneDetector.py --path <path to image>

Method Summary

  • Thresholding
  • Canny Edge Detection
  • Region of Interest Selection
  • Hough Transform Line Detection
  • Line Averaging

Input

I used an image from the Cityscapes dataset.

Thresholding

Thresholding is possibly a better option than converting an RGB image to HSV or HSL colour space as you're not always guaranteed of lines being an exact white or yellow.

Threshold is applied using

retval, threshold = cv2.threshold(convertGrayScale(img), 115, 255, cv2.THRESH_BINARY)

The parameters supplied to threshold can be tweaked. 115, 255 worked well for me. This gives

A gaussian kernel of size 3 is applied to blur out any rough lines and gives

Canny Edge Detection

Region of Interest Selection

The lanes, more often than not, fall within the polygon below. The vertices correspond to

a = [0, 1023]
b = [0, 630]
c = [720, 455]
d = [1505, 511]
e = [2047, 689]
f = [2047, 1023]

After filtering the image becomes

Hough Transform Line Detection

The parameters ho – distance resolution of the accumulator in pixels, theta – angle resolution of the accumulator in radians, threshold - only those lines are returned that get more votes than the threshold, minLineLength – segments shorter than this are rejected, and maxLineGap – maximum allowed gap between points on the same line to link them, can be tweaked to vary output. I used

cv2.HoughLinesP(image, rho = 1, theta = np.pi / 180, threshold = 20, minLineLength = 20, maxLineGap = 300)

Line Averaging

Each of the multiple line sets are averaged into one line. To do this I found lines with similar slopes and averaged them into one line. One limitation of this implementation is that it only considers two lanes for final output. However the two lanes can both be left lanes or right lanes unlike other implementations that look for one left and one right lane.

lane-detector's People

Contributors

acvictor avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.