Course Notes: Object detection (OpenCV/Python)


Object Detection OpenCV Python | Easy and Fast (2020)

Github – none, ObjectDetector-OpenCV

Related videos


Course Notes

Required files

Required files (from OpenCV documentation, but where exactly is anyone’s guess):

  • coco.names
  • ssd_inception_v2_coco_2017_11_17.pbtxt – out of date
  • ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt
  • frozen_inference_graph.pb

Using the files from these two links (frozen_inference_graph.pb (29.2 MB) and ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt) gave an error:

<class 'cv2.dnn_DetectionModel'> returned a result with an error set

In retrospect, the ssd file is probably ok, as it is the same as I subsequently used from ObjectDetector-OpenCV, so the frozen_inference_graph.pb (29.2 MB) is probably at fault, or doesn’t match the ssd file.

Using the files from ObjectDetector-OpenCV, the project worked as expected.


mobilenet -> accuracy vs speed, lightweight, use with RPi

The list of objects in coco.names starts at 1, but the list starts at 0 so we need to -1

We have three sets of info lists, but we don’t want three for loops so we use a zip

yolo requires a GPU

To get the  newly created project to appear in the interpreter dialog (New Projects Settings…>Preferences), you need to select an old projects window [and then click back].

Lena/person recognition complete.

Time: 20:05 – Adding camera

When using waitKey:

  • if using while True:, then use keyWait(1)
  • if not using while True:, then use keyWait(0)


I had real trouble with this project:

  • net.setInputSize(320, 320) it wants only one argument
  • this was possibly due to mismatching pb and pbtext files. Once I downloaded a matching set, then two arguments were required, as expected.
  • if lena.jpg is specified, and the file is actually a PNG, i.e. lena.png then you get an error:
error: (-215:Assertion failed) !ssize.empty() in function 'resize'

Once the matching PB and PBTXT pair and correct image were supplied, it worked..!

The camera feed didn’t detect any objects though.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s