taleb alashkar
taleb alashkar

Reputation: 11

cascade face detection C++ Opencv 3.0

I am trying to implement face detection mentioned in the tutorial

http://docs.opencv.org/3.0-beta/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html#cascade-classifier

I am using OpenCV 3.0 on Ubuntu 14.04.

I downloaed the cascade xml files from here

https://github.com/opencv/opencv/tree/master/data/haarcascades

When I compile the code it gives me this error message:

OpenCV Error: Parsing error (/...../haarcascade_frontalcatface.xml(5): Valid XML should start with '<?xml ...?>') in icvXMLParse, file /home/taleb/opencv3/opencv/modules/core/src/persistence.cpp, line 2220
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/taleb/opencv3/opencv/modules/core/src/persistence.cpp:2220: error: (-212) /home/taleb/pythonproject/test1/haarcascade_frontalcatface.xml(5): Valid XML should start with '<?xml ...?>' in function icvXMLParse

Any suggestion?

Upvotes: 1

Views: 671

Answers (1)

Ganesh Kathiresan
Ganesh Kathiresan

Reputation: 2088

I found a couple of fixes in stack overflow and other websites. They are as follows:

  1. Change the character encoding from UTF-8 to ANSI with Notepad++.

  2. Previous answer:

convert_cascade is for cascades trained by haartraining application and it does not support a format of cascades trained by traincascade application.

To do this with traincascade, just run opencv_traincascade again with the same "-data" but set "-numStages" to the point you want to generate up to. 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. Interrupting the process during a stage could result in corrupt data, so if you're best off deleting the stage in completion.

refrence: https://stackoverflow.com/a/25831423/5671364.

  1. XML Standard states:

if no encoding declaration is present in the XML document (and no external encoding declaration mechanism such as the HTTP header is available), the assumed encoding of an XML document depends on the presence of the Byte-Order-Mark (BOM).

There are 3 ways to fix this:

  • Let OpenCV just put the ´encoding="ASCII"´ tag into the top root XML tag.
  • Leave the top root XML tag, but encode everything as UTF-8 before writing it to file.
  • Do something else, with Byte-Order-Mark, but keep it to the standard.

refrence: http://code.opencv.org/issues/976

Upvotes: 2

Related Questions