python 人脸识别系统

21 篇文章 0 订阅
20 篇文章 0 订阅

python 人脸识别系统

import cv2
import face_recognition
import sys

#1.发现
face_image = face_recognition.load_image_file(input("请粘贴要识别的图片地址:")) #传入要识别的图片
#print(face_image)

#2.进行特征提取 向量化
face_encodings = face_recognition.face_encodings(face_image)  #进行特征提取 向量化
face_locations = face_recognition.face_locations(face_image)  #五官位置
#print(face_encodings)

#判断图片中出现的人数
n = len(face_encodings)
if n > 2:
    print('超过2个人')
    face1 = face_encodings[0]
    face2 = face_encodings[1]
    result = face_recognition.compare_faces([face1], face2, tolerance=0.5)




face1 = face_encodings[0]
face2 = face_encodings[1]



#比较是否是一个人
result = face_recognition.compare_faces([face1],face2,tolerance=0.5)  # 允许0.5的误差
#print(result)


if result == [True]:
    print('人脸一致')
    name = 'PASS'

else:
    print('人脸不一致')
    name = 'NO'

#绘图
for i in range(len(face_encodings)):
    face_encoding = face_encodings[(i-1)]
    face_location = face_locations[(i-1)]
    #print(face_location)
    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,(0,0,255),2)

face_image_rgb = cv2.cvtColor(face_image,cv2.COLOR_BGR2RGB)

#展示图像
cv2.imshow('OutPut',face_image_rgb)
#不要关闭
cv2.waitKey(0)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值