TestImages.H
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 #ifndef MEDIA_TESTIMAGES_H_DEFINED
00039 #define MEDIA_TESTIMAGES_H_DEFINED
00040
00041 #include "Image/Image.H"
00042 #include "Image/Pixels.H"
00043 #include "Raster/Raster.H"
00044 #include "Raster/GenericFrame.H"
00045
00046 #include <vector>
00047 #include <string>
00048
00049 #ifdef HAVE_LIBXML
00050 #include <libxml/parser.h>
00051 #include <libxml/tree.h>
00052 #endif
00053
00054
00055 class TestImages
00056 {
00057 public :
00058
00059 enum LIBRARY { ALOI, CSAIL, COIL, MIT_LABELME, CALTECH256,
00060 CSCLAB, IMG_DIR, XMLFILE };
00061
00062
00063 enum USETYPE { TRAIN, TEST, ALL };
00064
00065 struct ObjData {
00066 Image<PixRGB<byte> > img;
00067 unsigned int id;
00068 double maxProb;
00069 double normProb;
00070 std::string name;
00071 std::string description;
00072 std::string filename;
00073 Dims dims;
00074 std::vector<Point2D<int> > polygon;
00075
00076 Image<byte> objmask;
00077
00078
00079 std::vector<int> location3D;
00080 };
00081
00082 struct SceneData : public GenericFrame::MetaData
00083 {
00084 Image<PixRGB<byte> > img;
00085 std::string description;
00086 std::string filename;
00087 Dims dims;
00088 std::string type;
00089 std::vector<ObjData> objects;
00090 USETYPE useType;
00091 };
00092
00093
00094
00095 TestImages(const char* imagesPath, LIBRARY lib,
00096 const int numTraining = -1, const int numTesting = -1,
00097 const int numObjects = -1);
00098
00099 ~TestImages();
00100
00101
00102
00103 Image<PixRGB<byte> > getObject(int id=-1, int lum=-1, int col=-2, int rot=-2);
00104
00105
00106 SceneData getSceneData(uint scene, USETYPE useType=ALL);
00107
00108
00109
00110 ObjData getObjectData(uint scene, uint obj, bool getImage = false);
00111
00112
00113 ObjData getObjFromPos(uint scene, const Point2D<int> &pt);
00114
00115 Image<PixRGB<byte> > getScene(uint sceneId, USETYPE useType=ALL);
00116
00117 std::string getSceneFilename(uint sceneId);
00118
00119 Image<PixRGB<byte> > getLabelMeScene(uint sceneId);
00120 Image<PixRGB<byte> > getCscLabScene(uint sceneId);
00121
00122
00123 Image<PixRGB<byte> > generateScene(uint scene);
00124
00125 uint getMaxLum();
00126 uint getMaxCol();
00127 uint getMaxRot();
00128
00129
00130 uint getNumObj(uint scene = 0);
00131
00132
00133 uint getNumScenes(USETYPE useType = ALL);
00134
00135
00136 const char* getObjName(uint id);
00137
00138
00139 std::vector<Point2D<int> > getObjPolygon(uint id);
00140
00141
00142 Image<byte> getObjMask(uint id);
00143
00144
00145 Image<byte> getObjMask(uint scene, uint obj);
00146
00147
00148 Image<byte> getObjMask(uint scene, uint obj, const Dims& sceneDims);
00149
00150
00151 Image<byte> getAllObjMask();
00152
00153
00154 int labelScene(uint scene, Image<PixRGB<byte> > &sceneImg);
00155
00156
00157 void setRootPath(std::string path) { itsCurrentPath = path; }
00158
00159 private:
00160
00161 void readDir(const char *path);
00162
00163 void readCalTech256Dir(const char *path, const int trainingSize = -1,
00164 const int testingSize = -1, bool shuffe = true);
00165
00166 Image<PixRGB<byte> > getCscLabObj(int id);
00167
00168
00169 Image<PixRGB<byte> > getLabelMeObj(int id);
00170
00171
00172 void readObjXML(const char *path);
00173
00174 #ifdef HAVE_LIBXML
00175
00176 void getNodeMatchText(xmlDocPtr doc, xmlNodePtr nodePtr,
00177 const char* nodeName, std::string &result);
00178 #endif
00179
00180 const char* itsImagesPath;
00181 LIBRARY itsLibType;
00182
00183 int itsMaxLum;
00184 int itsMaxCol;
00185 int itsMaxRot;
00186
00187 static const char* ALOI_LUM[];
00188 static const char* ALOI_COL[];
00189 static const char* ALOI_ROT[];
00190
00191 int itsSceneId;
00192
00193 std::vector<std::vector<Point2D<int> > > itsObjPolygon;
00194 std::vector<std::string> itsObjNames;
00195 std::vector<std::string> itsSceneFilenames;
00196 std::vector<ObjData> itsObjects;
00197 Image<PixRGB<byte> > itsCurrentScene;
00198 std::string itsCurrentPath;
00199
00200 std::vector<SceneData> itsScenes;
00201 std::vector<SceneData> itsTrainScenes;
00202 std::vector<SceneData> itsTestScenes;
00203
00204 int itsNumTraining;
00205 int itsNumTesting;
00206 int itsNumObjects;
00207 };
00208
00209 #endif
00210
00211
00212
00213
00214
00215