getLabelMeInfo.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifdef HAVE_LIBXML
00039 #include <libxml/parser.h>
00040 #include <libxml/tree.h>
00041
00042 #include <dirent.h>
00043 #include <vector>
00044 #include <string>
00045
00046 std::vector<std::string> files;
00047
00048 void readDir(const char *path = NULL);
00049 void getObjects(std::string &filename, std::vector<std::string> &objNames);
00050
00051 #define ROOT_PATH "/lab/ilab15/tmp/objectsDB/mit/labelMe/Annotations"
00052
00053
00054 int main(const int argc, const char **argv)
00055
00056 {
00057
00058
00059 readDir(NULL);
00060
00061 for(uint i=0; i<files.size(); i++)
00062 {
00063 std::vector<std::string> objNames;
00064
00065 if (files[i].find(".xml") != std::string::npos){
00066
00067 getObjects(files[i], objNames);
00068 for(uint obj=0; obj<objNames.size(); obj++)
00069 printf("%s\n", objNames[obj].c_str());
00070 }
00071 }
00072 }
00073
00074
00075
00076 void readDir(const char *path)
00077 {
00078
00079 std::string newPath;
00080 if (path == NULL)
00081 newPath = std::string(ROOT_PATH);
00082 else
00083 newPath = std::string(ROOT_PATH) + "/" + std::string(path);
00084
00085 DIR *dp = opendir(newPath.c_str());
00086 if (dp != NULL)
00087 {
00088 dirent *dirp;
00089 while ((dirp = readdir(dp)) != NULL ) {
00090 if (dirp->d_name[0] != '.')
00091 {
00092 if (dirp->d_type == 4)
00093 {
00094 readDir(dirp->d_name);
00095 } else {
00096 if (path == NULL)
00097 files.push_back(std::string(dirp->d_name));
00098 else
00099 files.push_back(std::string(path) + "/" + std::string(dirp->d_name));
00100 }
00101 }
00102 }
00103 }
00104
00105 }
00106
00107
00108 void getObjects(std::string &filename, std::vector<std::string> &objNames)
00109 {
00110
00111 xmlDocPtr doc;
00112
00113
00114 std::string xmlFile = std::string(ROOT_PATH) + "/" + filename;
00115
00116
00117 doc = xmlReadFile(xmlFile.c_str(), NULL, 0);
00118 if (doc == NULL)
00119 {
00120 printf("Failed to parse %s\n", xmlFile.c_str());
00121 return;
00122 }
00123
00124
00125 objNames.clear();
00126
00127
00128 xmlNode *root_element = xmlDocGetRootElement(doc);
00129
00130
00131 xmlNodePtr cur = root_element->xmlChildrenNode;
00132 while (cur != NULL) {
00133 if ((!xmlStrcmp(cur->name, (const xmlChar *)"object"))) {
00134
00135 xmlNodePtr object = cur->xmlChildrenNode;
00136 while(object != NULL)
00137 {
00138
00139 if ((!xmlStrcmp(object->name, (const xmlChar *)"name"))) {
00140 xmlChar* name = xmlNodeListGetString(doc, object->xmlChildrenNode, 1);
00141 if (name != NULL)
00142 {
00143 objNames.push_back(std::string((const char*)name));
00144 xmlFree(name);
00145 }
00146 }
00147
00148 object = object->next;
00149 }
00150
00151 }
00152
00153 cur = cur->next;
00154 }
00155
00156
00157 xmlFreeDoc(doc);
00158 xmlCleanupParser();
00159
00160 }
00161
00162
00163 #endif
00164
00165
00166
00167
00168
00169
00170