https://github.com/freya135/smart-traffic-system
A Python-based system leveraging a Raspberry Pi to capture and process traffic images, dynamically control traffic lights and servo motors based on real-time vehicle detection using edge detection, and optimize traffic flow intelligently.
https://github.com/freya135/smart-traffic-system
canny-edge-detection gpiozero image-processing numpy open-cv python raspberry-pi-5 real-time-processing servo-motor signal-duration smart-traffic-light
Last synced: about 1 month ago
JSON representation
A Python-based system leveraging a Raspberry Pi to capture and process traffic images, dynamically control traffic lights and servo motors based on real-time vehicle detection using edge detection, and optimize traffic flow intelligently.
- Host: GitHub
- URL: https://github.com/freya135/smart-traffic-system
- Owner: Freya135
- Created: 2025-05-06T14:21:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-08T16:33:20.000Z (about 1 year ago)
- Last Synced: 2025-06-15T10:42:57.269Z (12 months ago)
- Topics: canny-edge-detection, gpiozero, image-processing, numpy, open-cv, python, raspberry-pi-5, real-time-processing, servo-motor, signal-duration, smart-traffic-light
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Smart Traffic Signal Controller using Raspberry Pi
This project is designed to automate traffic signal timing based on live image processing. It utilizes a Raspberry Pi, Pi Camera 2, and GPIO components to dynamically adjust the green light duration according to traffic conditions.
## 🛠️ Project Structure
| File | Description |
|------|-------------|
| `camera_capture.py` | Captures an image using the Pi Camera 2. |
| `image_processing.py` | Processes the captured image using Canny Edge Detection to assess traffic density. |
| `lights.py` | Sets the duration of the green signal based on processed image data. |
| `lightspigpio.py` | Interfaces with GPIO pins using the `gpiozero` library to control the signal lights. |
| `main.py` | Main script that orchestrates the full process from image capture to signal control. |
| `references.py` | Captures and stores a reference image for background subtraction or comparison. |
| `servomotor.py` | Controls a servo motor to rotate or move at specific time intervals. |
| `__pycache__/` | Contains Python bytecode files (auto-generated). |
## ⚙️ How It Works
1. **Image Capture**: `camera_capture.py` triggers the Pi Camera to capture a real-time image of the traffic lane.
2. **Image Analysis**: `image_processing.py` applies Canny Edge Detection to identify vehicles and estimate traffic density.
3. **Signal Timing**: Based on the density, `lights.py` adjusts the green light duration dynamically.
4. **Signal Control**: `lightspigpio.py` handles GPIO interactions to turn the traffic lights on or off.
5. **Reference Image**: `references.py` allows capturing a reference image to help in differential analysis.
6. **Servo Control**: `servomotor.py` manages timed servo operations (e.g., gate opening/closing).
## 📦 Requirements
- Raspberry Pi 5 (or any model with GPIO support)
- Pi Camera 2
- Traffic Light Modules
- Servo Motor
- Python 3.x
- Libraries:
- `gpiozero`
- `opencv-python`
- `numpy`
Install Python dependencies:
```bash
pip install gpiozero opencv-python numpy
```
## 🚀 Getting Started
1. Connect your Pi Camera and traffic signal LEDs to GPIO pins.
2. Run the main script:
```bash
python main.py
```
3. The system will:
- Capture an image.
- Analyze traffic density.
- Adjust green signal timing.
- Rotate servo motor (if applicable).
## 🧠 Future Improvements
- Integrate with cloud for data logging.
- Add GUI to visualize traffic and timings.
- Expand to multi-lane or multi-signal support.
## ⚠️ Disclaimer
Ensure safe practices when working with electronics and live environments. Use dummy loads during development.
---