Loading Model for FisherFaceRecognizer

asked 2018-01-05 06:04:33 -0600

sanJo gravatar image

Hi there,

I'm trying to load model files for a FisherFaceRecognizer. The initial problem is that the program was written for an older OpenCV version and it seems some interfaces were changed.

Info about my project:

  • programming language: Python 3.5
  • OpenCV Version: 3.3.0

These are the two lines were I had a problem with:

      model = cv2.face.createFisherFaceRecognizer()
      model.load('foo_model.xml')

In the OpenCV documentation I found out that there is a new way to call the create functions and it seems to work. But I could not find the right call for the load function. I have tried to use the read function of the recognizer, but that results in an error.

        model = cv2.face.FisherFaceRecognizer_create()
        model.read('foo_model.xml')

Does somebody can help me with loading the model files? Thank you :)

edit retag flag offensive close merge delete

Comments

yes, unfortunately, those interfaces are in perpetual motion, and 3.4 will also differ from 3.3.0.

can you add the 1st few lines of your xml to the question ? (and maybe find out the version, from which it was saved ?)

berak gravatar imageberak ( 2018-01-05 06:25:40 -0600 )edit
1

Thanks for your help. The code can be found on the following repo( click) . The model files can be found in the fish_models folder. I'm not quite sure about the OpenCV version, but in the corresponding blog post here it is mentioned that OpenCV 3 was used. I'm not sure if this helps since you mentioned that these interfaces can be changed from version to version. Thanks again

sanJo gravatar imagesanJo ( 2018-01-05 06:37:10 -0600 )edit

"but that results in an error." -- which is, exactly ?

berak gravatar imageberak ( 2018-01-05 07:07:43 -0600 )edit

"File can't be opened for reading! in function read"

sanJo gravatar imagesanJo ( 2018-01-05 07:13:02 -0600 )edit

Here is link:face recognition

supra56 gravatar imagesupra56 ( 2018-01-05 07:26:44 -0600 )edit

I used python 3.5 and OpenCV 3.4.0 for raspberry pi 3. No issue problem.

supra56 gravatar imagesupra56 ( 2018-01-05 07:27:56 -0600 )edit

please take another look at the xml files. do they look like this ? (saved from 3.3.0):

<?xml version="1.0"?>
<opencv_storage>
<my_object>

you might (or not) have to insert a <my_object> node manually.

berak gravatar imageberak ( 2018-01-05 07:32:57 -0600 )edit

I looked into the xml files. They all seem to start like this:

<?xml version="1.0"?>
<opencv_storage>
<num_components>7</num_components>
<mean type_id="opencv-matrix">
<rows>1</rows>
<cols>122500</cols>
<dt>d</dt>
<data>...

I will try to add the <my_object> node then and see if this works.

sanJo gravatar imagesanJo ( 2018-01-05 07:44:40 -0600 )edit

@supra56, the file format as well as the commands to read/write it changed a lot, so folks have problems reading models saved from an older version. it's a known issue.

berak gravatar imageberak ( 2018-01-05 07:56:53 -0600 )edit

I edited the xml files like this:

<?xml version="1.0"?>
<opencv_storage>
<my_object>
<num_components>7</num_components>
<mean type_id="opencv-matrix">
<rows>1</rows>
<cols>122500</cols>
<dt>d</dt>
<data>...

At the beginning and like this at the end :

<labelsInfo>
</labelsInfo>
</my_object>
</opencv_storage>

But unfortunately I'm still getting the same error as before

sanJo gravatar imagesanJo ( 2018-01-05 08:09:34 -0600 )edit