Last active
January 17, 2020 09:30
-
-
Save vittorio-nardone/72770062a98d59c08200ce5b8e6e546d to your computer and use it in GitHub Desktop.
Object detection sample in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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