Opencv_contrib: FaceRecognizer load() method is missing from Java wrapper

Created on 5 Jul 2017  Â·  7Comments  Â·  Source: opencv/opencv_contrib

System information (version)
  • OpenCV =>3.3.0
  • Operating System / Platform => Windows 64 Bit
  • Compiler =>Visual Studio 2017
Detailed description

The load(String filename)is missing from OpenCV Java wrapper, so unable to load the trained data from HD.

Note: I have tried theread(String filename), but it is not working. Throws the following exception:

OpenCV Error: Bad argument (This LBPH model is not computed yet. Did you call the train method?) in cv::face::LBPH::predict, file E:\opencv_contrib\modules\facesrc\lbph_faces.cpp, line 396
CvException [org.opencv.core.CvException: cv::Exception: E:\opencv_contrib\modules\facesrc\lbph_faces.cpp:396: error: (-5) This LBPH model is not computed yet. Did you call the train method? in function cv::face::LBPH::predict
]

Edit:
I have a test, which I trained the images with the new version of OpenCV (3.3.0-rc) and again load the trained data by the previous version (3.2.0) the problem still existed, I think the problem can be with the train() method also, because if the data was trained well, then the 3.2.0 version can successfully load the data. And also the load() method is missed totally two bugs till now I have detected....

Steps to reproduce
bug builinstall

All 7 comments

There are no load(String), save(String) methods in LBPHFaceRecognizer anymore. Use read/write instead.
Could you share the result of write?

@sovrasov I know now what was the problem. The problem is in the previous version (3.2.0) there was save(String) and load(String), but in the new version (3.3.0) the load(String) method has been omitted, but the save(String) still exist, so now we cannot use save(String), now we should use write(String) and read(String) instead of save(String) and load(String), so it will be better to ommit the save(String) method as well, to people don't be confuse with these similar methods.

Bahramudin , oh, indeed !

model->save("my.xml") will lead to this output:

<?xml version="1.0"?>
<opencv_storage>
<my_object>
  <threshold>1.7976931348623157e+308</threshold>
  <radius>1</radius>
  <neighbors>8</neighbors>
  <grid_x>8</grid_x>
  <grid_y>8</grid_y>

so model->read("my.xml") will get confused about the (artificial ?) "my_object" toplevel node

while model->write("my.xml") produces this:

<?xml version="1.0"?>
<opencv_storage>
<threshold>1.7976931348623157e+308</threshold>
<radius>1</radius>
<neighbors>8</neighbors>
<grid_x>8</grid_x>
<grid_y>8</grid_y>

unfortunately now, the save() method comes from cv::Algorithm, we cannot simply "skip" it ;(
also, ppl might have serialized models from a previous version (like you), so i'm afraid, the outcome will
have be the opposite: skip both read(String) and write(String) methods in favour of load() and save()

@berak I think we can leave read, write and load as they are and unify their behavior to provide backward compatibility with 3.2.

@sovrasov ah, right. probably just add the node to write(String) in the same way save(String) does it, and read(String) from getFirstToplevelNode() instead of root().

i'll try that. yes, that will work. imho, it should have a unit test, too.

C:\Users\srujan\Desktop\EMP>python final_code.py
[ INFO:0] Initialize OpenCL runtime…
OpenCV Error: Bad argument (This Fisherfaces model is not computed yet. Did you
call Fisherfaces::train?) in cv::face::Fisherfaces::predict, file C:\projects\op
encv-python\opencv_contrib\modules\facesrc\fisher_faces.cpp,

OpenCV: 3.4.0

plz tell me the solution

hey, I have the same error please help me

Was this page helpful?
0 / 5 - 0 ratings