Reputation: 89
I am new to openCV and copied some basic eye/face tracking code from example code. I receive a parsing error on line 20 - "face_cascade.load(...)".
String face_cascade_name = "C:/Users/$Username$/Downloads/haarcascade_frontalface_alt.xml";
if (!face_cascade.load( face_cascade_name ) )
{
cout << "--(!)Error loading eyes cascade\n";
return -1;
};
When I run it (in release mode), I get an "unhandled exception" and break. In debug mode, I also get an XML parsing error to the console (see below).
When debugging, I found everything runs as expected ONLY IF I use "haarcascade_eye_tree_eyeglasses.xml" as my CascadeClassifier.
String face_cascade_name = "C:/Users/$Username$/Downloads/haarcascade_eye_tree_eyeglasses.xml"
I have tried re-downloading the HaarCascades multiple times from openCV's github (I don't see any other complaints about bad XML files). I have tried to load multiple different XML files, but all throw the same error, other than the "haarcascade_eye_tree_eyeglasses.xml". I can't find this issue anywhere else I've looked online. I've tried re-building the openCV library, and even tried pasting the other classifier XML data into the header of "haarcascade_eye_tree_eyeglasses.xml" and don't know what to try next.
Any ideas why only 1 HaarCascade XML file is loading correctly?
Visual Studio Windowed Error
Unhandled exception at 0x00007FFC5E3F9129 in testCV.exe: Microsoft C++ exception: cv::Exception at memory location 0x000000883396DF90.
Debug Console Error
OpenCV(4.1.0-dev) Error: Parsing error (cv::XMLParser::parse) in C:\Users\$Username$\source\repos\testCV\haarcascade_frontalface_alt.xml(1): Valid XML should start with '<?xml ...?>', file C:\Users\$Username$\Downloads\opencv-master\modules\core\src\persistence_xml.cpp, line 786
persistance_xml.cpp line 774-786:
bool parse(char* ptr)
{
CV_Assert( fs != 0 );
std::string key, key2, type_name;
int tag_type = 0;
bool ok = false;
// CV_XML_INSIDE_TAG is used to prohibit leading comments
ptr = skipSpaces( ptr, CV_XML_INSIDE_TAG );
if( memcmp( ptr, "<?xml", 5 ) != 0 ) // FIXIT ptr[1..] - out of bounds read without check
CV_PARSE_ERROR_CPP( "Valid XML should start with \'<?xml ...?>\'" );
I am using Visual Studio 2017, OpenCV 4.1.0, Win10.
Upvotes: 0
Views: 5339
Reputation: 1
Here ,I finally find the true answer.
You need to change xml files to UTF-8. Usually ,We download the file is UTF-8 With Bom.
You Can Change the File Code Using VsCode APP.(Please Google it)
Upvotes: 0
Reputation: 151
Clone "OpenCV" repository from github (https://github.com/opencv/opencv/tree/master) on your local machine. "Dont" copy content .Copy paste file directly from cloned location to your visual studio. It would work.
Upvotes: 0
Reputation: 592
I had this issue when copy/pasted the content of those xml files from GitHub to a local file. After cloning the repo locally, and coping the xml files to the desired place the parsing issue disappeared.
Upvotes: 1