zoukankan      html  css  js  c++  java
  • 树莓派和计算棒实现图形识别 RaspBerry Pi4 with OpenVino and Movidius

     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)
  • 相关阅读:
    Ryzom简易汉化教程
    在Windows上编译运行Ryzom客户端
    在Windows(x86)上编译、配置并运行Ryzom Core(服务器/客户端)
    引擎设计与商业模式
    总结了一下新手学习Windows 8 Metro App 开发的捷径
    开始研究Ryzom Core!
    和Ryzom相关的项目简介
    关于Ryzom游戏开发的路线图
    根据 yyyymmdd格式日期取得当前日期所在周的开始和结束日期
    asp数组中REDIM的用法(动态数组)
  • 原文地址:https://www.cnblogs.com/cloudrivers/p/11566934.html
Copyright © 2011-2022 走看看