import cv2
modelFile = "./model/res10_300x300_ssd_iter_140000_fp16.caffemodel"
configFile = "./model/deploy.prototxt"
faceDetect = cv2.dnn_DetectionModel(modelFile, configFile)
if __name__ == "__main__":
cap = cv2.VideoCapture(1)
cap.set(3, 1920) # width
cap.set(4, 1080) # height
while True:
hasFrame, frame = cap.read()
detections = faceDetect.detect(frame)
try:
x, y, width, height = detections[2][0][0:4]
cv2.rectangle(frame, (x, y), (x+width, y+height), (0, 0, 255), 2)
except:
pass
cv2.imshow('detect', frame)
k = cv2.waitKey(1)
if k == 27:
cv2.destroyAllWindows()
break
Python 实现OpenCV DNN人脸检测
最新推荐文章于 2021-10-04 00:34:01 发布