00001 /*!@file ObjRec/getLabelMeInfo.C get information for the labelme data set */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/ObjRec/getLabelMeInfo.C $ 00035 // $Id: getLabelMeInfo.C 7063 2006-08-29 18:26:55Z rjpeters $ 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 //Check for jpg 00065 if (files[i].find(".xml") != std::string::npos){ 00066 //printf("%s\n", files[i].c_str()); 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 //Get the xml file for the given scene 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 //clear the objname and polygons 00125 objNames.clear(); 00126 00127 //Get the root element node 00128 xmlNode *root_element = xmlDocGetRootElement(doc); 00129 00130 //look for object annotations 00131 xmlNodePtr cur = root_element->xmlChildrenNode; //dont care about toop level 00132 while (cur != NULL) { 00133 if ((!xmlStrcmp(cur->name, (const xmlChar *)"object"))) { 00134 00135 xmlNodePtr object = cur->xmlChildrenNode; 00136 while(object != NULL) //read the attributes and polygons 00137 { 00138 //Name 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; //next object 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 /* So things look consistent in everyone's emacs... */ 00168 /* Local Variables: */ 00169 /* indent-tabs-mode: nil */ 00170 /* End: */