This repo shows how to use YOLO detection with OpenCV, which is hella-simple now you can use the opencv function cv2.dnn.readNetFromDarknet()
The repo is set up good to go except for the YOLO weights. For this code, we're using YOLO v3 so please make sure you download the correct weights from the YOLO page. You should be able to find them on https://pjreddie.com/media/files/yolov3.weights. Once downloaded, you should save the weights in the yolo_cfg
folder.
To label images, please run yolo_image.py
. If you find your images aren't being labelled then you may need to modify both the value for threshold
and min_confidence
- the current defaults for these are 0.3 and 0.5 respectively.
yolo_image.py
will then detect all files in input
with extension 'jpg','jpeg', 'bmp', 'png'
, and save the resulting detections in the output
folder - these will be saved as PNG
.
To label a video, please run yolo_video.py
. As with the above, you may need to change the threshold and condifence levels to suit your needs.
yolo_video.py
will detect all files in input
with extension 'mp4'
and save the resulting video to the output
folder with extension 'mp4'
.
Note that the code will only run detections on the first video file found (as otherwise it could run for a very long time).
If you are after something speedy then this is not for you - please consider the excellent keras-yolo3 from Experiencor and consider running on a GPU rather than CPU.
This repo is based on the tutorial from Adrian Rosebrock on PyImageSearch. There are loads of really good tutorials on that site so I heavily suggest that you try them out.