Hello,
I try to write a Python software for face recognition with the JeVois cam A33 and I always get an error in this line: recognizer.train(faces, np.array (labels)). The error is: TypeError: Expected cv::UMat for argument "labels". I realy do not know, how to solve this problem.
Here the code:
def train_face(self):
facenames = []
facenames=os.listdir('modules/Dambrowsky/FaceRecognition/Namen-und-Gesichter/')
recognizer = cv2.face.LBPHFaceRecognizer_create()
faces = []
labels = []
facename = ""
for facename in facenames:
for y in range(2, 9): # that means that I read for every person the face pictures 2 to 8
image_path = 'modules/Dambrowsky/FaceRecognition/Namen-und-Gesichter/'+str(facename)+'/'+str(y)+'.jpg'
image = cv2.imread(image_path, 0)
jevois.sendSerial(image_path)
face, self.msg = self.detect_face(image)
jevois.sendSerial("self.msg: " + self.msg)
#------STEP-4--------
# Bei diesem Tutorial werden nicht erkannte Gesichter ignoriert
if self.msg == "Gesicht zum Training erkannt":
# Addieren des Gesichtes zur Gesichtsliste
faces.append(face)
# Addieren der label fuer dieses Gesicht
labels.append(facename)
jevois.sendSerial("--" + str(labels) + "--")
recognizer.train(faces, np.array (labels)) <----- here comes the error
recognizer.write('share/facedetector/trainingData.yml')
jevois.sendSerial("Datei .yml_gespeichert")
return (faces, labels)
That is what you can see inside of labels:
[' Peter_Dambrowsky ', ' Peter_Dambrowsky ', ' Peter_Dambrowsky ', ' Peter_Dambrowsky '", 'Peter_Dambrowsky ', ' Peter_Dambrowsky ', ' Peter_Dambrowsky ', ' Peter_Dambrowsky ', ' Sretenka ', ' Sretenka ', ' Sretenka ', 'Sretenka ', ' Sretenka ', ' Sretenka ', ' Sretenka', ' Sretenka']
It means that I will train for 2 Persons the pictures 2 to 8.
Perhaps someone can help me.
Thank you
Regards Peter