Blogs about Deep Learning, Machine Learning, AI, NLP, Security, Oracle Traffic Director,Oracle iPlanet WebServer

  • January 3, 2019

Object Detection Using OpenCV YOLO

Object Detection Using OpenCV YOLO

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

This blog is also posted in my personal website here.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha