SHARE
TWEET

openvino_fd_myriad.py

Hobe Apr 20th, 2019 117 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2 as cv
  2. # Load the model.
  3. net = cv.dnn.readNet('face-detection-adas-0001.xml',
  4.                      'face-detection-adas-0001.bin')
  5. # Specify target device.
  6. net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)
  7. # Read an image.
  8. frame = cv.imread('/path/to/image')
  9. # Prepare input blob and perform an inference.
  10. blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U)
  11. net.setInput(blob)
  12. out = net.forward()
  13. # Draw detected faces on the frame.
  14. for detection in out.reshape(-1, 7):
  15.     confidence = float(detection[2])
  16.     xmin = int(detection[3] * frame.shape[1])
  17.     ymin = int(detection[4] * frame.shape[0])
  18.     xmax = int(detection[5] * frame.shape[1])
  19.     ymax = int(detection[6] * frame.shape[0])
  20.     if confidence > 0.5:
  21.         cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))
  22. # Save the frame to an image file.
  23. cv.imwrite('out.png', frame)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top