Ask Your Question
2

Convert opencv_traincascade intermediate output into xml

asked 2013-02-08 13:57:20 -0500

Justin gravatar image

I began training a cascade classifier

opencv_traincascade -data cascade -bg neg.txt -vec pos.vec -numPos 1000 -numNeg 1000 -w 48 -h 48

and partway in I killed the program, giving me intermediate output:

$ ls cascade/

params.xml

stage0.xml

stage1.xml

stage2.xml

stage3.xml

stage4.xml

stage5.xml

Now I would like to convert this into an XML file. I tried to use c-example-convert_cascade

c-example-convert_cascade --size="48x48" ./cascade cascade.xml

But got the following error:

OpenCV Error: Parsing error (./cascade(0): Valid XML should start with '') in icvXMLParse, file /home/jmuncaster/OutsideSource/opencv/modules/core/src/persistence.cpp, line 2227 terminate called after throwing an instance of 'cv::Exception' what(): /home/jmuncaster/OutsideSource/opencv/modules/core/src/persistence.cpp:2227: error: (-212) ./cascade(0): Valid XML should start with '' in function icvXMLParse

Question: How do I convert the intermediate output to an XML file readable by cv::CascadeClassifier?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-02-10 14:09:27 -0500

Maria Dimashova gravatar image

There are two applications to train cascade classifiers in OpenCV now, see http://answers.opencv.org/question/757/haartraining-vs-traincascade-object-detection/#759.

c-example-convert_cascade is for cascades trained by haartraining application and it does not support a format of cascades trained by traincascade application. This is why you got the exception.

For the conversion in your case you should run opencv_traincascade again with the same "-data" but set "-numStages 6". The application will load the trained stages, realize that there is required number of stages, write the result cascade in xml and finish a work.

Please also keep in mind that when you kill the application the last stage*.xml can be broken (partially saved). In this case you'll get an exception with the suggested conversion too because the broken xml can not be read. You can just remove the last stage xml or set "-numStages 5".

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2013-02-08 13:57:20 -0500

Seen: 5,423 times

Last updated: Feb 10 '13