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 "Component/ModelManager.H"
00039 #include "Component/OptionManager.H"
00040 #include "Controllers/PID.H"
00041 #include "Devices/FrameGrabberConfigurator.H"
00042 #include "Devices/sc8000.H"
00043 #include "GUI/XWinManaged.H"
00044 #include "Image/ColorOps.H"
00045 #include "Image/CutPaste.H"
00046 #include "Image/DrawOps.H"
00047 #include "Image/Image.H"
00048 #include "Image/MathOps.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/ShapeOps.H"
00051 #include "Neuro/SaliencyMap.H"
00052 #include "Neuro/VisualCortex.H"
00053 #include "Neuro/WTAwinner.H"
00054 #include "Neuro/WinnerTakeAll.H"
00055 #include "RCBot/Motion/MotionEnergy.H"
00056 #include "Raster/Raster.H"
00057 #include "SIFT/Keypoint.H"
00058 #include "SIFT/ScaleSpace.H"
00059 #include "SIFT/VisualObject.H"
00060 #include "SIFT/VisualObjectDB.H"
00061 #include "Transport/FrameIstream.H"
00062 #include "Util/Timer.H"
00063 #include "Util/Types.H"
00064 #include "Util/log.H"
00065 #include <math.h>
00066
00067
00068 #define UP_KEY 98
00069 #define DOWN_KEY 104
00070 #define LEFT_KEY 100
00071 #define RIGHT_KEY 102
00072
00073 XWinManaged window(Dims(256, 256), -1, -1, "Test Output 1");
00074 XWinManaged window1(Dims(256, 256), -1, -1, "S Map");
00075
00076
00077 int main(int argc, char **argv)
00078 {
00079 MYLOGVERB = LOG_INFO;
00080
00081
00082 ModelManager manager("Camera capture");
00083
00084
00085 nub::soft_ref<FrameGrabberConfigurator>
00086 gbc(new FrameGrabberConfigurator(manager));
00087 manager.addSubComponent(gbc);
00088
00089 nub::soft_ref<VisualCortex>
00090 itsVC(new VisualCortex(manager, "Visual Cortex", "VC"));
00091
00092
00093
00094
00095
00096
00097
00098
00099 manager.addSubComponent(itsVC);
00100
00101 nub::soft_ref<SaliencyMap> itsSMAP(new SaliencyMapTrivial(manager));
00102 manager.addSubComponent(itsSMAP);
00103
00104 nub::soft_ref<WinnerTakeAll> itsWTA(new WinnerTakeAllFast(manager));
00105 manager.addSubComponent(itsWTA);
00106
00107
00108
00109 if (manager.parseCommandLine(argc, (const char **)argv, "", 0, 0) == false) return(1);
00110
00111
00112 nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00113 if (gb.get() == NULL)
00114 LFATAL("You need to select a frame grabber type via the "
00115 "--fg-type=XX command-line option for this program "
00116 "to be useful -- ABORT");
00117
00118
00119
00120
00121
00122 manager.start();
00123
00124
00125
00126 gb->startStream();
00127
00128
00129
00130 int key = 0;
00131
00132
00133
00134 double time = 0;
00135 itsVC->reset(MC_RECURSE);
00136 std::vector<double> feature_vector;
00137
00138 std::vector<double> mean;
00139
00140 Image<PixRGB<byte> > track_img;
00141 Image<PixRGB<byte> > key_points;
00142
00143 VisualObjectDB vdb;
00144
00145
00146
00147 bool find_obj = false;
00148
00149 while(key != 24){
00150
00151
00152
00153 Image< PixRGB<byte> > ima = gb->readRGB();
00154
00155 Point2D<int> location = window.getLastMouseClick();
00156 if (location.i > -1 && location.j > -1){
00157 Dims WindowDims = window.getDims();
00158
00159 float newi = (float)location.i * (float)ima.getWidth()/(float)WindowDims.w();
00160 float newj = (float)location.j * (float)ima.getHeight()/(float)WindowDims.h();
00161 location.i = (int)newi;
00162 location.j = (int)newj;
00163
00164
00165
00166 Rectangle r(Point2D<int>(location.i, location.j), Dims(50, 50));
00167 track_img = crop(ima, r);
00168 rutz::shared_ptr<VisualObject> vo(new VisualObject("Track", "TracK", track_img));
00169
00170
00171 vdb.addObject(vo);
00172 key_points = vo->getKeypointImage();
00173 find_obj = true;
00174
00175 }
00176
00177 Image< PixRGB<byte> > mimg;
00178 std::vector<Point2D<int> > tl, tr, br, bl;
00179
00180 if (find_obj){
00181 std::vector< rutz::shared_ptr<VisualObjectMatch> > matches;
00182 rutz::shared_ptr<VisualObject> vo(new VisualObject("PIC", "PIC", ima));
00183
00184 const uint nmatches = vdb.getObjectMatches(vo, matches, VOMA_KDTREEBBF);
00185
00186 printf("Found %i\n", nmatches);
00187 if (nmatches > 0 ){
00188 for(unsigned int i=0; i< nmatches; i++){
00189 rutz::shared_ptr<VisualObjectMatch> vom = matches[i];
00190 rutz::shared_ptr<VisualObject> obj = vom->getVoTest();
00191 LINFO("### Object match with '%s' score=%f",
00192 obj->getName().c_str(), vom->getScore());
00193
00194 mimg = vom->getTransfTestImage(mimg);
00195
00196
00197
00198 Point2D<int> ptl, ptr, pbr, pbl;
00199 vom->getTransfTestOutline(ptl, ptr, pbr, pbl);
00200 tl.push_back(ptl); tr.push_back(ptr);
00201 br.push_back(pbr); bl.push_back(pbl);
00202
00203
00204 mimg = Image<PixRGB<byte> >(mimg * 0.5F + ima * 0.5F);
00205
00206
00207 PixRGB<byte> col(255, 255, 0);
00208 for (unsigned int i = 0; i < tl.size(); i ++)
00209 {
00210 drawLine(mimg, tl[i], tr[i], col, 1);
00211 drawLine(mimg, tr[i], br[i], col, 1);
00212 drawLine(mimg, br[i], bl[i], col, 1);
00213 drawLine(mimg, bl[i], tl[i], col, 1);
00214 }
00215
00216 window1.drawImage(rescale(mimg, 255, 255));
00217 }
00218 } else {
00219 window1.drawImage(key_points);
00220 }
00221
00222
00223
00224
00225
00226 }
00227
00228
00229
00230
00231 window.drawImage(rescale(ima, 256, 256));
00232
00233
00234
00235 time += 0.1;
00236 }
00237
00238
00239
00240
00241 manager.stop();
00242 return 0;
00243 }
00244
00245
00246
00247
00248
00249
00250