Welcome new user! You can search existing questions and answers without registering, but please register to post new questions and receive answers. Note that due to large amounts of spam attempts, your first three posts will be manually moderated, so please be patient.
Because of un-manageable amounts of spam despite our use of CAPTCHAs, email authorization, and other tools, we have discontinued this forum (see the 700k+ registered users with validated email addresses at right?). Please email us any questions or post bug reports and feature requests on GitHub at https://github.com/jevois -- The content below remains available for future reference.
Welcome to JeVois Tech Zone, where you can ask questions and receive answers from other members of the community.

I have a problem with : recognizer.train(faces, np.array (labels))

0 votes

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 = []


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)


      face, self.msg = self.detect_face(image)

      jevois.sendSerial("self.msg: " + self.msg)


     # Bei diesem Tutorial werden nicht erkannte Gesichter ignoriert

     if self.msg == "Gesicht zum Training erkannt":

     # Addieren des Gesichtes zur Gesichtsliste


     # Addieren der label fuer dieses Gesicht


     jevois.sendSerial("--" + str(labels) + "--")

    recognizer.train(faces, np.array (labels))  <----- here comes the error


    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
asked Dec 5, 2018 in Programmer Questions by Peter (580 points)

1 Answer

0 votes

I found my problem after a cuple of days and a lot of testing. It is not possible to use a table of strings with the np.array, I have to use only int. It was nessecary to create a table of ints from a table of strings. I changed the program a little bit and now it functuions.

One problem also is inside the invator. If yor program is working without inframe and outframe for a cuple of seconds, your created Python object will be closed from the inventor and you see again the Demo Saliency. that is not OK, but I cannont change it. It would be a good job for Laurent Itti  :-(

Now I can only say:  Merry christmas and a happy new year with a lot of succes.

answered Dec 7, 2018 by Peter (580 points)
Great that you found the answer, it was not trivial. Thanks for sharing and merry Christmas to you too! You mean, if your process() function takes a long time (several seconds), the inventor will switch back to demosaliency? Yes, that is possible and we will look into this.