00001
00002
00003
00004
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;
00031
00032
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
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
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
00061 Image<float> imgL
00062 = Raster::ReadGray(manager.getExtraArg(0));
00063 Image<float> imgR
00064 = Raster::ReadGray(manager.getExtraArg(1));
00065 int w = imgL.getWidth();
00066 int h = imgR.getHeight();
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
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
00105 printf("\nSTART\n\n");
00106 manager.start();
00107
00108 printf("adding Stereo Channel");
00109
00110 LFATAL("fixme");
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 XWinManaged final(Dims(w,h),1000,800,"FINAL");
00122 wList.add(final);
00123
00124
00125 printf("\nMAIN_LOOP\n\n");
00126
00127 while(1)
00128 {
00129
00130 const FrameState is = ifs->update(seq->now());
00131 if (is == FRAME_COMPLETE) break;
00132 if (is == FRAME_NEXT || is == FRAME_FINAL)
00133 {
00134 stc->setSecondImage(&imgR);
00135 rutz::shared_ptr<SimEventInputFrame>
00136 e(new SimEventInputFrame(brain.get(), GenericFrame(bimgL), 0));
00137 seq->post(e);
00138 }
00139
00140
00141 (void) seq->evolve();
00142
00143
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;
00152
00153
00154 if (ifs->shouldWait() || ofs->shouldWait())
00155 Raster::waitForKey();
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 }
00215 while(!(wList.pressedAnyCloseButton()))sleep(1);
00216
00217 manager.stop();
00218
00219
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