Welcome to my Lane Detection project! This repository implements a full lane detection pipeline using classical computer vision techniques. The project is written in C++, uses OpenCV, and is structured with modularity in mind, similar to real-world robotics and embedded systems codebases.
Before deep learning became mainstream, lane detection relied purely on geometry, not neural networks. This project recreates that classical approach from scratch.
You might be asking:
“Why bother with classical methods when I could train a deep learning model?”
Great question, here’s why I think traditional methods still matter:
- Real-time performance: Runs at full FPS even on low-power CPUs
- No GPU required: Works on embedded devices
- No training data: No dataset collection, labeling, or training pipeline
- Interpretable: Every step is transparent and tunable
Before AI, lanes were detected because of simple geometric properties:
- Road edges -> strong gradients -> extract with Canny
- Lane lines -> mostly straight -> detect with Hough Transform
- Left/right lanes -> opposite slope signs -> filter by slope
- Parallel lines -> appear to converge -> average slopes + intercepts
Despite their simplicity, these techniques still deliver surprisingly good results.
This pipeline follows the classic highway lane-detection sequence:
Load dashcam footage using cv::VideoCapture.
Mask everything except the road area directly ahead. This removes irrelevant edges such as sky, signs, trees, and guard rails.
Lane detection relies on contrast, not color.
Smooths noise and prevents false Canny responses.
Extracts strong gradients which is ideal for detecting lane boundaries.
Only edges inside the polygon-shaped ROI are kept.
Detects straight lines from the masked edge image.
- Negative slope -> left lane
- Positive slope -> right lane Weighted by segment length for stability.
Two stable, long lane boundaries are drawn on the original image.
Each step of the pipeline is implemented inside its own .cpp and .h files for clarity and modularity.
CMake is a build system generator.
It reads your CMakeLists.txt and generates build instructions for your compiler.
CMake = the recipe writer It writes how your program should be compiled.
Make is the actual build tool. It reads the Makefile generated by CMake and compiles your code.
Make = the chef It cooks according to CMake’s recipe.
- First time setting up the project
- You add/remove
.cppfiles - You modify
CMakeLists.txt - You reorganize files/folders
- You edit any existing
.cppor.hfile - You want to rebuild after small code changes
- You already ran
cmake ..at least once
In the output, the left and right lane lines may appear to intersect at the top of the image. This is normal in classical lane detection.
- Real lane lines are parallel in the real world
- A camera projects 3D -> 2D, creating a vanishing point
- All parallel lines appear to converge at that point
- The algorithm extends lane lines using slope + intercept
- Extended straight lines naturally meet at the horizon
This project demonstrates how classical computer vision can still deliver effective lane detection:
- Real-time performance
- Transparent and interpretable steps
- No machine learning required
- High portability (runs anywhere C++ and OpenCV can run)