test-motion.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 #include "Component/ModelManager.H"
00039 #include "Component/OptionManager.H"
00040 #include "Devices/FrameGrabberConfigurator.H"
00041 #include "Image/ColorOps.H"
00042 #include "Image/CutPaste.H"
00043 #include "Image/DrawOps.H"
00044 #include "Image/FilterOps.H"
00045 #include "Image/Image.H"
00046 #include "Image/Layout.H"
00047 #include "Image/MathOps.H"
00048 #include "Image/Pixels.H"
00049 #include "Image/ShapeOps.H"
00050 #include "Image/SimpleFont.H"
00051 #include "Media/FrameSeries.H"
00052 #include "RCBot/Motion/MotionEnergy.H"
00053 #include "Raster/Raster.H"
00054 #include "Transport/FrameInfo.H"
00055 #include "Util/Pause.H"
00056 #include "Util/Timer.H"
00057 #include "Util/Types.H"
00058 #include "Util/csignals.H"
00059 #include "Util/log.H"
00060 #include <math.h>
00061
00062
00063 int main(const int argc, const char **argv)
00064 {
00065 MYLOGVERB = LOG_INFO;
00066
00067 volatile int signum = 0;
00068 catchsignals(&signum);
00069
00070 ModelManager manager("Test Motion Energy");
00071
00072 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00073 manager.addSubComponent(ifs);
00074
00075 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00076 manager.addSubComponent(ofs);
00077
00078 if (manager.parseCommandLine((const int)argc, (const char**)argv,
00079 "?pyrlevel=0? ?magthresh=1500?", 0, 2) == false)
00080 return(1);
00081
00082 const int pyrlevel =
00083 manager.numExtraArgs() > 0
00084 ? manager.getExtraArgAs<int>(0)
00085 : 0;
00086
00087 const float magthresh =
00088 manager.numExtraArgs() > 1
00089 ? manager.getExtraArgAs<float>(1)
00090 : 1500.0f;
00091
00092 manager.start();
00093
00094 Timer timer(1000000);
00095 timer.reset();
00096 int frame = 0;
00097
00098 MotionEnergyPyrBuilder<byte> motionPyr(Gaussian5, 0.0f, 10.0f, 5,
00099 magthresh);
00100
00101 PauseWaiter p;
00102
00103 while (1)
00104 {
00105 if (signum != 0)
00106 {
00107 LINFO("quitting because %s was caught", signame(signum));
00108 break;
00109 }
00110
00111 if (ofs->becameVoid())
00112 {
00113 LINFO("quitting because output stream was closed or became void");
00114 break;
00115 }
00116
00117 if (p.checkPause())
00118 continue;
00119
00120 const FrameState is = ifs->updateNext();
00121 if (is == FRAME_COMPLETE) break;
00122
00123 Image< PixRGB<byte> > input = ifs->readRGB();
00124
00125 if (!input.initialized()) break;
00126 Image<byte> lum = luminance(input);
00127
00128 motionPyr.updateMotion(lum, pyrlevel+1);
00129
00130 Image<float> vMotion = motionPyr.buildVerticalMotionLevel(pyrlevel);
00131 Image<float> hMotion = motionPyr.buildHorizontalMotionLevel(pyrlevel);
00132
00133 Image<float> quad = median3(quadEnergy(vMotion, hMotion));
00134 inplaceNormalize(quad, 0.0F, 255.0F);
00135
00136 inplaceNormalize(vMotion, 0.0F, 255.0F);
00137 inplaceNormalize(hMotion, 0.0F, 255.0F);
00138
00139 Image<byte> vimg = vMotion;
00140 writeText(vimg, Point2D<int>(1,1), "Vertical Motion", byte(0), byte(255),
00141 SimpleFont::fixedMaxWidth(8));
00142
00143 Image<byte> himg = hMotion;
00144 writeText(himg, Point2D<int>(1,1), "Horizontal Motion", byte(0), byte(255),
00145 SimpleFont::fixedMaxWidth(8));
00146
00147 const FrameState os = ofs->updateNext();
00148
00149 const Layout<byte> disp = vcat(hcat(lum, Image<byte>(quad)), hcat(himg, vimg));
00150
00151 ofs->writeGrayLayout(disp, "motion-energy",
00152 FrameInfo("motion energy output images", SRC_POS));
00153
00154 if (os == FRAME_FINAL)
00155 break;
00156
00157 frame++;
00158 }
00159
00160 LINFO("%d frames in %gs (%.2ffps)\n", frame, timer.getSecs(), frame / timer.getSecs());
00161
00162
00163 manager.stop();
00164
00165
00166 return 0;
00167
00168 }
00169
00170
00171
00172
00173
00174