【opencv-python-face

效果

两个同样的人能识别为true

两个不一样的人能识别为false

准备要求

装opencv库等基础库
装numpy库等基础库
cv2 和 np 自己搜索安装
装cmake库等基础库
装face_recognition
如下 *** 作

pip install cmake -i https://mirror.baidu.com/pypi/simple
pip install face_recognition -i https://mirror.baidu.com/pypi/simple

主要函数

载入图片

imglhc = face_recognition.load_image_file(‘1_liiuhaocun.png’)

调整大小

imglhc = cv2.resize(imglhc,(0,0),None,0.5,0.5)

面部画矩形

cv2.rectangle(imglhc,(faceLoc[3],faceLoc[0]),(faceLoc[1],faceLoc[2]),(255,0,255),2)

比较

results = face_recognition.compare_faces([encodelhc],encodelhctest,0.4)

encodelhc,encodelhctest 分别为两张图片的编码,0.4为差值,值越小越准确

代码
import cv2
import numpy as np
import face_recognition


imglhc = face_recognition.load_image_file('1_liiuhaocun.png')
imglhc = cv2.cvtColor(imglhc,cv2.COLOR_BGR2RGB)
imglhc = cv2.resize(imglhc,(0,0),None,0.5,0.5)
imglhctest = face_recognition.load_image_file('2_zhenhuan.png')
imglhctest = cv2.cvtColor(imglhctest,cv2.COLOR_BGR2RGB)

faceLoc = face_recognition.face_locations(imglhc)[0]
encodelhc = face_recognition.face_encodings(imglhc)[0]
cv2.rectangle(imglhc,(faceLoc[3],faceLoc[0]),(faceLoc[1],faceLoc[2]),(255,0,255),2)

faceLoc = face_recognition.face_locations(imglhctest)[0]
encodelhctest = face_recognition.face_encodings(imglhctest)[0]
cv2.rectangle(imglhctest,(faceLoc[3],faceLoc[0]),(faceLoc[1],faceLoc[2]),(255,0,255),2)

results = face_recognition.compare_faces([encodelhc],encodelhctest,0.4)
print(results)

cv2.imshow('lhc',imglhc)
cv2.imshow('imglhctest',imglhctest)
cv2.waitKey(0)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/917338.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存