Skip to content

marriapavl/detect_traffic_lights

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

GTA Traffic Light Detector

A real-time traffic light detection script for screen capture

This Python script performs real-time traffic light detection from a specified region of your screen. It uses a YOLO model for object detection and OpenCV for color analysis to identify if a traffic light is red or green, displaying "STOP" or "GO" messages accordingly.

Features

  • Real-time Screen Capture: Efficiently captures a monitor region for live analysis using the mss library.
  • YOLO-based Object Detection: Uses a pre-trained YOLO model (yolo11m.pt) to accurately locate traffic lights.
  • Color Classification: Analyzes the pixels within detected bounding boxes to determine if the light is red or green.
  • Dynamic Overlay: Displays "STOP" or "GO" text in the middle of the screen based on the detected light color.
  • Automatic Monitor Detection: Automatically detects the primary monitor's dimensions, but can be configured for multi-monitor or specific window capture

Installation

  1. Clone the repository or download the script files:
sh
git clone https://github.com/marriapavl/detect_traffic_lights.git
cd detect_traffic_lights
  1. Install dependencies: The script relies on several Python libraries. Use the provided requirements.txt file to install them.
sh
pip install -r requirements.txt
  1. Download the YOLO model: This script is configured to use a YOLOv11m model. You must download the yolo11m.pt file and place it in a models directory in the same location as your script. The model file can be found on the Ultralytics GitHub repository or their official website. https://github.com/ultralytics/assets/releases/
.
├── models/
│   └── yolo11m.pt
├── requirements.txt
└── main.py

Usage

Run the script play the video on the screen:

sh python3 main.py

Exit the script: Press the 'q' key on your keyboard to stop the screen capture and exit the application.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages