Overview
The main.py GUI application provides an intuitive, full-featured interface for waste detection and classification. It includes real-time video feed, visual classification feedback, and color-coded detection boxes.The GUI requires the setUp folder with background images and classification icons, plus the trained model at
Modelos/best.pt.Launching the GUI
Run the GUI Application
Execute main.py:The GUI window will open with title “RECICLAJE INTELIGENTE” (Intelligent Recycling).
GUI Layout
The application window is 1280x720 pixels with three main areas:Layout Regions
Video Feed
Position: Center-left (320, 180)Size: 640px width (auto-scaled)Shows live camera feed with bounding boxes
Detection Image
Position: Left panel (75, 260)Displays icon of detected waste type
Classification Text
Position: Right panel (995, 310)Shows classification label image
Detection Features
Color-Coded Classifications
Each waste type has a unique color for easy identification:- Metal
- Glass
- Plastic
- Carton
- Medical
Color: Yellow (RGB: 255, 255, 0)Class ID: 0Displays metal.png and metaltxt.png when metal is detected.
main.py:82-95
Smart Label Rendering
The GUI uses intelligent text rendering with background boxes:main.py:87-92
Core Functions
Scanning Function
The heart of the GUI is theScanning() function that runs continuously:
main.py:38-176
- Runs every 10 milliseconds (
lblVideo.after(10, Scanning)) - Clears classification images when no objects detected
- Handles color space conversion (BGR to RGB)
- Resizes video to 640px width for display
Image Display Function
Handles classification image updates:main.py:15-35
Clean Label Function
Clears classification images when no detection occurs:main.py:10-13
Application Initialization
Theventana_principal() function sets up the entire application:
main.py:182-225
The GUI uses
cv2.CAP_DSHOW on Windows for DirectShow support. On Linux/Mac, this flag is ignored automatically.Required Assets
The GUI requires these image files in thesetUp/ directory:
Background
- Canva.png: Main application background (1280x720)
Classification Icons
Waste Type Icons
- metal.png
- vidrio.png (glass)
- plastico.png
- carton.png
- medical.png
Text Label Icons
- metaltxt.png
- vidriotxt.png
- plasticotxt.png
- cartontxt.png
- medicaltxt.png
Performance Considerations
Frame Rate Optimization
The GUI updates every 10ms, targeting ~100 FPS update rate:main.py:176
Video Resizing
Video is resized to 640px width for efficient display:main.py:167
Troubleshooting
Missing setUp folder error
Missing setUp folder error
If you get file not found errors:
- Create the setUp directory in your source folder
- Add all required background and icon images
- Ensure image filenames match exactly (case-sensitive)
GUI window not responding
GUI window not responding
If the GUI freezes:
- Check camera connection
- Verify model file exists at Modelos/best.pt
- Ensure no other application is using the camera
- Try reducing detection frequency by increasing the delay in line 176
Classification images not showing
Classification images not showing
Verify:
- All image files exist in setUp/ directory
- Images are readable (not corrupted)
- File permissions allow reading
Camera initialization fails on Windows
Camera initialization fails on Windows
If
cv2.CAP_DSHOW causes issues:main.py:219
Color display issues
Color display issues
The GUI performs color space conversions between BGR and RGB:
- Camera input: BGR (OpenCV default)
- Display output: RGB (Tkinter/PIL requirement)
Closing the Application
To exit the GUI:- Click the window close button (X)
- Camera will be released automatically
- All resources cleaned up via
cap.release()
Next Steps
Camera Configuration
Learn how to optimize camera settings for better detection
CLI Detection
Use the lightweight command-line interface