Overview
Proper camera configuration is crucial for accurate waste detection. Both TrashDetect.py and main.py use identical camera settings optimized for the YOLOv8 model.Default Camera Settings
Both applications use these standard settings:Resolution is set to 1280x720 (720p HD) for optimal balance between detection accuracy and processing speed.
OpenCV Camera Properties
Understanding cap.set() Parameters
OpenCV uses numeric property IDs for camera configuration:| Property ID | Name | Default Value | Description |
|---|---|---|---|
| 3 | cv2.CAP_PROP_FRAME_WIDTH | 1280 | Frame width in pixels |
| 4 | cv2.CAP_PROP_FRAME_HEIGHT | 720 | Frame height in pixels |
| 5 | cv2.CAP_PROP_FPS | (auto) | Frames per second |
| 10 | cv2.CAP_PROP_BRIGHTNESS | (auto) | Camera brightness |
| 11 | cv2.CAP_PROP_CONTRAST | (auto) | Camera contrast |
| 12 | cv2.CAP_PROP_SATURATION | (auto) | Color saturation |
Code Implementation
Selecting Camera Device
Camera Index
The camera index specifies which camera to use:- 0: Built-in webcam or first USB camera
- 1: Second USB camera
- 2: Third USB camera
- And so on…
Finding Available Cameras
Use this script to detect all available cameras:find_cameras.py
Resolution Settings
Why 1280x720?
The default resolution balances several factors:Detection Accuracy
Higher resolution provides:
- More pixel data for YOLO
- Better small object detection
- Improved edge definition
Processing Speed
720p offers:
- Real-time performance on most hardware
- Efficient memory usage
- Smooth frame rates
Alternative Resolutions
Adjust based on your hardware and requirements:- High Performance (Lower Resolution)
- Standard (Default)
- High Accuracy (Higher Resolution)
For faster processing on limited hardware:Pros:
- Faster processing
- Lower CPU/GPU usage
- Higher frame rates
- Reduced detection accuracy for small objects
- Less detail in video feed
Platform-Specific Configuration
Windows
Use DirectShow backend for better camera support:Linux
Use default V4L2 backend:macOS
Use AVFoundation backend:Advanced Camera Settings
Adjusting Brightness and Contrast
For low-light or high-glare environments:Setting Frame Rate
Control capture frame rate:Not all cameras support manual FPS control. The camera will use its default rate if the setting is not supported.
Auto-Focus and Exposure
Verification Script
Test and verify your camera configuration:test_camera.py
Optimal Detection Conditions
Lighting
Good Lighting
- Natural daylight or bright indoor lighting
- Even illumination without harsh shadows
- No direct glare on camera lens
- Consistent light levels
Poor Lighting
- Very dim or dark environments
- Harsh backlighting (object in shadow)
- Flickering lights (fluorescent)
- Direct sunlight causing lens flare
Camera Positioning
Recommended setup:- Distance: 30-100 cm from objects
- Angle: Slightly above, looking down at ~30-45°
- Stability: Mount camera or use stable surface
- Field of view: Ensure entire object visible in frame
Environment
Troubleshooting Camera Issues
Resolution not applied
Resolution not applied
If camera doesn’t use requested resolution:
- Check camera capabilities:
- Try supported resolutions: 640x480, 800x600, 1280x720, 1920x1080
- Update camera drivers
Camera not detected
Camera not detected
Linux: Check permissionsWindows: Install camera drivers from manufacturermacOS: Grant camera permissions in System Preferences > Security & Privacy
Low frame rate / Lag
Low frame rate / Lag
To improve performance:
- Reduce resolution:
- Close other applications using camera
- Ensure GPU acceleration enabled for YOLOv8:
- Use lower quality USB cameras (less compression overhead)
Camera feed appears distorted
Camera feed appears distorted
Color space or aspect ratio issues:
- Verify color conversion:
- Maintain aspect ratio when resizing:
Multiple cameras cause conflicts
Multiple cameras cause conflicts
If multiple applications access the same camera:
- Explicitly release camera:
- Use different camera indices for different applications
- Check running processes:
Performance Benchmarking
Measure your camera and detection performance:benchmark.py
Next Steps
CLI Detection
Start using the command-line detection tool
GUI Application
Explore the full-featured graphical interface