00001 /*! @file INVT/StereoVision.C [put description here] */ 00002 00003 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/INVT/StereoVision.C $ 00004 // $Id: StereoVision.C 10827 2009-02-11 09:40:02Z itti $ 00005 00006 #include "Channels/StereoChannel.H" 00007 #include "Component/ModelManager.H" 00008 #include "Image/Image.H" 00009 #include "Image/Pixels.H" 00010 #include "Media/FrameSeries.H" 00011 #include "GUI/XWinManaged.H" 00012 #include "Image/ColorOps.H" 00013 #include "Image/ShapeOps.H" 00014 #include "Media/MediaSimEvents.H" 00015 #include "Neuro/StdBrain.H" 00016 #include "Neuro/NeuroSimEvents.H" 00017 #include "Neuro/VisualCortex.H" 00018 #include "Raster/Raster.H" 00019 #include "Simulation/SimEventQueueConfigurator.H" 00020 00021 #include <cstdio> 00022 #include <cstdlib> 00023 #include <cstring> 00024 #include <stdio.h> 00025 00026 void printRegion(Image<float> img,int sX,int eX,int dX, int sY,int eY, int dY); 00027 00028 int main(const int argc, const char **argv) 00029 { 00030 MYLOGVERB = LOG_INFO; // suppress debug messages 00031 00032 // Instantiate a ModelManager: 00033 ModelManager manager("Stereo Vision Model"); 00034 00035 nub::soft_ref<SimEventQueueConfigurator> 00036 seqc(new SimEventQueueConfigurator(manager)); 00037 manager.addSubComponent(seqc); 00038 00039 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager)); 00040 manager.addSubComponent(ifs); 00041 00042 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager)); 00043 manager.addSubComponent(ofs); 00044 00045 // Instantiate our various ModelComponents: 00046 nub::soft_ref<StdBrain> brain(new StdBrain(manager)); 00047 manager.addSubComponent(brain); 00048 00049 nub::soft_ref<StereoChannel> stc(new StereoChannel(manager)); 00050 manager.addSubComponent(stc); 00051 00052 // Parse command-line: 00053 if (manager.parseCommandLine(argc, argv, 00054 "<image> <image>", 2, 2) == false) 00055 return(1); 00056 00057 nub::soft_ref<SimEventQueue> seq = seqc->getQ(); 00058 00059 CloseButtonListener wList; 00060 //int w = 256; int h = 256; 00061 Image<float> imgL//;imgL.resize(w,h,true); 00062 = Raster::ReadGray(manager.getExtraArg(0)); 00063 Image<float> imgR//;imgR.resize(w,h,true); 00064 = Raster::ReadGray(manager.getExtraArg(1)); 00065 int w = imgL.getWidth(); 00066 int h = imgR.getHeight(); 00067 00068 /* 00069 for (int i = 0; i < 4; i++) 00070 for (int j = 0; j <4; j++) 00071 { 00072 if(!(i == 2 & j == 1)) 00073 { 00074 drawPatch(imgR, *(new Point2D<int>(32+64*i ,32+64*j)),2,(float)255.0); 00075 drawPatch(imgL, *(new Point2D<int>(32+64*i+2,32+64*j)),2,(float)255.0); 00076 } 00077 else 00078 { 00079 drawPatch(imgR, *(new Point2D<int>(32+64*i+2,32+64*j)),2,(float)255.0); 00080 drawPatch(imgL, *(new Point2D<int>(32+64*i ,32+64*j)),2,(float)255.0); 00081 } 00082 } 00083 //drawPatch(imgR, *(new Point2D<int>(84,80)),2,(float)205.0); 00084 //drawPatch(imgL, *(new Point2D<int>(82,80)),2,(float)205.0); 00085 00086 inplaceAddBGnoise2(imgL, 2.0); 00087 inplaceAddBGnoise2(imgR, 2.0); 00088 */ 00089 00090 //imgL = zoomXY(imgL, 4,-1); 00091 //imgR = zoomXY(imgR, 4,-1); 00092 00093 XWinManaged L(Dims(w,h),1000,000,"imgL"); 00094 L.drawImage(zoomXY(imgL, 1,-1),0,0); wList.add(L); 00095 XWinManaged R(Dims(w,h),1000,300,"imgR"); 00096 R.drawImage(zoomXY(imgR, 1,-1),0,0); wList.add(R); 00097 00098 Image<byte> bimgL = imgL; 00099 Image<byte> bimgR = imgR; 00100 Image <byte> zerro(bimgL.getWidth(),bimgL.getHeight(),ZEROS); 00101 XWinManaged LR(Dims(w,h),1000,800,"imgL+imgR"); 00102 LR.drawImage(zoomXY(makeRGB(bimgL,bimgR,zerro), 1,-1),0,0); wList.add(LR); 00103 00104 // let's get all our ModelComponent instances started: 00105 printf("\nSTART\n\n"); 00106 manager.start(); 00107 00108 printf("adding Stereo Channel"); 00109 00110 LFATAL("fixme"); 00111 /* 00112 brain->getVC()->addSubChan(stc); 00113 00114 // set the weight of channels besides stereo to 0; 00115 brain->getVC()->setSubchanTotalWeight("color", 0.0); 00116 brain->getVC()->setSubchanTotalWeight("flicker", 0.0); 00117 brain->getVC()->setSubchanTotalWeight("intensity", 0.0); 00118 brain->getVC()->setSubchanTotalWeight("orientation", 0.0); 00119 brain->getVC()->setSubchanTotalWeight("motion", 0.0); 00120 */ 00121 XWinManaged final(Dims(w,h),1000,800,"FINAL"); 00122 wList.add(final); 00123 00124 // main loop: 00125 printf("\nMAIN_LOOP\n\n"); 00126 00127 while(1) 00128 { 00129 // read new image in? 00130 const FrameState is = ifs->update(seq->now()); 00131 if (is == FRAME_COMPLETE) break; // done 00132 if (is == FRAME_NEXT || is == FRAME_FINAL) // new frame 00133 { 00134 stc->setSecondImage(&imgR); 00135 rutz::shared_ptr<SimEventInputFrame> 00136 e(new SimEventInputFrame(brain.get(), GenericFrame(bimgL), 0)); 00137 seq->post(e); // post the image to the brain 00138 } 00139 00140 // evolve brain: 00141 (void) seq->evolve(); 00142 00143 // write outputs or quit? 00144 bool gotcovert = false; 00145 if (seq->check<SimEventWTAwinner>(0)) gotcovert = true; 00146 const FrameState os = ofs->update(seq->now(), gotcovert); 00147 00148 if (os == FRAME_NEXT || os == FRAME_FINAL) 00149 brain->save(SimModuleSaveInfo(ofs, *seq)); 00150 00151 if (os == FRAME_FINAL) break; // done 00152 00153 // if we displayed a bunch of images, let's pause: 00154 if (ifs->shouldWait() || ofs->shouldWait()) 00155 Raster::waitForKey(); 00156 00157 /* 00158 Image<float> ***fImgL, ***fL; 00159 Image<float> ***fImgR, ***fR; 00160 00161 ImageSet<float> dispMap[12]; 00162 00163 stc->getRawFilteredImages(&fImgL,&fImgR); 00164 stc->dispChan(0,0).getRawFilteredImages(&fL,&fR); 00165 00166 for(int i = 0; i<3; i++) 00167 stc->dispChan(0,i).getDispMap(&dispMap[i]); 00168 00169 int chan = 0; 00170 Image<float> temp0 = stc->dispChan(0,chan).getOutput(); 00171 XWinManaged subchan0(Dims(w,h),1000,500,"Conspicuous0"); 00172 subchan0.drawImage(zoomXY(temp0, 16,-1),0,0); wList.add(subchan0); 00173 00174 chan = 1; 00175 Image<float> temp1 = stc->dispChan(0,chan).getOutput(); 00176 XWinManaged subchan1(Dims(w,h),1000,600,"Conspicuous1"); 00177 subchan1.drawImage(zoomXY(temp1, 16,-1),0,0); wList.add(subchan1); 00178 00179 chan = 2; 00180 Image<float> temp2 = stc->dispChan(0,chan).getOutput(); 00181 XWinManaged subchan2(Dims(w,h),1000,700,"Conspicuous2"); 00182 subchan2.drawImage(zoomXY(temp2, 16,-1),0,0); wList.add(subchan2); 00183 00184 Image<float> temp = stc->getOutput(); 00185 final.drawImage(zoomXY(temp, 16,-1),0,0); 00186 00187 XWinManaged *SM[6]; 00188 for(int i = 0; i< 6; i++) 00189 { 00190 temp = stc->dispChan(0,chan).getSubmap(i); 00191 temp.setVal(0,0,0); 00192 temp.setVal(0,1,1); 00193 00194 SM[i] = new XWinManaged(Dims(w,h),750,i*150,"SUBMAP"); 00195 SM[i]->drawImage(zoomXY(temp,16,-1),0,0); 00196 wList.add(*SM[i]); 00197 00198 } 00199 00200 //int de = 0; 00201 XWinManaged *DM[3][7]; 00202 //float min, max; 00203 for(int i = 0;i<3;i++) 00204 for(int de = 0; de< 7; de++) 00205 { 00206 //dispMap[i][de].getMinMax(min,max); 00207 //printf("MIN: %f, MAX: %f\n\n",min,max); 00208 00209 //DM[i][de] = new XWinManaged(Dims(w,h),i*250,de*200,"imgL"); 00210 //DM[i][de]->drawImage(zoomXY(dispMap[i][de],(int)pow(2.0,de),-1),0,0); 00211 //wList.add(*DM[i][de]); 00212 } 00213 */ 00214 } 00215 while(!(wList.pressedAnyCloseButton()))sleep(1); 00216 // stop all our ModelComponents 00217 manager.stop(); 00218 00219 // all done! 00220 printf("All done\n"); 00221 return 0; 00222 } 00223 00224 00225 void printRegion(Image<float> img,int sX,int eX,int dX, int sY,int eY, int dY) 00226 { 00227 for(int j = sY; j<=eY; j+=dY) 00228 { 00229 for(int i = sX; i<=eX; i+=dX) 00230 printf("%8.3f ", img.getVal(i,j)); 00231 printf(" \n"); 00232 } 00233 printf("\n"); 00234 } 00235