Object Detection Using OpenCV YOLO

Meena Vyas
3 min readDec 4, 2018

You only look once (YOLO) is a state-of-the-art, real-time object detection system.

It applies a single neural network to the full image. This network divides the image into regions and predicts bounding boxes and probabilities for each region. These bounding boxes are weighted by the predicted probabilities. It looks at the whole image at test time so its predictions are informed by global context in the image. It is extremely fast, more than 1000x faster than R-CNN and 100x faster than Fast R-CNN.

Non-Maxima Suppression : During prediction time you may have lot’s of box predictions around a single object the non maxima supression algorithm will filter out those boxes that overlap between each other and also some threshold.

I tried object detection on this video.

Download the following files :

  • yolov3.cfg
  • yolov3.weight which contains pre-trained weights using wget command as shown below
wget https://pjreddie.com/media/files/yolov3.weights
  • yolov3.txt which contains all the class names this library can detect.

Import relevant packages. Add random color to each class which will be used to draw rectangles.

For each image, call processImage function which does the following

  • Takes image frame as input
  • read pre-trained model,
  • Gather predictions
  • If confidence is less than 0.5 ignore the detection
  • Apply non-max suppression
  • Draw boundary boxes
  • Save the output images with boundary boxes

Now we try to observe a few of these output images

Due to non maxima suppression sometimes if the two cars are in the same area, one gets undetected at times.

Refer my ipython notebook https://github.com/meenavyas/Misc/blob/master/ObjectDetectionUsingYolo/ObjectDetectionUsingYolo.ipynb for full source code.

References and thanks to

Originally published at meenavyas.wordpress.com on December 4, 2018.

--

--