树莓派+神经计算棒2实时人脸检测
生活随笔
收集整理的這篇文章主要介紹了
树莓派+神经计算棒2实时人脸检测
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
樹莓派配置攝像頭
sudo apt-get install python-opencv sudo apt-get install fswebcam配置攝像頭
sudo nano /etc/modules查看樹莓派CPU型號
cat /proc/cpuinfo
cpu型號為bcm2711
添加
配置展示窗口
實時人臉檢測代碼
#coding=utf-8 #face-detection-camera.py import cv2 as cv import numpy as npprint('開始人臉攝像頭實時監測') print('press "q" to exit ') #載入模型文件和權重文件 net = cv.dnn.readNet('face-detection-adas-0001.xml','face-detection-adas-0001.bin') #specify target device net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)#從攝像頭中讀取圖像幀 cap = cv.VideoCapture(0) while(1):#獲取一幀圖像ret,frame=cap.read()#prepare input blob and perform an inferenceframe = cv.resize(frame,(480,320),interpolation=cv.INTER_CUBIC)blob = cv.dnn.blobFromImage(frame,size=(672,384),ddepth=cv.CV_8U)net.setInput(blob)out=net.forward()#繪制人臉框for detection in out.reshape(-1,7):confidence = float(detection[2])#獲取左上角圖片的坐標xmin=int(detection[3]*frame.shape[1])ymin=int(detection[4]*frame.shape[0])#獲取右下角圖片的坐標xmax=int(detection[5]*frame.shape[1])ymax=int(detection[6]*frame.shape[0])if confidence>0.5:cv.rectangle(frame,(xmin,ymin),(xmax,ymax),color=(0,255,0))#展示圖像cv.imshow("capture",frame)if cv.waitKey(1)&0xFF==ord('q'):#每一毫秒監聽一次鍵盤的動作,按q鍵結束,并保存圖片cv.imwrite('out_cam.png',frame)print("save one image done!")break #關閉攝像頭及顯示窗口 cap.release() cv.destoryAllWindows()總結
以上是生活随笔為你收集整理的树莓派+神经计算棒2实时人脸检测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于华为海思Hi35XX系列开发的思考与
- 下一篇: facenet + Mtcnn 实现人脸