栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

【opencv-python-face

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【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)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/883563.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号