5MODEL_FPATH =
"face-detection-retail-0004.bin"
6ARCH_FPATH =
"face-detection-retail-0004.xml"
10net = cv2.dnn.readNet(ARCH_FPATH, MODEL_FPATH)
13net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
14net.setPreferableTarget(cv2.dnn.DNN_TARGET_MYRIAD)
16vid_cap = cv2.VideoCapture(0)
17if not vid_cap.isOpened():
18 raise IOError(
"Webcam cannot be opened!")
22 ret, frame = vid_cap.read()
25 blob = cv2.dnn.blobFromImage(frame, size=(300, 300), ddepth=cv2.CV_8U)
30 for detect
in out.reshape(-1, 7):
31 conf = float(detect[2])
32 xmin = int(detect[3] * frame.shape[1])
33 ymin = int(detect[4] * frame.shape[0])
34 xmax = int(detect[5] * frame.shape[1])
35 ymax = int(detect[6] * frame.shape[0])
37 if conf > CONF_THRESH:
38 cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0), thickness=2)
40 cv2.imshow(
'Input', frame)
43 if cv2.waitKey(1) == 27:
48cv2.destroyAllWindows()