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.
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). |
- Image Capture:
camera_capture.py
triggers the Pi Camera to capture a real-time image of the traffic lane. - Image Analysis:
image_processing.py
applies Canny Edge Detection to identify vehicles and estimate traffic density. - Signal Timing: Based on the density,
lights.py
adjusts the green light duration dynamically. - Signal Control:
lightspigpio.py
handles GPIO interactions to turn the traffic lights on or off. - Reference Image:
references.py
allows capturing a reference image to help in differential analysis. - Servo Control:
servomotor.py
manages timed servo operations (e.g., gate opening/closing).
- 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:
pip install gpiozero opencv-python numpy
- Connect your Pi Camera and traffic signal LEDs to GPIO pins.
- Run the main script:
python main.py
- The system will:
- Capture an image.
- Analyze traffic density.
- Adjust green signal timing.
- Rotate servo motor (if applicable).
- Integrate with cloud for data logging.
- Add GUI to visualize traffic and timings.
- Expand to multi-lane or multi-signal support.
Ensure safe practices when working with electronics and live environments. Use dummy loads during development.