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 #include "ComplexObject.H"
00039 #include "Image/DrawOps.H"
00040 #include "Image/ColorOps.H"
00041 #include "GUI/XWindow.H"
00042
00043 #include <cmath>
00044 #include <fstream>
00045
00046
00047 ComplexObject::ComplexObject(char* name, char* vodbName)
00048 {
00049 itsName = name;
00050 itsVODBName = vodbName;
00051 MYLOGVERB=LOG_CRIT;
00052
00053 if (itsVODB.loadFrom(vodbName) == false)
00054 LFATAL("Cannot operate without a valid database.");
00055
00056
00057
00058 std::string objectfilestr = vodbName;
00059
00060
00061 std::string filepathstr = objectfilestr.substr(0, objectfilestr.find_last_of('/')+1);
00062
00063
00064 }
00065
00066
00067
00068 ComplexObject::ComplexObject(char* objFile)
00069 {
00070
00071
00072 std::ifstream is(objFile);
00073 std::string name ="";
00074 std::string vodbName ="";
00075 std::string objFileStr = objFile;
00076
00077 if (is.is_open() == false) {
00078 LERROR("Cannot open object '%s' ", objFile);
00079 return;
00080 }
00081
00082
00083 std::string filepath = objFileStr.substr(0, objFileStr.find_last_of('/')+1);
00084
00085 getline(is, name);
00086 getline(is, vodbName);
00087 vodbName = filepath + vodbName;
00088
00089
00090 itsName = name;
00091
00092 printf("VODB: %s \t Object Name: %s \n", vodbName.c_str(), itsName.c_str());
00093 itsVODBName = (char*)vodbName.c_str();
00094 MYLOGVERB=LOG_CRIT;
00095
00096 if (itsVODB.loadFrom(vodbName) == false)
00097 LFATAL("Cannot operate without a valid database.");
00098
00099
00100
00101 std::string objectfilestr = vodbName;
00102
00103
00104 std::string filepathstr = objectfilestr.substr(0, objectfilestr.find_last_of('/')+1);
00105
00106 }
00107
00108
00109
00110 ComplexObject::~ComplexObject()
00111 {
00112 }
00113
00114
00115
00116
00117 int ComplexObject::matchKeypoints(bool showAll, Image< PixRGB<byte> > inputImg, VisualObjectMatchAlgo voma, std::vector < rutz::shared_ptr<VisualObjectMatch> >& matches, Image< PixRGB<byte> >& kpImg, Image< PixRGB<byte> >& fusedImg)
00118 {
00119
00120
00121
00122 rutz::shared_ptr<VisualObject>
00123 vo(new VisualObject("mypic", "mypicfilename", inputImg,
00124 Point2D<int>(-1,-1), std::vector<float>(),
00125 std::vector< rutz::shared_ptr<Keypoint> >(), true));
00126 return matchKeypoints(showAll, vo, voma, matches, kpImg, fusedImg);
00127
00128 }
00129
00130
00131
00132 int ComplexObject::matchKeypoints(bool showAll, rutz::shared_ptr<VisualObject> vo, VisualObjectMatchAlgo voma, std::vector < rutz::shared_ptr<VisualObjectMatch> >& matches, Image< PixRGB<byte> >& kpImg, Image< PixRGB<byte> >& fusedImg)
00133 {
00134
00135
00136
00137
00138
00139
00140
00141 const uint nmatches = itsVODB.getObjectMatches(vo, matches, voma, 1);
00142
00143
00144
00145 Image< PixRGB<byte> > mimg;
00146 std::vector<Point2D<int> > tl, tr, br, bl;
00147
00148
00149
00150
00151 if (nmatches == 0U)
00152 {
00153 printf("### No matching object found.\n");
00154 }
00155 else
00156 {
00157
00158
00159
00160 if(showAll) {
00161 for (uint i = 0; i < nmatches; i ++)
00162 {
00163 rutz::shared_ptr<VisualObjectMatch> vom = matches[i];
00164 rutz::shared_ptr<VisualObject> obj = vom->getVoTest();
00165
00166 printf("### %s Object match with '%s' score=%f\n",
00167 itsName.c_str(), obj->getName().c_str(), vom->getScore());
00168
00169
00170
00171
00172
00173
00174 mimg = vom->getTransfTestImage(mimg);
00175
00176
00177
00178 Point2D<int> ptl, ptr, pbr, pbl;
00179 vom->getTransfTestOutline(ptl, ptr, pbr, pbl);
00180 tl.push_back(ptl); tr.push_back(ptr);
00181 br.push_back(pbr); bl.push_back(pbl);
00182
00183 }
00184 }
00185 else {
00186
00187 rutz::shared_ptr<VisualObjectMatch> vom = matches[0];
00188 if (vom->checkSIFTaffine() == false)
00189 return 0;
00190
00191 rutz::shared_ptr<VisualObject> obj = vom->getVoTest();
00192 kpImg = vom->getMatchImage(1.0F);
00193 printf("### %s Object match with '%s' score=%f\n",
00194 itsName.c_str(), obj->getName().c_str(), vom->getScore());
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 }
00214
00215
00216 return nmatches;
00217 }
00218
00219
00220
00221
00222
00223
00224