face_recognition实现简单的人脸识别

face_recognition实现简单的人脸识别

分别实现从图片,视频和摄像头中进行人脸识别,并对人脸区域进行标注。

三种方式的实现方法本质上是一样的,区别只在于对opencv的调用上存在一点区别。

下面以图片中识别人脸的代码为例:

#实现从图片中进行人脸识别
#导入face_recognition 和 cv2 库
import face_recognition
import cv2
import numpy as np

#读入图片
frame = cv2.imread('D:/test/3face.jpg')

#进行图片缩放,这个十分重要,影响到识别是正确率和速度
#大图片进行适当的缩小能明显提高识别速度(在摄像头和视频识别中非常有效)(指数型)
#小图片进行适当放大之后,可以明显提高识别成功率
frame = cv2.resize(frame,(0,0),fx=0.25,fy=0.25)

#cv2的图片排列方式为BGR,需要先转变为RGB模式,face_recognition库才能正常运行
rgb_frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)

#执行face_locations,识别出图片中人脸的位置(左上点,右下点)
face_locations = face_recognition.face_locations(rgb_frame)

for face_location in face_locations:
    top = face_location[0]
    right = face_location[1]
    bottom = face_location[2]
    left = face_location[3]
    #画出矩形框
    cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

cv2.imshow('img', frame)
cv2.imwrite('3faceout.jpg', frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

原图片如下:

1face.jpg?raw=true

3face.jpg?raw=true

效果图如下:

单人脸识别:

1faceout.jpg?raw=true

多人脸识别:

3faceout.jpg?raw=true

其他详细代码(视频,摄像头)和效果展示请见:https://github.com/1647790440/deeplearning/tree/master/face_recognition

转载于:https://www.cnblogs.com/phd1999/p/10767893.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值