You need to complete these steps:
- Import the modules:
import cv2import numpy as np
- Import the Caffe model:
model = cv2.dnn.readNetFromCaffe('../data/MobileNetSSD_deploy.prototxt', '../data/MobileNetSSD_deploy.caffemodel')
- Set a confidence threshold and specify the classes supported by the model:
CONF_THR = 0.3LABELS = {1: 'aeroplane', 2: 'bicycle', 3: 'bird', 4: 'boat', 5: 'bottle', 6: 'bus', 7: 'car', 8: 'cat', 9: 'chair', 10: 'cow', 11: 'diningtable', 12: 'dog', 13: 'horse', 14: 'motorbike', 15: 'person', 16: 'pottedplant', 17: 'sheep', 18: 'sofa', 19: 'train', 20: 'tvmonitor'}
- Open the video with road traffic:
video = cv2.VideoCapture('../data/traffic.mp4')while True: ret, frame = video.read() if not ret: break ...