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.EigenFaceRecognizer_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= 19228.277485215305
算法:PCA人脸识别是将高维的人脸数据处理为低维数据后(降维),再进行数据分析和处理,获取识别结果。
retval=cv2.face.EigenFaceRecognizer_create([, num_components[, threshold]])
None=cv2.face_FaceRecognizer.train(src, labels)
label, confidence=cv2.face_FaceRecognizer.predict(src)
网址:https://www.matongxue.com/madocs/1025/
本文分享自 图像处理与模式识别研究所 微信公众号,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文参与 腾讯云自媒体同步曝光计划 ,欢迎热爱写作的你一起参与!