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.
We have moved to a new forum at http://jevois.usc.edu, please check it out. The forum at jevois.org/qa will not allow new user registrations but is maintained alive for its useful past questions and answers.
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
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
asked Dec 5, 2018 in Programmer Questions by Peter (580 points)

1 Answer

0 votes
Hello,

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.

Peter
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.
...