OpenCV C++ program that identifies and tracks lanes and their intersection. Can be used for autonomous driving features such as lane changing, blindspot detection, hill crest detection, turn detection and sign recognition. Works on input video, image or live video feed.
Detect lanes and their respective intersection point on the horizon in order to track the point’s movement to determine if the vehicle is turning or changing slope.
- Input Video:Pikes Peak race track (on road and off road)
- Youtube Demo
- Language: C++ (OpenCV)
- IDE: Xcode
- Signal Processing:
- Canny edge detector
- Hough line detector
- Slope and turn tracking(incomplete)
- Customizable ROI
- video or image file, or video feed
- (optional) xcode to utilize the included project file
How to use
I have only worked with this on osx so you may be on your own!
brew install opencv
- Set path to input file in
- Configure options in
houghVotedetermines the fidelity of the line recognition (higher means more lines kept)
- Under the
// Set up windowsyou can enable or disable windows of your choice
- Also may be necessary to modify the ROI (region of intrest) to best capture the road
- Can uncomment the
VideoWriterline to write the output to file
- Run program
- Either using the xcode project file
g++ $(pkg-config --cflags --libs opencv) LaneDetect.cpp(this works on my system, but may vary. It should run on
Edge Detection Implementation Basics
- Apply Gaussian filter to smooth the image in order to remove the noise
- Find the intensity gradients of the image
Canny Edge Detection
Line Detection Implementation Basics
- Extract edge points and map to lines by representing in polar form
- Store lines in an accumulator
- Find stored lines of infinite length using thresholding and filtering
- Convert infinite lines to finite lines
Line Detection result
Add up number on lines that are found within a threshold of a given rho,theta and use that to determine a score. Only lines with a good enough score are kept.
Calculation for the distance of the car from the center. This should also determine if the road in turning. Might not want to be in the center of the road for a turn.
Several other parameters can be played with: min vote on houghp, line distance and gap. Some type of feed back loop might be good to self tune these parameters.
Added filter on theta angle to reduce horizontal and vertical lines. Added image ROI to reduce false lines from things like trees/powerlines
General idea and some code modified from: chapter 7 of Computer Vision Programming using the OpenCV Library by Robert Laganiere, Packt Publishing, 2011.