立即学习:https://edu.csdn.net/course/play/28807/427170?utm_source=blogtoedu
人脸检测
程序如下:
练习
1. cd ~/CSDN200/01/exercise-1/
2. source /opt/intel/openvino/bin/setupvars.sh
3. vi face-detection.py
import cv2 as cv
# Load the model
net = cv.dnn.readNet('face-detection-adas-0001.xml', 'face-detection-adas-0001.bin')
# Specify target device (CPU)
net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
# Read an image
frame = cv.imread('faces.jpg')
# Prepare input blob
blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U)
#perform inference (face detection)
net.setInput(blob)
out = net.forward()
# Draw detected faces on the frame
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))
# Save the frame to an image file
cv.imwrite('out.png', frame)
按ESC后输入:q 来退出编辑模式
4. 使用show命令可以显示图片,播放视频:
show faces.jpg
5. 运行人脸检测代码
python3 face-detection.py