From e4acf5a6cecb813e048d11817c7879775b81a48b Mon Sep 17 00:00:00 2001 From: berak Date: Sun, 31 Jan 2016 07:56:47 +0100 Subject: [PATCH] datasets: make or_pascal fail gracefully on absent tags --- modules/datasets/src/or_pascal.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/modules/datasets/src/or_pascal.cpp b/modules/datasets/src/or_pascal.cpp index 112a8e589..9afdf1d7e 100644 --- a/modules/datasets/src/or_pascal.cpp +++ b/modules/datasets/src/or_pascal.cpp @@ -61,8 +61,8 @@ public: private: void loadDataset(const string &path, const string &nameImageSet, vector< Ptr > &imageSet); - Ptr parseAnnotation(const string path, const string id); - const char* parseNodeText(XMLElement* node, const string nodeName, const string defaultValue); + Ptr parseAnnotation(const string &path, const string &id); + const char* parseNodeText(XMLElement* node, const string &nodeName, const string &defaultValue); }; @@ -105,17 +105,20 @@ void OR_pascalImp::loadDataset(const string &path, const string &nameImageSet, v } } -const char* OR_pascalImp::parseNodeText(XMLElement* node, const string nodeName, const string defaultValue) +const char* OR_pascalImp::parseNodeText(XMLElement* node, const string &nodeName, const string &defaultValue) { - const char* e = node->FirstChildElement(nodeName.c_str())->GetText(); + XMLElement* child = node->FirstChildElement(nodeName.c_str()); + if ( child == 0 ) + return defaultValue.c_str(); - if( e != 0 ) - return e ; - else + const char* e = child->GetText(); + if( e == 0 ) return defaultValue.c_str(); + + return e ; } -Ptr OR_pascalImp::parseAnnotation(const string path, const string id) +Ptr OR_pascalImp::parseAnnotation(const string &path, const string &id) { string pathAnnotations(path + "Annotations/"); string pathImages(path + "JPEGImages/");