ROS + OpenCV Lane Detection
Real-time lane detection from a USB camera stream with PID-ready steering signal generation — Teknofest Robotaksi prototype.
- Category
- Computer Vision / Autonomous Driving
- Context
- Real-time prototype for Teknofest Robotaksi
- Input
- USB camera or ROS camera driver
- Output
- Lane masking & steering angle (PID-ready)
- Platform
- ROS (Ubuntu), OpenCV
- Tech stack
- ROS, OpenCV, Python, C++, Canny, Hough, PID
- Links
- GitHub repository
Algorithm pipeline
The system targets real-time performance with a classic OpenCV-based lane detection approach:
- ROI (Region of Interest): Masking the road’s region of interest (lower triangle/polygon).
- Preprocessing: Grayscale, Gaussian blur, dynamic thresholding.
- Edge extraction (Canny): Extracting candidate line edges.
- HoughLinesP: Finding right/left lane candidates as line segments.
- Symmetry & merging: Filtering the lines and merging by slope/continuity.
- Heading angle estimation: Computing deviation relative to the lane centre and generating
steering_angle. - Optional corrections: Temporal-window smoothing, jitter reduction.
Example ROS topics
/camera/image_raw— Input image/lane/overlay— Detected lane overlay (optional)/lane/steering_angle— Steering angle (float)/lane/pid— PID control input (optional)
Example parameters
| Parameter | Description | Example |
|---|---|---|
canny_low |
Lower edge threshold | 50 |
canny_high |
Upper edge threshold | 150 |
hough_threshold |
Hough vote threshold | 30 |
minLineLength |
Minimum line length | 25 |
maxLineGap |
Line merging gap | 20 |
roi_vertices |
Region-of-interest polygon | lower triangle |
smoothing_window |
Angle smoothing window | 5 |
Topic names, node names and parameter files are defined within the repository; the values here are a general template.
Setup & running (example)
# ROS & dependencies (example: Noetic / Ubuntu 20.04)
sudo apt update
sudo apt install ros-noetic-desktop-full python3-opencv
# Workspace and repository
mkdir -p ~/catkin_ws/src && cd ~/catkin_ws/src
git clone https://github.com/mr-ozdemir/Lane-detection-with-Opencv-in-Ros.git
cd .. && catkin_make && source devel/setup.bash
# Camera driver and lane detection
roslaunch usb_cam usb_cam-test.launch
roslaunch lane_detection lane_detection.launch
Commands may vary depending on the repository structure; adapt them to the README/launch files in the repository.
Notes & potential improvements
- The ROI and edge/line thresholds should be tuned to the field for different lighting/surface conditions.
- FPS/latency targets depend on resolution and hardware; more stable real-time performance is achieved at 640×480.
- The classic method could be combined with segmentation-based approaches (e.g., U-Net, ENet) in a hybrid scheme.
- A ROS2 port and hardware acceleration (GPU/OpenCL) can be planned.