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 "Beobot/BeobotVisualCortex.H"
00039 #include "GUI/XWindow.H"
00040 #include "Image/ColorOps.H"
00041 #include "Image/CutPaste.H"
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Image/fancynorm.H"
00045 #include "Raster/Raster.H"
00046
00047 #include <iostream>
00048 #include <cstdio>
00049
00050
00051
00052 #define NBNEIGH 24
00053
00054
00055 int main(const int argc, const char **argv)
00056 {
00057 initRandomNumbers();
00058
00059 int sml = 4;
00060 int delta_min = 3, delta_max = 4;
00061 int level_min = 2, level_max = 4;
00062 int nborient = 4;
00063 int jdepth = 3;
00064 int frame, initFrame; char imageNameBase[100]; int outframe = 0;
00065 bool pause, writeframes, firstFrame = true;
00066
00067 if (argc >= 2) strcpy(imageNameBase, argv[1]);
00068 else LFATAL("USAGE: test-Jet <path> [initFrame] [pause] [writeframes]");
00069 if (imageNameBase[strlen(imageNameBase) - 1] != '/')
00070 strcat(imageNameBase, "/");
00071 if (argc >= 3) initFrame = atoi(argv[2]); else initFrame = 0;
00072 if (argc >= 4) pause = atoi(argv[3]) != 0; else pause = false;
00073 if (argc >= 5) writeframes = atoi(argv[4]) != 0; else writeframes = false;
00074
00075
00076 Image< PixRGB<byte> > col_image =
00077 Raster::ReadRGB(sformat("%sframe%06d.ppm", imageNameBase, initFrame));
00078
00079 XWindow xwindow(Dims(col_image.getWidth() * 3, col_image.getHeight() * 2),
00080 -1, -1, "Visual Scene Clustering");
00081 Image< PixRGB<byte> > disp(col_image.getWidth() * 3,
00082 col_image.getHeight() * 2, ZEROS);
00083
00084 Point2D<int> centroid(col_image.getWidth() / (1 << (sml + 1)),
00085 col_image.getHeight() / (1 << sml) - 2);
00086 Point2D<int> prevcentroid(centroid);
00087
00088
00089 BeobotVisualCortex visualCX;
00090 visualCX.init(col_image.getWidth(), col_image.getHeight(),
00091 level_min, level_max, delta_min, delta_max,
00092 sml, nborient, VCXNORM_DEFAULT, sml, jdepth, NBNEIGH,
00093 nub::soft_ref<Beowulf>());
00094
00095 for (frame = initFrame; ; frame++)
00096 {
00097 col_image = Raster::ReadRGB(sformat("%sframe%06d.ppm", imageNameBase, frame));
00098 inplacePaste(disp, col_image, Point2D<int>(0, 0));
00099
00100 visualCX.newVisualInput(col_image);
00101 visualCX.process(frame);
00102 visualCX.initSprings(firstFrame);
00103
00104 Image< PixRGB<byte> > deformedImage;
00105
00106 const float dt = 0.1;
00107 int nbIter; if (firstFrame) nbIter = 5 ; else nbIter = 5;
00108
00109 for(int t = 0; t < nbIter; t++)
00110 {
00111
00112 visualCX.iterateSprings(dt);
00113
00114 Image< PixRGB<byte> > img;
00115 visualCX.getPositions(img, 1 << (sml+1));
00116 inplacePaste(disp, img, Point2D<int>(col_image.getWidth(), 0));
00117
00118
00119 visualCX.getClusteredImage(deformedImage, centroid, prevcentroid);
00120 prevcentroid = centroid;
00121 inplacePaste(disp, deformedImage, Point2D<int>(0, col_image.getHeight()));
00122
00123
00124 xwindow.drawImage(disp);
00125
00126
00127 if (writeframes) Raster::WriteRGB(disp, sformat("T%06d.ppm", outframe ++));
00128
00129 if (pause)
00130 {
00131 std::cout<<"<<<<< Press [RETURN] to continue >>>>>"<<std::endl;
00132 getchar();
00133 }
00134 }
00135 firstFrame = false;
00136 }
00137 return 0;
00138 }
00139
00140
00141
00142
00143
00144