import cv2
import numpy as np
images=[]
images.append(cv2.imread('C:/Users/xpp/Desktop/coins.png',cv2.IMREAD_GRAYSCALE))#原始图像
images.append(cv2.imread('C:/Users/xpp/Desktop/coins.png',cv2.IMREAD_GRAYSCALE))#原始图像
images.append(cv2.imread('C:/Users/xpp/Desktop/Lena.png',cv2.IMREAD_GRAYSCALE))#原始图像
images.append(cv2.imread('C:/Users/xpp/Desktop/Lena.png',cv2.IMREAD_GRAYSCALE))#原始图像
labels=[0,0,1,1]#图像标签
recognizer=cv2.face.FisherFaceRecognizer_create()#人脸识别
recognizer.train(images,np.array(labels))#模型训练
predict_image=cv2.imread('C:/Users/xpp/Desktop/face.png',cv2.IMREAD_GRAYSCALE)#原始图像
label, confidence=recognizer.predict(predict_image)#模型预测
print("label=",label)
print("confidence=",confidence)
cv2.imshow("predict_image",predict_image)
cv2.waitKey()
cv2.destroyAllWindows()
label= 1 confidence= 10647.989937693492
算法:LDA人脸识别是一种经典的线性学习方法,也称Fisher判别分析法。
例子:
Fisher线性判别分析是要找到一条最优的投影线,满足: ● A、B组内的点之间尽可能地靠近 ● C的两个端点之间的距离(间距离)尽可能地远离
retval=cv2.face.FisherFaceRecognizer_create([, num_components[, threshold]])
None=cv2.face_FaceRecognizer.train(src, labels)
label, confidence=cv2.face_FaceRecognizer.predict(src)
本文分享自 图像处理与模式识别研究所 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有