用python进行人脸识别-小白级

小白练手的~
欢迎指出不足~

import cv2
import face_recognition
from PIL import Image
#1.读取
face_image=face_recognition.load_image_file(r'C:\Users\hzy\Desktop\1.jpg')

#128维人脸编码 相当于 五官数据
face_encodings=face_recognition.face_encodings(face_image)

face_locations=face_recognition.face_locations(face_image)

face1=face_encodings[0]

face2=face_encodings[1]
#3.比较 tolerance越低越严格
results=face_recognition.compare_faces([face1],face2,tolerance=0.5)#布尔类型的数据
#4.结果
print(results)
#结果为true or false
if results==[True]:
    print(1)
    name='Yes'
else:
    print(0)
    name='No'
#绘图
for i in range(len(face_encodings)):
    face_encoding=face_encodings[(i-1)]
    face_location=face_locations[(i-1)]
    top,right,bottom,left=face_location
    #画框
    cv2.rectangle(face_image,(left,top),(right,bottom),(0,255,0),2)
    #写字
    cv2.putText(face_image,name,(left-10,top-10),cv2.FONT_HERSHEY_SIMPLEX,0.8,(255,0,0),2)
face_image_rgb=cv2.cvtColor(face_image,cv2.COLOR_BGR2RGB)
cv2.imshow('output',face_image_rgb)




ps:这个程序识别刘亦菲和黄圣依的某张照片tolerance=0.5时结果为True,0.4时结果为False了。。。

关于face_recognition的安装我参考了这两篇:
https://blog.csdn.net/scc_722/article/details/80613933
https://blog.csdn.net/weixin_41453476/article/details/105854784

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值