Some problems with old OpenCV library and haarcascade

Hi to all,
I’m trying to run face recognition on an old version of the OpenCV library, but when uploading a file haarcascade_frontalface_alt.xml the library returns an error with the cvLoad function:

OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /home/sachin/opencv/sachin/opencv-2.4.10/modules/core/src/persistence.cpp, line 4991
terminate called after throwing an instance of 'cv::Exception'
what(): /usr/src/RPM/BUILD/libopencv2.4-2.4.9.1/modules/core/src/persistence.cpp:4991: error: (-2) The node does not represent a user object (unknown type?) in function cvRead

What does the library mean? What kind of user object does she need and where to specify it? I understand that I should use OpenCV version 4.x, but so far I have only managed to figure out the bindings for version 2.x for my programming language (FreePascal). Bindings for version 4 are only in development.

what’s the code you’re trying to run? what data (data files) are you trying to run it on? where did you take that file (XML file) from?

generally, a MRE helps

Code:

...
//Imported function
type
TcvLoad = function(const filename: pCvChar; memstorage: pCvMemStorage = Nil; const name: pCvChar = nil;
    const real_name: ppCvChar = nil): Pointer; cdecl;
var
  cvLoad: TcvLoad;
cvLoad := ocvGetProcAddress('cvLoad', coreDLL);
...

//code for load haar
storage := cvCreateMemStorage(0);
  // Load the First HaarClassifierCascade
  if fileexists(extractfilepath(application.exename)+''+cascade_name) then
  Cascade_Name:=extractfilepath(application.exename)+''+cascade_name;
  try
    ClassifierCascade := cvLoad(pCVChar(Cascade_Name));
...

the program crashes on the line ClassifierCascade := cvLoad(pCVChar(Cascade_Name));
data files getted from github, from OpenCV repo, branch 2.4.(also tried files from archive opencv-2.4.9.zip getted from sourceforge mirror) used file: haarcascade_frontalface_alt.xml, also tried haarcascade_smile.xml and haarcascade_eye.xml

oh wow, that looks like it’s using the ancient OpenCV 1.x API (a C API). abandon all hope. that stuff was made obsolete with OpenCV version 2.0, which introduced C++ API.

if you abandon freepascal too, and switch to embarcadero stuff, you’ll even find a somewhat active-ish community.

you didn’t pass anything for memstorage. maybe you should. the parameters for a cascade classifier are probably not trivial enough to do without the memstorage.

generally, if you get a violated assertion, you can take that message and look for it in the source code. or see what source file and line is stated in that line of output (modules/core/src/persistence.cpp:4991).

1 Like