【发布时间】:2018-04-08 16:07:21
【问题描述】:
我使用 openCV 3 和 Python 3 来训练人脸识别。我可以毫无错误地训练 LBPHFace 和 EigenFace,但在训练 FisherFace 时会显示错误。
这是我的代码。
import os
import cv2
import numpy as np
from PIL import Image
LBPHFace=cv2.face.LBPHFaceRecognizer_create()
EigenFace=cv2.face.EigenFaceRecognizer_create()
FisherFace=cv2.face.FisherFaceRecognizer_create()
path='dataSet'
def getImagesWithID(path):
imagePaths=[os.path.join(path,f) for f in os.listdir(path)]
#print imagePaths
faces=[]
IDs=[]
for imagePath in imagePaths:
faceImg=Image.open(imagePath).convert('L')
faceNp=np.array(faceImg,'uint8')
ID=int(os.path.split(imagePath)[-1].split('.')[1])
faces.append(faceNp)
IDs.append(ID)
cv2.imshow("training" , faceNp)
cv2.waitKey(10)
return np.array(IDs), faces
Ids,faces=getImagesWithID(path)
LBPHFace.train(faces, Ids)
LBPHFace.write('recognizer/LBPHData.xml')
EigenFace.train(faces, Ids)
EigenFace.write('recognizer/EigenData.xml')
FisherFace.train(faces, Ids)
FisherFace.write('recognizer/FisherData.xml')
cv2.destroyAllWindows()
它显示像这样的错误。
Traceback (most recent call last):
File "C:\Users\lenovoITC\AppData\Local\Programs\Python\Python36-32\training.py", line 33, in <module>
FisherFace.train(faces, Ids)
cv2.error: C:\projects\opencv-python\opencv\modules\core\src\lda.cpp:1019:
error: (-5) At least two classes are needed to perform a LDA. Reason: Only one class was given! in function cv::LDA::lda
如何训练 FisherFaceRecognizer 数据集?
【问题讨论】:
-
可能值得一看this
-
我认为,它至少需要两张图像来训练数据集。
标签: python opencv image-processing