test-BeoSubTaskDecoder.C
Go to the documentation of this file.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 #ifndef TESTBEOSUBTASKDECODER_H_DEFINED
00039 #define TESTBEOSUBTASKDECODER_H_DEFINED
00040
00041
00042 #include "Component/ModelManager.H"
00043
00044 #include "Media/FrameSeries.H"
00045 #include "Transport/FrameIstream.H"
00046 #include "Media/MediaOpts.H"
00047
00048 #include "Image/Image.H"
00049 #include "Image/Pixels.H"
00050 #include "Raster/Raster.H"
00051
00052 #include "GUI/XWinManaged.H"
00053
00054 #include "BeoSub/BeoSubTaskDecoder.H"
00055
00056 #include "Image/ImageSet.H"
00057 #include "Util/Timer.H"
00058 #include "Util/Types.H"
00059 #include "Util/log.H"
00060
00061 #include <string>
00062
00063 #define NAVG 20
00064
00065 int main(int argc, char **argv)
00066 {
00067
00068 ModelManager manager("Frame Grabber Tester");
00069
00070
00071 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00072 manager.addSubComponent(ifs);
00073
00074 nub::soft_ref<BeoSubTaskDecoder> test(new BeoSubTaskDecoder(manager));
00075 manager.addSubComponent(test);
00076
00077 manager.exportOptions(MC_RECURSE);
00078
00079
00080 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00081
00082
00083 int w = ifs->getWidth(), h = ifs->getHeight();
00084 std::string dims = convertToString(Dims(w, h));
00085 LINFO("image size: [%dx%d]", w, h);
00086 manager.setOptionValString(&OPT_InputFrameDims, dims);
00087 manager.setModelParamVal("InputFrameDims", Dims(w, h),
00088 MC_RECURSE | MC_IGNORE_MISSING);
00089
00090
00091 manager.start();
00092
00093
00094 rutz::shared_ptr<XWinManaged> win(new XWinManaged(Dims(w,h), 200, 200, "input window"));
00095 Timer tim; uint64 t[NAVG]; int frame = 0;
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 float avg2 = 0.0;
00126
00127 Image< PixRGB<byte> > img;
00128
00129 bool goforever = true;
00130 while(goforever){
00131
00132 ImageSet< PixRGB<byte> > input;
00133 for(int i = 0; i < 100; i++){
00134 tim.reset();
00135
00136 ifs->updateNext(); img = ifs->readRGB();
00137 if(!img.initialized()) break;
00138 win->drawImage(img,0,0);
00139 input.push_back(img);
00140
00141 char buf[32];
00142 sprintf(buf, "image%d.ppm", i);
00143 Raster::WriteRGB(img, buf);
00144
00145 uint64 t0 = tim.get();
00146 t[frame % NAVG] = tim.get();
00147 t0 = t[frame % NAVG] - t0;
00148
00149 if (frame % NAVG == 0 && frame > 0)
00150 {
00151 uint64 avg = 0ULL; for (int i = 0; i < NAVG; i ++) avg += t[i];
00152 avg2 = 1000.0F / float(avg) * float(NAVG);
00153 }
00154 frame ++;
00155 }
00156
00157 LINFO("fps: %f", avg2);
00158 test->setupDecoder("Red", true);
00159 test->runDecoder(input, avg2);
00160 float hertz = test->calculateHz();
00161
00162 printf("\n\nFinal hertz calculated is: %f\n\n", hertz);
00163 Raster::waitForKey();
00164 }
00165
00166 manager.stop();
00167 return 0;
00168 }
00169
00170 #endif
00171
00172
00173
00174
00175