Skip to main content

Overview

Reciclaje AI classifies waste into 5 distinct categories to facilitate proper recycling and waste management. Each class is assigned a unique ID and visual color code for easy identification.
clsName = ['Metal', 'Glass', 'Plastic', 'Carton', 'Medical']

Classification System

The model outputs a class ID (0-4) for each detected object. The mapping is as follows:

Class 0: Metal

Metallic waste materials including cans, foil, and metal containers.

Class 1: Glass

Glass bottles, jars, and other glass containers.

Class 2: Plastic

Plastic bottles, containers, bags, and plastic packaging materials.

Class 3: Carton

Cardboard boxes, paper cartons, and similar paper-based materials.

Class 4: Medical

Medical waste including syringes, masks, and healthcare-related items.

Visual Color Coding

Each class is displayed with a distinctive color for quick visual identification:
1

Metal - Yellow/Cyan

if cls == 0:
    cv2.rectangle(frame_show, (x1, y1), (x2, y2), (255, 255, 0), 2)
    cv2.putText(frame_show, text, (x1, y1 - 5), 
                cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 0), 2)
Color: (255, 255, 0) - Yellow/Cyan in BGR format
2

Glass - White

if cls == 1:
    cv2.rectangle(frame_show, (x1, y1), (x2, y2), (255, 255, 255), 2)
    cv2.putText(frame_show, text, (x1, y1 - 5), 
                cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
Color: (255, 255, 255) - White in BGR format
3

Plastic - Red

if cls == 2:
    cv2.rectangle(frame_show, (x1, y1), (x2, y2), (0, 0, 255), 2)
    cv2.putText(frame_show, text, (x1, y1 - 5), 
                cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
Color: (0, 0, 255) - Red in BGR format
4

Carton - Gray

if cls == 3:
    cv2.rectangle(frame_show, (x1, y1), (x2, y2), (150, 150, 150), 2)
    cv2.putText(frame_show, text, (x1, y1 - 5), 
                cv2.FONT_HERSHEY_SIMPLEX, 1, (150, 150, 150), 2)
Color: (150, 150, 150) - Gray in BGR format
5

Medical - Blue

if cls == 4:
    cv2.rectangle(frame_show, (x1, y1), (x2, y2), (255, 0, 0), 2)
    cv2.putText(frame_show, text, (x1, y1 - 5), 
                cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
Color: (255, 0, 0) - Blue in BGR format
OpenCV uses BGR (Blue-Green-Red) color format instead of the standard RGB format. This is why red is represented as (0, 0, 255) rather than (255, 0, 0).

Class Detection Implementation

Here’s how the system processes class predictions:
# Extract class ID from detection
cls = int(box.cls[0])

# Map to human-readable name
class_name = clsName[cls]

# Display with confidence score
text = f'{class_name} {int(conf) * 100}%'

Label Rendering

Each detection displays a label with the class name and confidence percentage:
# Calculate text size for background rectangle
text = f'{clsName[cls]} {int(conf) * 100}%'
sizetext = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 1, 2)
dim = sizetext[0]
baseline = sizetext[1]

# Draw black background for text readability
cv2.rectangle(frame_show, (x1, y1 - dim[1] - baseline), 
              (x1 + dim[0], y1 + baseline), (0, 0, 0), cv2.FILLED)

# Draw colored text
cv2.putText(frame_show, text, (x1, y1 - 5), 
            cv2.FONT_HERSHEY_SIMPLEX, 1, color, 2)
The black background rectangle ensures text readability regardless of the underlying frame content.

Class-Specific UI Integration

The GUI version (main.py) displays corresponding icons and text labels for each detected class:
# Load class-specific images
img_metal = cv2.imread("setUp/metal.png")
img_glass = cv2.imread("setUp/vidrio.png")
img_plastic = cv2.imread("setUp/plastico.png")
img_carton = cv2.imread("setUp/carton.png")
img_medical = cv2.imread("setUp/medical.png")

# Display appropriate image when class is detected
if cls == 0:
    images(img_metal, img_metaltxt)
elif cls == 1:
    images(img_glass, img_glasstxt)
# ... and so on

Detection Examples

When a metal can is detected:
  • Class ID: 0
  • Label: "Metal 95%" (example confidence)
  • Bounding box color: Yellow/Cyan
  • UI displays metal icon and recycling instructions
When a plastic bottle is detected:
  • Class ID: 2
  • Label: "Plastic 87%" (example confidence)
  • Bounding box color: Red
  • UI displays plastic icon and recycling instructions
When medical waste is detected:
  • Class ID: 4
  • Label: "Medical 92%" (example confidence)
  • Bounding box color: Blue
  • UI displays medical waste warning and disposal instructions

Why These 5 Classes?

Recyclable Materials

Metal, Glass, Plastic, and Carton are the most common recyclable materials in household and industrial waste.

Safety Priority

Medical waste requires special handling and disposal procedures. Early identification prevents contamination and health hazards.

Educational Value

These categories align with standard recycling education curricula, making the system ideal for schools and educational programs.

Practical Implementation

Five classes provide a good balance between specificity and model complexity for real-time detection on standard hardware.

Extending the Classification System

To add more classes, you would need to:
  1. Retrain the YOLOv8 model with additional labeled data
  2. Update the clsName array with new class names
  3. Add color codes and UI elements for new classes
  4. Ensure the model architecture supports the new number of classes

Next Steps

How It Works

Learn about the complete detection pipeline

Model Architecture

Understand the YOLOv8 model behind the classifications

Build docs developers (and LLMs) love