- PyCharm: Download here
- Python: Download here
- Note: This project uses Python 3.12.0, but later versions should work as well.
- Check your Python version:
python --version
-
Create a New Project in PyCharm
- Open PyCharm and select "New Project".
- Choose a location and ensure the correct Python interpreter is selected.
-
Install Required Libraries
- Open the terminal and run:
pip install cvzone pip install opencv-python pip install numpy
- Or install directly within PyCharm:
- Open the terminal and run:
import cvzone
import cv2
img = cv2.imread('path_to_image.jpg')
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('Gray Image', imgGray)
cv2.waitKey(0)
from ultralytics import YOLO
model = YOLO("../Yolo-Weights/yolov8n.pt") # Nano
model = YOLO("../Yolo-Weights/yolov8s.pt") # Small
- YOLO detects objects such as:
- "person", "bicycle", "car", "motorbike", ..., "teddy bear", "hair drier", "toothbrush"
- To detect more objects, YOLO needs additional training with custom datasets.
- Find datasets:
from cvzone.SerialModule import SerialObject
# Uses "pySerial" Package - check serialModule.py (External Libraries -> site-packages -> cvzone)
# Sends Arduino a true/false state. If a face is detected, the light should turn on.
if bboxs:
arduino.sendData([1])
else:
arduino.sendData([0])
- Bounding boxes (bboxs) confirm object presence.
- Ensure the camera is turned off when running the program.
- Fine-Tuning with Transfer Learning: View on Kaggle
- Automatic Dataset Labeling:
from ultralytics import YOLO
import cv2
import cvzone
import math
import time
cap = cv2.VideoCapture(0) # Webcam
cap.set(3, 1280)
cap.set(4, 720)
model = YOLO("../Yolo-Weights/yolov8n.pt")
classNames = ["person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck", "boat", "traffic light", ...]
prev_frame_time = 0
new_frame_time = 0
while True:
new_frame_time = time.time()
success, img = cap.read()
results = model(img, stream=True)
for r in results:
boxes = r.boxes
for box in boxes:
x1, y1, x2, y2 = map(int, box.xyxy[0])
w, h = x2 - x1, y2 - y1
cvzone.cornerRect(img, (x1, y1, w, h))
conf = math.ceil((box.conf[0] * 100)) / 100
cls = int(box.cls[0])
cvzone.putTextRect(img, f'{classNames[cls]} {conf}', (max(0, x1), max(35, y1)), scale=1, thickness=1)
fps = 1 / (new_frame_time - prev_frame_time)
prev_frame_time = new_frame_time
print(fps)
cv2.imshow("Image", img)
cv2.waitKey(1)
- Kaggle: Garbage Classification Transfer Learning
- Kaggle: Garbage Classification ResNet
- Deep Waste App
- Deep Waste REST API
- Keras Applications
- YOLOv8 Trash Dataset