Object Detection Yolo
π Overview
Use YOLO (You Only Look Once) to recognise object classes and positions in real time; OpenCV's tutorial uses YOLOv3, which detects the 80 common COCO classes (person, car, cat, phone, and so on).
YOLO is famous for producing all detection boxes from a single forward pass, balancing real-time speed against accuracy - a classic hands-on project in object detection.
π§° What you need
- Computer + camera (or image/video files)
- Python 3.7+ environment
- pip install: opencv-python, numpy
- YOLOv3 weights + config file + coco.names class file
π§ Step by step
Download the model files
Get yolov3.weights (about 236MB), yolov3.cfg, and coco.names
The lighter yolov3-tiny is also an option if you need speed
Load the network and classes
Load the cfg and weights with readNetFromDarknet
Read in the list of 80 class names
Blob the input
Convert the image to a blob with the right scaling and input size
Remember that YOLO inputs are normalised to 0-1
Forward pass
Iterate the network output layers to get the detections
Each detection has a centre coordinate, width/height, confidence, and class probabilities
Filter and NMS
Filter out low-confidence detections with a threshold
Remove duplicate boxes with NMSBoxes
Draw the results
Draw the class name, confidence, and box on the original frame
Different classes can use different colours
π‘ Tips
- Inferring every frame of a video is slow, so skip frames (detect every 2-3 frames) to speed it up
- yolov3-tiny is fast but misses small objects more often - choose according to your scene
- Lowering the confidence threshold (0.3, say) surfaces more objects, along with more false positives