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
00039
00040
00041 #ifndef TESTCOMPLEXOBJECT_H_DEFINED
00042 #define TESTCOMPLEXOBJECT_H_DEFINED
00043
00044 #include "BeoSub/ComplexObject.H"
00045
00046
00047 #include "Image/Image.H"
00048 #include "Image/Pixels.H"
00049 #include "Image/Transforms.H"
00050 #include "Image/MathOps.H"
00051 #include "GUI/XWindow.H"
00052 #include "Component/ModelManager.H"
00053 #include "Devices/FrameGrabberFactory.H"
00054 #include "Raster/Raster.H"
00055 #include "Util/Timer.H"
00056 #include "Util/Types.H"
00057 #include "Util/log.H"
00058 #include "BeoSub/BeoSubCanny.H"
00059
00060 #include <cstdio>
00061 #include <cstdlib>
00062 #include <cstring>
00063 #include <fstream>
00064 #include <iostream>
00065
00066
00067
00068 int main(int argc, char **argv)
00069 {
00070 Image< PixRGB<byte> > outputImg;
00071
00072 Point2D<int> tl, tr, br, bl;
00073 MYLOGVERB=LOG_CRIT;
00074 bool hasSetup = false;
00075
00076 const char *infilename = NULL;
00077
00078 std::string objectfile="";
00079 int matchcount = 0;
00080 const char *showMatches = NULL;
00081 bool showAllMatches = false;
00082
00083
00084
00085 const char* objectdbfilename = NULL;
00086 std::string line = "";
00087
00088 std::vector < rutz::shared_ptr<VisualObjectMatch> > matches;
00089 Image< PixRGB<byte> > fusedImg;
00090 Image< PixRGB<byte> > keypointImg;
00091
00092 std::vector < rutz::shared_ptr<ComplexObject> > cov;
00093 std::vector < rutz::shared_ptr<ComplexObject> >::iterator coIter, coIterStop;
00094 rutz::shared_ptr<ComplexObject> co;
00095
00096 rutz::shared_ptr<XWindow> wini;
00097
00098
00099
00100 if(argc < 3){
00101 fprintf(stderr,"\n<USAGE> %s database_filename image showall\n",argv[0]);
00102 fprintf(stderr,"\n database_filename: The path and filename of the object database.\n");
00103 fprintf(stderr,"\n image: An image to process. Must be in PGM format.\n");
00104 fprintf(stderr," Type 'none' for camera input.\n");
00105 fprintf(stderr,"\n showall(Y/N): Whether one match (N) or all matches (Y)\n");
00106 fprintf(stderr,"\n should be found.\n");
00107 exit(1);
00108 }
00109
00110
00111
00112
00113
00114
00115 objectdbfilename = argv[1];
00116 std::string fname = objectdbfilename;
00117
00118 std::string filepathstr = fname.substr(0, fname.find_last_of('/')+1);
00119
00120
00121 std::ifstream is(objectdbfilename);
00122 if (is.is_open() == false)
00123 { LERROR("Cannot open '%s' -- USING EMPTY", objectdbfilename); exit(0); }
00124
00125 while(!is.eof()) {
00126 getline(is, line);
00127 objectfile = line;
00128
00129 if (strcmp(objectfile.c_str(), "") == 0) {
00130 continue;
00131 }
00132
00133 printf("Loading: %s\n", objectfile.c_str());
00134
00135
00136 co.reset(new ComplexObject((char*)(filepathstr + objectfile).c_str()));
00137 cov.push_back(co);
00138 }
00139
00140
00141
00142
00143 infilename = argv[2];
00144
00145 showMatches = argv[3];
00146
00147
00148 if(!strcmp(showMatches, "Y") || !strcmp(showMatches, "y")){
00149 showAllMatches = true;
00150 }
00151
00152
00153
00154
00155
00156
00157 ModelManager manager("ComplexObject Tester");
00158
00159 nub::soft_ref<FrameIstream>
00160 gb(makeIEEE1394grabber(manager, "COcam", "cocam"));
00161
00162 if(!strcmp(infilename, "none")){
00163
00164 manager.addSubComponent(gb);
00165
00166
00167
00168 gb->setModelParamVal("FrameGrabberSubChan", 0);
00169 gb->setModelParamVal("FrameGrabberBrightness", 128);
00170 gb->setModelParamVal("FrameGrabberHue", 180);
00171 }
00172 manager.start();
00173
00174 Image< PixRGB<byte> > Img;
00175
00176 if(!strcmp(infilename, "none")){
00177 }
00178 else{
00179
00180 Img = Raster::ReadRGB(infilename);
00181 }
00182
00183
00184
00185 while(1){
00186
00187
00188 if(!strcmp(infilename, "none")){
00189 Img = gb->readRGB();
00190 }
00191
00192
00193 coIter = cov.begin();
00194 coIterStop = cov.end();
00195
00196
00197 rutz::shared_ptr<VisualObject>
00198 vo(new VisualObject("mypic", "mypicfilename", Img,
00199 Point2D<int>(-1,-1), std::vector<float>(),
00200 std::vector< rutz::shared_ptr<Keypoint> >(), false));
00201 outputImg = Img;
00202
00203
00204 while(coIter != coIterStop) {
00205 matchcount = (*coIter)->matchKeypoints(showAllMatches, vo, VOMA_SIMPLE, matches, keypointImg, fusedImg);
00206
00207
00208
00209 if(!hasSetup){
00210
00211 wini.reset(new XWindow(Img.getDims(), -1, -1, "input window"));
00212 wini->setPosition(0, 0);
00213
00214 Dims ndims(Img.getDims().w(), (Img.getDims().h()*2));
00215
00216 hasSetup = true;
00217 }
00218
00219
00220
00221 if (matches.size() > 0) {
00222
00223 LINFO("\nMATCHCOUNT :: %d\tmatches.size() :: %d\n", matchcount, int(matches.size()));
00224 matches[0]->getTransfTestOutline(tl,tr,br,bl);
00225
00226
00227
00228
00229 int size = 3;
00230
00231 Point2D<int> *tmp = NULL;
00232 for(int i = 0; i < 4; i++) {
00233 switch(i) {
00234 case 0:
00235 tmp = &tl;
00236 break;
00237
00238 case 1:
00239 tmp = &tr;
00240 break;
00241
00242 case 2:
00243 tmp = &bl;
00244 break;
00245
00246 case 3:
00247 tmp = &br;
00248 break;
00249 }
00250
00251
00252 if (tmp->i <= 3) {
00253 tmp->i = 4;
00254 }
00255 else if (tmp->i >= outputImg.getWidth()-3) {
00256 tmp->i = outputImg.getWidth() - 4;
00257 }
00258
00259 if (tmp->j <= 3) {
00260 tmp->j = 4;
00261 }
00262 else if (tmp->j >= outputImg.getHeight()-3) {
00263 tmp->j = outputImg.getHeight() - 4;
00264 }
00265 }
00266
00267
00268 drawLine(outputImg, tl, tr, PixRGB<byte>(255, 0, 0), size);
00269 drawLine(outputImg, tr, br, PixRGB<byte>(255, 0, 0), size);
00270 drawLine(outputImg, br, bl, PixRGB<byte>(255, 0, 0), size);
00271 drawLine(outputImg, bl, tl, PixRGB<byte>(255, 0, 0), size);
00272
00273 Point2D<int> com = (tl+tr+bl+br)/4;
00274 drawCross(outputImg, com, PixRGB<byte>(255, 0, 0), 10, size);
00275 }
00276
00277
00278
00279
00280
00281 *coIter++;
00282 }
00283 wini->drawImage(outputImg);
00284 }
00285 return 0;
00286
00287 }
00288
00289
00290 #endif
00291
00292
00293
00294
00295