extractframes.C
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 "Image/ColorOps.H"
00040 #include "Image/CutPaste.H"
00041 #include "Image/DrawOps.H"
00042 #include "Image/FilterOps.H"
00043 #include "Image/Image.H"
00044 #include "Image/ImageSet.H"
00045 #include "Image/Layout.H"
00046 #include "Image/MathOps.H"
00047 #include "Image/Pixels.H"
00048 #include "Image/PyramidOps.H"
00049 #include "Image/ShapeOps.H"
00050 #include "Image/Transforms.H"
00051 #include "Media/FrameSeries.H"
00052 #include "Media/MediaOpts.H"
00053 #include "Raster/GenericFrame.H"
00054 #include "Raster/Raster.H"
00055 #include "Transport/FrameInfo.H"
00056 #include "Transport/TransportOpts.H"
00057 #include "Util/csignals.H"
00058 #include "rutz/shared_ptr.h"
00059 #include "rutz/trace.h"
00060 #include "rutz/rand.h"
00061
00062 #include "CUDA/CudaSaliency.H"
00063
00064 #include <ctype.h>
00065 #include <deque>
00066 #include <iterator>
00067 #include <limits>
00068 #include <stdlib.h>
00069 #include <string.h>
00070 #include <sys/resource.h>
00071 #include <signal.h>
00072 #include <time.h>
00073 #include <vector>
00074
00075
00076
00077
00078 int submain(int argc, const char** argv)
00079 {
00080 volatile int signum = 0;
00081 signal(SIGPIPE, SIG_IGN);
00082 catchsignals(&signum);
00083
00084
00085
00086 ModelManager manager("Nv2");
00087
00088 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00089 manager.addSubComponent(ifs);
00090
00091
00092 if (manager.parseCommandLine((const int)argc, (const char**)argv, "<sampleimagesdir>", 1, 1) == false)
00093 return 1;
00094
00095 manager.exportOptions(MC_RECURSE);
00096
00097 manager.start();
00098
00099 std::string sampleImagesDir;
00100
00101 sampleImagesDir = manager.getExtraArg(0);
00102
00103
00104 int retval = 0;
00105 ifs->startStream();
00106 const GenericFrameSpec fspec = ifs->peekFrameSpec();
00107
00108
00109
00110 rutz::urand r(0);
00111
00112 int curPickedFrame=0;
00113
00114 while (true)
00115 {
00116 if (signum != 0) {
00117 LINFO("quitting because %s was caught", signame(signum));
00118 retval = -1;
00119 break;
00120 }
00121
00122
00123
00124
00125 const FrameState is = ifs->updateNext();
00126 if (is == FRAME_COMPLETE) break;
00127
00128
00129 int willPick = r.idraw(100);
00130
00131 if(willPick==0)
00132 {
00133
00134 GenericFrame input = ifs->readFrame();
00135 if (!input.initialized()) break;
00136
00137 const Image<PixRGB<byte> > rgbin = input.asRgb();
00138
00139 char fname[200];
00140 sprintf(fname,"%s/Frame-%d.png",sampleImagesDir.c_str(),curPickedFrame);
00141 Raster::WriteRGB(rgbin,fname);
00142 curPickedFrame++;
00143 }
00144 }
00145
00146 manager.stop();
00147 return retval;
00148 }
00149
00150
00151 int main(int argc, const char** argv)
00152 {
00153 try {
00154 return submain(argc, argv);
00155 } catch (...) {
00156 REPORT_CURRENT_EXCEPTION;
00157 }
00158 }
00159
00160
00161
00162
00163
00164
00165