人脸检测——基于face_recognition库

1.face_recognition库安装

        安装face_recognition库需要依赖很多模块。

2.基于face_recognition人脸检测

        代码如下:

# 1.导入库文件
import face_recognition
import cv2
import time

# 2.记录节拍
t = time.time()

# 3.将jpg文件加载到numpy 数组中
image = face_recognition.load_image_file("img_1.jpg")
frame = cv2.imread("img_1.jpg")

# 4.使用默认的给予HOG模型查找图像中所有人脸
# 这个方法已经相当准确了,但还是不如CNN模型那么准确,因为没有使用GPU加速
face_locations = face_recognition.face_locations(image)

# 使用CNN模型
# face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn")

# 5.打印:我从图片中找到了 多少 张人脸
print("I found {} face(s) in this photograph.".format(len(face_locations)))

# 6.循环找到的所有人脸
for face_location in face_locations:
    # 打印每张脸的位置信息
    top, right, bottom, left = face_location
    print(
        "A face is located at pixel location Top: {}, Left: {}, Bottom: {}, Right: {}".format(top, left, bottom, right))

    # 指定人脸的位置信息,然后显示人脸图片
    cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

cv2.imshow('image', frame)
cv2.imwrite('new_image.jpg',frame)
cv2.waitKey(1)  # 刷新界面 不然只会呈现灰色
print('运行时间{}'.format(time.time() - t))
cv2.waitKey(0)
cv2.destroyAllWindows()

        结果显示:

参考:

基于python3、 face_recognition 实现人脸检测,人脸识别_Nie_Hen的博客-CSDN博客_facerecognition实现人脸检测

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值