This project demonstrates a simple yet powerful application of the YOLOv8 (You Only Look Once) object detection model for identifying various traffic-related objects. The script uses the ultralytics Python library to analyze a given image and detect objects such as cars, buses, motorcycles, traffic lights, and more. It then draws bounding boxes around the detected objects and displays the results. This is a great starting point for anyone interested in real-time object detection for computer vision applications.
To run this project, you need to have Python installed. The core functionality relies on the ultralytics library, which can be easily installed using pip. Install Python: Ensure you have Python 3.8 or a newer version installed on your system. Install Required Libraries: Open your terminal or command prompt and run the following command:
'''pip install ultralytics'''
This command will automatically install all necessary dependencies, including torch and opencv, which are required for the model and image processing.
Save the Script: Save the provided Python code as traffic_detection.py in a directory of your choice. Run from the Command Line: Navigate to the directory where you saved the file and run the script using the Python interpreter. '''python traffic_detection.py'''
The script is configured to use a test image hosted online by default. You can modify the test_image_url variable in the if '''name == "main":''' block to a different URL or a local image path.
After running the script, a new window will pop up displaying the input image with bounding boxes drawn around the detected traffic objects. The objects will be labeled with their class (e.g., Car, Bus) and a confidence score. An example of the output is shown below.
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.