jkarimi
jkarimi

Reputation: 1267

OpenCV Cascade Performance: valid XML error

I am running opencv 2.4.8 inside a conda environment. I am able to train a car detector using

opencv_traincascade -data data -vec cars.vec -bg bg.txt -numPos 500 -numNeg 500 -numStages 2 -w 48 -h 24

However, I can not check the performance using

opencv_performance -data data -info cars.txt

I receive a parsing error:

OpenCV Error: Parsing error (data(0): 
Valid XML should start with '<?xml ...?>') in icvXMLParse, 
file /Users/jhelmus/anaconda/conda-bld/work/opencv-2.4.8/modules/core/src/persistence.cpp, line 2252
libc++abi.dylib:terminating with uncaught exception of type cv::
Exception: /Users/jhelmus/anaconda/conda-bld/work/opencv-2.4.8/modules/core/src/persistence.cpp:2252: 
error: (-212) data(0): Valid XML should start with '<?xml ...?>' in function icvXMLParse  

I have checked the .xml files and they are appropriately formatted with

<?xml version="1.0"?>

as the first line.

What is causing this error?

Upvotes: 2

Views: 1499

Answers (1)

bslawski
bslawski

Reputation: 620

It's a poorly worded error message; the issue is with the format of the saved detector. opencv_performance uses an old format that is output by opencv_haartraining, and doesn't work on detectors saved in the format used by opencv_traincascade (docs).

There are two solutions:

1) You could train your detector using opencv_haartraining (man page). This is not recommended, since opencv_haartraining is limited to a single thread. It is also a deprecated method.

2) You can add the -baseFormatSave flag to your opencv_traincascade command (man page), forcing it to save the detector in the old format, i.e.:

opencv_traincascade -data data -vec cars.vec -bg bg.txt -numPos 500 -numNeg 500 -numStages 2 -w 48 -h 24 -baseFormatSave

This feature has a bug, however, that leaves out a classifier type declaration. You can fix it by running

sed -i 's/<cascade>/<cascade type_id="opencv-haar-classifier">/g' data/cascade.xml

on the saved detector to add the missing classifier type.

Either method should allow you to run

opencv_performance -data data -info cars.txt

to test your detector.

Upvotes: 2

Related Questions