Skip to main content

Common Issues and Solutions

This guide covers the most common issues you might encounter when using Reciclaje AI and their solutions.
Most issues can be resolved by ensuring all dependencies are properly installed and the model file is in the correct location.

Camera Issues

Problem: The application fails to access the webcam or shows a black screen.Solutions:
  1. Check camera permissions:
    • On Linux, ensure your user has access to /dev/video0
    • On Windows, check Privacy Settings > Camera
    • On macOS, grant camera permissions in System Preferences
  2. Verify camera index:
    # Try different camera indices
    cap = cv2.VideoCapture(0)  # Default camera
    cap = cv2.VideoCapture(1)  # External camera
    
  3. Test camera with OpenCV:
    import cv2
    cap = cv2.VideoCapture(0)
    if not cap.isOpened():
        print("Cannot open camera")
    
  4. Remove CAP_DSHOW flag (Windows): If you’re not on Windows, remove the cv2.CAP_DSHOW flag from main.py:219:
    cap = cv2.VideoCapture(0)  # Instead of cv2.VideoCapture(0, cv2.CAP_DSHOW)
    
Problem: Video stream is slow or laggy.Solutions:
  1. Reduce resolution:
    cap.set(3, 640)   # Width
    cap.set(4, 480)   # Height
    
  2. Enable GPU acceleration:
    • Install CUDA toolkit if you have an NVIDIA GPU
    • Install PyTorch with CUDA support
  3. Optimize YOLO settings:
    results = model(frame, stream=True, verbose=False, conf=0.5)
    

Model Issues

Problem: Error: FileNotFoundError: [Errno 2] No such file or directory: 'Modelos/best.pt'Solutions:
  1. Download the model:
  2. Create the correct directory structure:
    mkdir -p Modelos
    # Move best.pt to Modelos/
    
  3. Verify file location:
    ls -la Modelos/best.pt
    
The model file should be located in Modelos/best.pt relative to where you run the script.
Problem: The model doesn’t detect objects correctly or has low confidence.Known Limitations:
  • Poor lighting conditions can affect accuracy
  • Image noise or blur reduces detection quality
  • Unusual viewing angles may impact results
  • Rare or unusual waste items not in training data
Solutions:
  1. Improve lighting:
    • Use consistent, bright lighting
    • Avoid shadows and backlighting
  2. Position objects clearly:
    • Place objects within camera frame
    • Avoid overlapping items
    • Use a neutral background
  3. Adjust confidence threshold:
    results = model(frame, stream=True, verbose=False, conf=0.3)
    
  4. Clean camera lens:
    • Ensure webcam is clean and focused

Dependency Issues

Problem: ModuleNotFoundError or ImportError when running the application.Solutions:
  1. Install all required dependencies:
    pip install ultralytics opencv-python pillow imutils numpy
    
  2. Create a virtual environment:
    python -m venv venv
    source venv/bin/activate  # Linux/macOS
    venv\Scripts\activate     # Windows
    pip install -r requirements.txt
    
  3. Check Python version:
    python --version  # Should be Python 3.8+
    
  4. Verify package installation:
    pip list | grep -E "ultralytics|opencv|pillow|imutils"
    
Problem: Cannot install or import ultralytics package.Solutions:
  1. Update pip:
    pip install --upgrade pip
    
  2. Install ultralytics:
    pip install ultralytics
    
  3. Check for conflicts:
    pip check
    
  4. Use specific version:
    pip install ultralytics==8.0.196
    

GUI Issues

Problem: Error: FileNotFoundError for images in setUp/ directory.Solutions:
  1. Verify setUp directory exists:
    ls setUp/
    
  2. Required files in setUp/ directory:
    • Canva.png - Background image
    • metal.png, vidrio.png, plastico.png, carton.png, medical.png
    • metaltxt.png, vidriotxt.png, plasticotxt.png, cartontxt.png, medicaltxt.png
  3. Clone the complete repository:
    git clone https://github.com/AprendeIngenia/reciclaje_ai.git
    
The GUI version (main.py) requires all setup images. Use TrashDetect.py for a simpler version without GUI.
Problem: ImportError: No module named 'tkinter'Solutions:On Ubuntu/Debian:
sudo apt-get install python3-tk
On Fedora:
sudo dnf install python3-tkinter
On macOS:
brew install python-tk
Alternative: Use TrashDetect.py which doesn’t require Tkinter.

Performance Issues

High CPU Usage

  • Reduce video resolution
  • Lower FPS in capture settings
  • Close other applications
  • Use GPU acceleration if available

Memory Leaks

  • Restart the application periodically
  • Check for proper resource cleanup
  • Monitor with htop or Task Manager
  • Update to latest ultralytics version

Getting Help

If you continue to experience issues:

Watch Tutorial

Watch the complete video tutorial for setup and usage

GitHub Issues

Report bugs or request features on GitHub

Community

Join the community and ask questions

Contributing

Help improve the project by contributing

Debugging Tips

Enable verbose mode in YOLO to see detailed inference information:
results = model(frame, stream=True, verbose=True)
  1. Check all file paths:
    import os
    print("Current directory:", os.getcwd())
    print("Model exists:", os.path.exists('Modelos/best.pt'))
    
  2. Test components individually:
    • Test camera capture separately
    • Test YOLO model with a static image
    • Test GUI components independently
  3. Review error messages:
    • Read the full stack trace
    • Note the line number where error occurs
    • Check if file paths are correct
  4. Update dependencies:
    pip install --upgrade ultralytics opencv-python pillow
    

Build docs developers (and LLMs) love