/YOLOv4-inference-code-with-masking

Simple inference script for YOLOv4 using opencv.

Primary LanguagePython

Simple Inference Scripts for YOLO with OpenCV (With Mask Output Option)

I forked a YOLOv4 inference script from 'erentknn' for both video and image files, easy to use and not complicated.

The edits in this fork add a 'mask_output' cropping the labels onto a black background.

Example Usage

python yolo_image.py -i street.jpg -o output.jpg -m mask_output.jpg

python yolo_video.py -i video.mp4 -o video_out.avi -m mask_output.avi

Your Code Edits

weights = glob.glob("yolo/*.weights")[0]

labels = glob.glob("yolo/*.txt")[0]

cfg = glob.glob("yolo/*.cfg")[0]

Change these lines in the script to your weights, labels and cfg files.

Normal Output

output

Mask Output

mask

TODO

  • Add custom training script

References

https://github.com/opencv/opencv/blob/master/samples/dnn/object_detection.py https://www.pyimagesearch.com/2020/06/01/opencv-social-distancing-detector/