Overview
This guide demonstrates how to use the TrashSystem class to process video streams in real-time for trash classification. The system captures frames from a video source, processes them using the TrashClassificator, and displays the results with visual annotations.Complete TrashSystem Class
The TrashSystem class provides a simple interface for video-based trash classification:video_stream.py
Step-by-Step Implementation
Import Required Libraries
Import OpenCV for video processing and the TrashClassificator for classification:
Make sure OpenCV is installed:
pip install opencv-pythonInitialize Video Capture
Create a VideoCapture object with your video source:Video Source Options:
0- Default webcam1, 2, ...- Additional cameras"path/to/video.mp4"- Video file path"rtsp://camera_url"- Network camera stream
Initialize TrashClassificator
Create an instance of the classification system:The TrashClassificator handles all detection and classification logic internally.
Process Video Frames
Read frames in a loop and process each one:The
frame_processing() method returns:image: Annotated frame with bounding boxes and labelsprocess_log: Dictionary containing detection results and metadata
Display Results and Handle Controls
Show the processed frame and implement keyboard controls:Keyboard Controls:
- Press
qto quit the application
Usage Examples
Expected Output
When running the video stream processing, you’ll see:Console Output
Video Window
The displayed video frame will include:- Bounding boxes around detected trash items
- Class labels (plastic, paper, metal, glass, organic, other)
- Confidence scores for each detection
- Real-time processing with minimal latency
Performance Considerations
Processing Speed: The system processes frames at approximately 20-25 FPS on modern hardware. For real-time applications, ensure your video source matches this frame rate.
Troubleshooting
Camera Not Opening
Low Frame Rate
- Reduce video resolution:
Memory Issues
- Process every Nth frame instead of all frames:
Next Steps
Serial Communication
Learn how to send classification results to external devices
Custom Integration
Integrate the classifier into your own applications