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
00042
00043
00044
00045
00046 #include "Beowulf/Beowulf.H"
00047 #include "Component/ModelManager.H"
00048 #include "Devices/DeviceOpts.H"
00049 #include "Devices/FrameGrabberConfigurator.H"
00050 #include "Image/ColorOps.H"
00051 #include "Image/CutPaste.H"
00052 #include "Image/DrawOps.H"
00053 #include "Image/FilterOps.H"
00054 #include "Image/Image.H"
00055 #include "Image/Image.H"
00056 #include "Image/ImageSet.H"
00057 #include "Image/MathOps.H"
00058 #include "Image/Pixels.H"
00059 #include "Image/ShapeOps.H"
00060 #include "Image/Transforms.H"
00061 #include "Neuro/NeuroOpts.H"
00062 #include "Neuro/SaccadeControllerConfigurator.H"
00063 #include "Neuro/SaccadeController.H"
00064 #include "Parallel/pvisionTCP-defs.H"
00065 #include "Simulation/SimEventQueue.H"
00066 #include "Simulation/SimEventQueueConfigurator.H"
00067 #include "Transport/FrameIstream.H"
00068 #ifdef HAVE_SDL_SDL_H
00069 #include "GUI/SDLdisplay.H"
00070 #endif
00071 #include "Util/Assert.H"
00072 #include "Util/FpsTimer.H"
00073 #include "Util/Timer.H"
00074 #include "Util/sformat.H"
00075 #include "Video/RgbConversion.H"
00076 #include "Media/FrameSeries.H"
00077 #include "Transport/FrameInfo.H"
00078
00079 #include <signal.h>
00080 #include <unistd.h>
00081
00082
00083
00084 #define PRESCALE 2
00085
00086
00087 #define NAVG 20
00088 #define TOTAL_FRAMES 100
00089
00090 static bool goforever = true;
00091
00092
00093 void terminate(int s)
00094 { LERROR("*** INTERRUPT ***"); goforever = false; }
00095
00096
00097 void receiveCMAPS(nub::soft_ref<Beowulf>& beo, Image<float> *cmap,
00098 int32 *cmapframe);
00099 uint nCMAPSreceived;
00100
00101 int submain(int argc, char** argv)
00102 {
00103 #ifndef HAVE_SDL_SDL_H
00104 LFATAL("<SDL/SDL.h> must be installed to use this program");
00105 #else
00106 MYLOGVERB = LOG_INFO;
00107
00108
00109 ModelManager manager("Parallel Vision TCP Version 3");
00110
00111
00112 nub::soft_ref<SimEventQueueConfigurator>
00113 seqc(new SimEventQueueConfigurator(manager));
00114 manager.addSubComponent(seqc);
00115
00116 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00117 manager.addSubComponent(ifs);
00118
00119 nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00120 manager.addSubComponent(ofs);
00121
00122
00123
00124
00125
00126 nub::soft_ref<Beowulf>
00127 beo(new Beowulf(manager, "Beowulf Master", "BeowulfMaster", true));
00128 manager.addSubComponent(beo);
00129
00130
00131
00132
00133
00134
00135
00136 nub::soft_ref<SaccadeControllerEyeConfigurator>
00137 scc(new SaccadeControllerEyeConfigurator(manager));
00138 manager.addSubComponent(scc);
00139
00140
00141 manager.setOptionValString(&OPT_SaccadeControllerEyeType, "Threshfric");
00142 manager.setOptionValString(&OPT_FrameGrabberType, "V4L");
00143 manager.setOptionValString(&OPT_SCeyeMaxIdleSecs, "1000.0");
00144 manager.setOptionValString(&OPT_SCeyeThreshMinOvert, "4.0");
00145 manager.setOptionValString(&OPT_SCeyeThreshMaxCovert, "3.0");
00146
00147
00148
00149 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00150
00151
00152 nub::soft_ref<SimEventQueue> seq = seqc->getQ();
00153
00154
00155
00156
00157
00158
00159
00160
00161 int w = ifs->getWidth(), h = ifs->getHeight();
00162 std::string dims = convertToString(Dims(w, h));
00163 LINFO("image size: [%dx%d]", w, h);
00164
00165
00166 manager.setModelParamVal("InputFrameDims", Dims(w, h),
00167 MC_RECURSE | MC_IGNORE_MISSING);
00168
00169 nub::ref<SaccadeController> sc = scc->getSC();
00170
00171 const int foa_size = 64;
00172 manager.setModelParamVal("InputFrameDims", Dims(w, h),
00173 MC_RECURSE | MC_IGNORE_MISSING);
00174 manager.setModelParamVal("SCeyeStartAtIP", true,
00175 MC_RECURSE | MC_IGNORE_MISSING);
00176 manager.setModelParamVal("SCeyeInitialPosition",Point2D<int>(w/2,h/2),
00177 MC_RECURSE | MC_IGNORE_MISSING);
00178 manager.setModelParamVal("FOAradius", foa_size,
00179 MC_RECURSE | MC_IGNORE_MISSING);
00180 manager.setModelParamVal("FoveaRadius", foa_size,
00181 MC_RECURSE | MC_IGNORE_MISSING);
00182
00183
00184
00185
00186 signal(SIGHUP, terminate); signal(SIGINT, terminate);
00187 signal(SIGQUIT, terminate); signal(SIGTERM, terminate);
00188 signal(SIGALRM, terminate);
00189
00190
00191 PixRGB<byte> pix(255, 255, 0);
00192 TCPmessage smsg;
00193 FpsTimer tim;
00194 Timer masterclock;
00195
00196 Image<float> cmap[NBCMAP2];
00197 int32 cmapframe[NBCMAP2];
00198 for (int i = 0; i < NBCMAP2; i ++) cmapframe[i] = -1;
00199 int sml = 4;
00200 Image<float> sm(w >> sml, h >> sml, ZEROS);
00201 Point2D<int> fixation(-1, -1);
00202
00203 nCMAPSreceived = 0;
00204
00205
00206 const PixRGB<byte> grey(127);
00207 std::string info;
00208
00209
00210
00211
00212
00213 manager.start();
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 masterclock.reset();
00230
00231 Timer timer(1000000);
00232
00233 uint fNum = 0;
00234 ifs->updateNext(); Image< PixRGB<byte> > ima = ifs->readRGB();
00235 if(!ima.initialized()) { goforever = false; }
00236 uint nCMAPSsent = 0;
00237
00238 while(nCMAPSreceived < TOTAL_FRAMES*8)
00239 {
00240 timer.reset();
00241
00242 receiveCMAPS(beo, cmap, cmapframe);
00243 uint64 t1 = timer.get();
00244 LINFO("time1[%d]: %f", fNum, t1/1000.0F);
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 sc->evolve(*seq);
00259 Point2D<int> eye = sc->getDecision(*seq);
00260 if (eye.isValid()) fixation = eye;
00261 uint64 t2 = timer.get();
00262 LINFO("time2[%d]: %f", fNum, (t2-t1)/1000.0F);
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 LINFO(" %.1ffps ", tim.getRecentFps());
00281
00282
00283
00284
00285
00286
00287 receiveCMAPS(beo, cmap, cmapframe);
00288
00289
00290
00291 if (nCMAPSsent < TOTAL_FRAMES)
00292 {
00293 nCMAPSsent++;
00294
00295 const int32 frame = int32(tim.frameNumber());
00296
00297
00298
00299
00300 Image<PixRGB<byte> > ima2 =
00301 decY(decX(ima,1<<PRESCALE),1<<PRESCALE);
00302
00303 uint64 t3a = timer.get();
00304 LINFO("time3a[%d]: %f", fNum, (t3a-t2)/1000.0F);
00305
00306
00307
00308 Image<byte> lum = luminance(ima2);
00309
00310
00311 uint64 t3b = timer.get();
00312 LINFO("time3b[%d]: %f", fNum, (t3b-t3a)/1000.0F);
00313
00314
00315 smsg.reset(frame, BEO_ORI0); smsg.addImage(lum); beo->send(smsg);
00316 smsg.setAction(BEO_ORI15); beo->send(smsg);
00317 smsg.setAction(BEO_ORI30); beo->send(smsg);
00318 smsg.setAction(BEO_ORI45); beo->send(smsg);
00319 smsg.setAction(BEO_ORI60); beo->send(smsg);
00320 smsg.setAction(BEO_ORI75); beo->send(smsg);
00321 smsg.setAction(BEO_ORI90); beo->send(smsg);
00322 smsg.setAction(BEO_ORI105); beo->send(smsg);
00323 smsg.setAction(BEO_ORI120); beo->send(smsg);
00324 smsg.setAction(BEO_ORI135); beo->send(smsg);
00325 smsg.setAction(BEO_ORI150); beo->send(smsg);
00326 smsg.setAction(BEO_ORI165); beo->send(smsg);
00327
00328
00329 smsg.setAction(BEO_FLICKER); beo->send(smsg);
00330
00331
00332 smsg.setAction(BEO_LUMINANCE); beo->send(smsg);
00333
00334 uint64 t3c = timer.get();
00335 LINFO("time3c[%d]: %f", fNum, (t3c-t3b)/1000.0F);
00336
00337
00338 Image<byte> r, g, b, y; getRGBY(ima2, r, g, b, y, (byte)25);
00339
00340 smsg.reset(frame, BEO_REDGREEN);
00341 smsg.addImage(r); smsg.addImage(g); beo->send(smsg);
00342 smsg.reset(frame, BEO_BLUEYELLOW);
00343 smsg.addImage(b); smsg.addImage(y); beo->send(smsg);
00344
00345 uint64 t3d = timer.get();
00346 LINFO("time3d[%d]: %f", fNum, (t3d-t3c)/1000.0F);
00347 }
00348
00349 uint64 t3 = timer.get();
00350 LINFO("time3[%d]: %f", fNum, (t3-t2)/1000.0F);
00351
00352
00353 receiveCMAPS(beo, cmap, cmapframe);
00354
00355
00356 info = sformat("%06d / ", tim.frameNumber());
00357 Image<float> sminput;
00358 for (int i = 0; i < NBCMAP2; i ++)
00359 if (cmap[i].initialized())
00360 {
00361 if (sminput.initialized()) sminput += cmap[i];
00362 else sminput = cmap[i];
00363 info += sformat("%06d ", cmapframe[i]);
00364 }
00365 else
00366 info += "------ ";
00367
00368
00369 if (sminput.initialized()) sm = sm * 0.7F + sminput * 0.3F;
00370
00371
00372 while(seq->now() < masterclock.getSimTime()) seq->evolve();
00373 sc->evolve(*seq);
00374
00375
00376 float maxval; Point2D<int> currwin; findMax(sm, currwin, maxval);
00377 WTAwinner newwin =
00378 WTAwinner::buildFromSMcoords(currwin, sml, true,
00379 masterclock.getSimTime(),
00380 maxval, false);
00381 if (newwin.isValid()) sc->setPercept(newwin, *seq);
00382
00383 uint64 t4 = timer.get();
00384 LINFO("time4[%d]: %f", fNum, (t4-t3)/1000.0F);
00385
00386
00387 receiveCMAPS(beo, cmap, cmapframe);
00388
00389
00390 tim.nextFrame();
00391 while(seq->now() < masterclock.getSimTime()) seq->evolve();
00392
00393 uint64 t5 = timer.get();
00394 LINFO("time5[%d]: %f", fNum, (t5-t4)/1000.0F);
00395
00396 fNum++;
00397 }
00398
00399
00400
00401
00402
00403 double time = (tim.getElapsedTime()).sec();
00404 double frate = TOTAL_FRAMES/time;
00405 LINFO("[%6d]: %15.6fsec: %6.3f fps -> %8.3f ms/f\n",
00406 fNum, time, frate, 1000/frate);
00407
00408 LINFO("Normal exit");
00409 manager.stop();
00410 #endif
00411 return 0;
00412 }
00413
00414
00415 void receiveCMAPS(nub::soft_ref<Beowulf>& beo, Image<float> *cmap,
00416 int32 *cmapframe)
00417 {
00418 TCPmessage rmsg;
00419 int32 rframe, raction, rnode = -1, recnb=0;
00420 while(beo->receive(rnode, rmsg, rframe, raction))
00421 {
00422 nCMAPSreceived++;
00423 LINFO("--------------> nCMAPSreceived: %6d", nCMAPSreceived);
00424
00425
00426 switch(raction & 0xffff)
00427 {
00428 case BEO_CMAP:
00429 {
00430
00431 Image<float> ima = rmsg.getElementFloatIma();
00432
00433
00434
00435 int32 mapn = raction >> 16;
00436 if (mapn < 0 || mapn >= NBCMAP4) {
00437 LERROR("Bogus cmap number ignored");
00438 break;
00439 }
00440
00441
00442
00443
00444
00445 if (cmapframe[mapn] < rframe)
00446 { cmap[mapn] = ima; cmapframe[mapn] = rframe; }
00447 }
00448
00449 break;
00450 default:
00451 LERROR("Bogus action %d -- IGNORING.", raction);
00452 break;
00453 }
00454
00455 recnb ++; if (recnb > NBCMAP4 * 2) break;
00456 }
00457 }
00458
00459
00460 extern "C" int main(int argc, char** argv)
00461 {
00462 try
00463 {
00464 return submain(argc, argv);
00465 }
00466 catch (...)
00467 {
00468 REPORT_CURRENT_EXCEPTION;
00469 return 1;
00470 }
00471 return 0;
00472 }
00473
00474
00475
00476
00477
00478