标签:图片 asp cti std simple imwrite man das port
1 import cv2 as cv 2 import sys 3 import logging as log 4 5 # openvino_fd_myriad.py 6 filename =‘./‘ 7 8 log.basicConfig(format="[ %(levelname)s ] %(message)s", level=log.INFO, stream=sys.stdout) 9 10 if len(sys.argv) > 1 : 11 filename = filename + sys.argv[1] 12 else: 13 filename = filename + ‘Girls.jpg‘ 14 15 log.info("Image is " + filename) 16 # Load the model. 17 net = cv.dnn.readNet(‘face-detection-adas-0001.xml‘,‘face-detection-adas-0001.bin‘) 18 19 # Specify target device. 20 21 net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD) 22 23 log.info("Inference model is face-detection-adas-0001") 24 # Read an image. 25 frame = cv.imread(filename) 26 27 if frame is None: 28 raise Exception(‘Image not found!‘) 29 30 log.info("Perform an inference " + filename) 31 # Prepare input blob and perform an inference. 32 blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U) 33 net.setInput(blob) 34 out = net.forward() 35 36 i = 0 37 # Draw detected faces on the frame. 38 for detection in out.reshape(-1, 7): 39 confidence = float(detection[2]) 40 xmin = int(detection[3] * frame.shape[1]) 41 ymin = int(detection[4] * frame.shape[0]) 42 xmax = int(detection[5] * frame.shape[1]) 43 ymax = int(detection[6] * frame.shape[0]) 44 if confidence > 0.5: 45 cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0), thickness=1) 46 cv.rectangle(frame, (xmin-1, ymin-1),(xmin+70, ymin-10), color=(0, 255, 0), thickness= -1) 47 i = i + 1 48 cv.putText(frame, ‘Human : ‘ + str(i) + ‘ ‘ + str(confidence) , (xmin, ymin -2), cv.FONT_HERSHEY_SIMPLEX, 0.3, (0,0,0), thickness=1) 49 50 # Save the frame to an image file. 51 cv.imwrite(filename + ‘_out.png‘, frame) 52 log.info("Save the frame to an image file as png : " + filename)
RaspBerry Pi4 with OpenVion and Movidius
标签:图片 asp cti std simple imwrite man das port
原文地址:https://www.cnblogs.com/cloudrivers/p/11566934.html