Skip to content

Instantly share code, notes, and snippets.

@vittorio-nardone
Last active January 17, 2020 09:30
Show Gist options
  • Save vittorio-nardone/72770062a98d59c08200ce5b8e6e546d to your computer and use it in GitHub Desktop.
Save vittorio-nardone/72770062a98d59c08200ce5b8e6e546d to your computer and use it in GitHub Desktop.
Object detection sample in Python
cap = VideoCapture(webcam_url)
model = cv2.dnn.readNetFromTensorflow('models/frozen_inference_graph.pb',
'models/ssd_mobilenet_v2_coco_2018_03_29.pbtxt')
# Get a frame
frame = cap.read()
# Submit it to model
model.setInput(cv2.dnn.blobFromImage(frame, size=(300, 300), swapRB=True))
output = model.forward()
# List detected object
for detection in output[0, 0, :, :]:
confidence = detection[2]
if confidence > .5:
class_id = detection[1]
class_name=id_class_name(class_id,classNames)
print(str(str(class_id) + " " + str(detection[2]) + " " + class_name))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment