Project · 02
Lane Detection Automation
Computer Vision / Robotics
A robot that spots lane lines and figures out which way the road turns.
- Year
- 2024
- Stack
- Python · OpenCV · NumPy · Tkinter · HTTP requests

Overview
This one went through two versions. The first runs on recorded road video — it picks out the lane lines, finds the middle of the lane, guesses if the road is turning left, right, or going straight, and draws all of that back on the video.
The second version does it on a live camera feed from the robot and adds a control panel (Tkinter) that sends movement commands to the robot over HTTP.
- Recorded and live video processing
- Yellow lane color filtering
- Bird's-eye perspective transform
- Grayscale + Canny edge detection
- Probabilistic Hough line detection
- Slope- and position-based lane filtering
- Lane-center estimation
- Turn prediction (left / right / straight)
- Lane overlay projected back onto the frame
- Tkinter control panel with live video
- Movement commands sent to the robot over HTTP
- Account login and per-user command log
Focus
- Classical computer vision
- Perspective transforms
- Edge detection
- Hough line detection
- Network-based control
Architecture
The images below are the real output of each step on one frame of the night drive.
The original version had the perspective window hardcoded for one camera and judged every frame on its own, so on new footage the lines would glitch. Now it calibrates the window itself every few frames, only looks for each lane near where it was last frame, and takes a median over the last few detections so a bad frame or two can't make the lines jump. If a lane drops out or wanders off, it's rebuilt from the other one using the lane width.
The demo footage is two dashcam clips (a sunset highway and a night drive), not my original road video. The live robot version runs a simpler take on the camera feed: grayscale, blur, Canny, Hough, and a slope filter.
Source
- Video / Camera Feed
- Image Preprocessing
- Perspective Transformation
- Edge Detection
- Hough Line Detection
- Lane Filtering
- Lane Geometry
- Steering / Turn Decision
- Robot Control Interface

One raw frame from the night drive, inside a tunnel. 
Pixels in the yellow range get brightened. The tunnel lights tint the lane lines warm, so they pass. 
Auto-calibrated from the vanishing point and my own lane's two lines.

That window warped to a top-down view, so the lanes run straight up. 
Grayscale, then Canny keeps only the sharp edges. 
Near-vertical segments, sorted into left (blue) and right (red). The middle blue one is a seam in the road, too far from the lane to be kept. 
Smoothed lane lines and the lane center, which drives the turn call.

The overlay run through the inverse warp, back into the camera's view. 
Added onto the original frame.
The robot
The live version ran on a small tank robot built from a XiaoR Geek TH tank chassis kit (opens in a new tab), with a Raspberry Pi 1 Model B+ (opens in a new tab), a battery pack, and a cheap webcam on top.
The Pi didn't do any of the vision work. It ran a small live API that streamed the webcam feed to my computer, the computer ran the lane detection and worked out the movement commands, and those got sent back to the robot to drive it.
The prototype had the webcam taped straight onto the chassis. For the final robot at the end of the class we 3D printed a stand for it. We were working with really cheap equipment, so the stand cut down the vibration and raised the camera up for a clearer view of the lines.

Prototype 
Final robot 
Final robot, side view
What I learned
This is where I learned how to work with images in code. A frame is really just a grid of numbers, so you can filter it, mask it, and warp it however you want, and I got into the core image processing tools for that: color thresholds, edge detection, and Hough transforms.
A lot of it ended up being linear algebra too. The bird's-eye view is a perspective transform matrix, and finding the lanes came down to fitting lines, solving for where they cross, and approximating where the lane really is from a bunch of noisy segments.
Repositories
Stack
- Python
- OpenCV
- NumPy
- Tkinter
- HTTP requests
Contact
Get in touch.
Want to talk about something I've built, or something you're building? Email's the fastest way to reach me.