A real-time Vision-Based Object Tracking System built using Raspberry Pi, OpenCV, Pi Camera, HC-SR04 Ultrasonic Sensor, and PID Control. The system detects and tracks a target object while maintaining a safe following distance autonomously.
This project combines computer vision, distance sensing, and motion control to create an autonomous tracking robot capable of:
- Detecting target objects using camera vision
- Tracking object movement in real-time
- Maintaining safe distance automatically
- Controlling motor speed using PID
- Stopping safely when the object is lost
✅ Real-time object detection and tracking
✅ HSV-based color segmentation
✅ Distance measurement using HC-SR04
✅ PID-based motor control
✅ Differential drive movement
✅ Moving average filtering for stable readings
✅ Automatic stop when target is lost
| Component | Description |
|---|---|
| Raspberry Pi 4B | Main processing unit |
| Pi Camera Module | Image capture |
| HC-SR04 Ultrasonic Sensor | Distance measurement |
| L298N Motor Driver | Motor control |
| DC Motors | Robot movement |
| Battery Pack | Power supply |
- Python
- OpenCV
- Raspberry Pi GPIO
- NumPy
- PID Control Algorithm
- HSV Color Detection
Start
↓
Capture Camera Frame
↓
Convert Image → HSV
↓
Apply Yellow Mask
↓
Detect Object Contours
↓
Calculate Object Position
↓
Measure Distance (Ultrasonic)
↓
Apply Moving Average Filter
↓
PID Control
↓
Motor Adjustment
↓
Robot Movement
The system uses:
- Capture frame from Pi Camera
- Convert image from RGB → HSV
- Apply yellow color threshold
- Perform erosion and dilation
- Detect contours
- Extract centroid position
- Calculate tracking error
- Control robot direction
Distance is measured using HC-SR04 ultrasonic sensor.
Features:
- Safe following distance: 30 cm
- Moving average filter window: 5 samples
- Noise reduction
- Stable tracking performance
- Move forward
- Adjust direction
- Maintain distance
- Stop motors
- Wait for object reappearance
- Reduce speed
- Stop if required
Vision-Based-Object-Tracking-System/
│── Codes/
│ ├── Color_detect_HSV.py -- Used to read the HSV values for the required color (Yellow is our case).
│ ├── HSV.py -- Read the HSV values and print them.
│ └── Tracker.py -- Main code file
│
│── images/
│── README.md- Maintained 30 cm safe distance
- Real-time object detection
- Smooth tracking using PID
- Full horizontal tracking capability
- Stable distance filtering
- Multi-object tracking
- YOLOv8 integration
- Obstacle avoidance
- ROS2 integration
- Cloud telemetry dashboard
- Battery optimization
Components connected:
Raspberry Pi 4B
↓
Pi Camera Module
↓
HC-SR04 Sensor
↓
L298N Motor Driver
↓
Differential Drive Robot
D Mabu Jaheer Abbas
Narra Raghuvender
This project is developed for educational and research purposes.
MIT License