采用face_recognition进行人脸识别时,解决摄像头太远人脸太小导致无法检测的问题

经测试发现,把图像resise放大后再进行人脸识别,可以识别出非常小的人脸区域
以上相片站在10米开外,分辨率300万的笔记本电脑上都可以识别
不过处理速度非常的慢,很卡,不知道换1080TI或者以上显卡能否提高效率

本来离摄像头不到1米的距离就无法识别的,现在距离10米左右,人脸小的自己站的地方都看不清的情况下,仍然可以识别。
ret, frame = video_capture.read()

Resize frame of video to 1/4 size for faster face recognition processing
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

small_frame = frame
Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
rgb_small_frame = small_frame[:, :, ::-1]
上面的0.25就是为了快速处理而缩小了1/4的图像大小,效率是提高了,但人脸面积太小就无法识别了。
然后我把它改成放大或者不变就可以识别小面积的脸型了,但如果是在视频中提取,效率就会很低。
small_frame = cv2.resize(frame, (0, 0), fx=2, fy=2)
另外,还要还原比例:# Scale back up face locations since the frame we detected in was scaled to 1/4 size
top = top/2
right = right/2
bottom = bottom/2
left = left/2
还原后类型变成了float型,如果不处理又会报类型错误。
cv2.rectangle(frame, (round(left), round(top)), (round(right), round(bottom)), (0, 0, 255), 2)
用round把float进行四舍五入转找成整形。
--------------------- 
作者:SAME999ABC 
来源:CSDN 
原文:https://blog.csdn.net/SAME999ABC/article/details/82955670 
版权声明:本文为博主原创文章,转载请附上博文链接!

猜你喜欢

转载自blog.csdn.net/c2a2o2/article/details/86524544