A real-time trash detection system that classifies different types of waste materials using YOLO object detection.
This project implements a trash detection system capable of identifying and classifying various types of waste materials in real-time. The system can process both video files and live webcam feeds to detect items like metal, plastic pouches, foil pouches, and other plastic materials.
- Real-time Detection: Process video streams and webcam feeds in real-time
- Multiple Material Detection: Identify various waste categories including:
- Metal
- Plastic pouches
- Foil pouches
- General plastic items
- Flexible Input Sources: Support for both video files and live webcam
- Fast Inference: Optimized performance with YOLO model
- Visual Feedback: Real-time bounding boxes and confidence scores
- Python 3.7+
- OpenCV
- Ultralytics YOLO
pip install ultralytics opencv-pythonSpace_Object-Detection/
├── detect_best.pt # Trained YOLO model weights
├── test.py # Main detection script
├── Screenshot_2025-10-30_183112.png # Example detection output
├── requirements.txt # Python dependencies
└── README.md # Project documentation
- Run the detection script:
python test.py-
Choose input mode:
- Enter
vfor video file detection - Enter
wfor webcam detection
- Enter
-
For video mode: Place your video file (
Video2.mp4) in the project directory -
Controls:
- Press
qto quit the application
- Press
detect_from_video(video_path): Processes video files for trash detectiondetect_from_webcam(): Uses webcam for real-time detection
# Load trained model
model = YOLO("detect_best.pt")
# Run inference
results = model(frame)
# Visualize results
annotated_frame = results[0].plot()- Ensure your trained model weights (
detect_best.pt) are in the project directory - Run the script and select your preferred input method
- The system will display real-time detection with bounding boxes and labels (as shown in the screenshot above)
- Press 'q' to exit the application
- The model is trained to detect specific trash categories with high accuracy
- Performance may vary based on hardware capabilities
- For best results, ensure good lighting conditions when using webcam
- The screenshot demonstrates successful detection of multiple waste items with confidence scores
Feel free to fork this project and submit pull requests for any improvements.
This project is open source and available under the MIT License.