00001 /*!@file AppMedia/app-thumbnail-movies.C Make a "moving thumbnail" array from a set of movies */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/app-thumbnail-movies.C $ 00035 // $Id: app-thumbnail-movies.C 10214 2008-09-06 00:34:20Z dberg $ 00036 // 00037 00038 #ifndef APPMEDIA_APP_THUMBNAIL_MOVIES_C_DEFINED 00039 #define APPMEDIA_APP_THUMBNAIL_MOVIES_C_DEFINED 00040 00041 #include "Component/ModelManager.H" 00042 #include "Image/FilterOps.H" 00043 #include "Image/Image.H" 00044 #include "Image/Pixels.H" 00045 #include "Image/ShapeOps.H" 00046 #include "Media/MpegInputStream.H" 00047 #include "Media/FrameSeries.H" 00048 #include "Transport/FrameInfo.H" 00049 #include "Util/csignals.H" 00050 #include "Util/sformat.H" 00051 #include "rutz/trace.h" 00052 00053 #include <cmath> 00054 #include <vector> 00055 00056 int submain(int argc, const char** argv) 00057 { 00058 GVX_TRACE(__PRETTY_FUNCTION__); 00059 00060 volatile int signum = 0; 00061 catchsignals(&signum); 00062 00063 ModelManager mgr("movie thumbnailer"); 00064 00065 nub::ref<InputMPEGStream> indummy(new InputMPEGStream(mgr)); 00066 mgr.addSubComponent(indummy); 00067 00068 nub::ref<OutputFrameSeries> out(new OutputFrameSeries(mgr)); 00069 mgr.addSubComponent(out); 00070 00071 if (mgr.parseCommandLine(argc, argv, "nskipframes movie1.mpg movie2.mpg ...", 00072 2, -1) == false) 00073 exit(1); 00074 00075 std::vector<nub::ref<InputMPEGStream> > inputs; 00076 00077 const int nskipframes = mgr.getExtraArgAs<int>(0); 00078 00079 LINFO("got nskipframes=%d", nskipframes); 00080 00081 for (uint i = 1; i < mgr.numExtraArgs(); ++i) 00082 { 00083 inputs.push_back(nub::ref<InputMPEGStream>(new InputMPEGStream(mgr))); 00084 mgr.addSubComponent(inputs.back()); 00085 inputs.back()->setFileName(mgr.getExtraArg(i)); 00086 } 00087 00088 mgr.exportOptions(MC_RECURSE); 00089 mgr.start(); 00090 00091 std::vector<Image<PixRGB<byte> > > images(inputs.size()); 00092 00093 const int nx = int(ceil(sqrt(inputs.size()))); 00094 00095 for (int sk = 0; sk < nskipframes; ++sk) 00096 { 00097 if (signum != 0) 00098 { 00099 LINFO("quitting because %s was caught", signame(signum)); 00100 return -1; 00101 } 00102 00103 LINFO("skipping input frame %d", sk); 00104 00105 bool done = false; 00106 00107 for (uint i = 0; i < inputs.size(); ++i) 00108 { 00109 if (!inputs[i]->readAndDiscardFrame()) 00110 { 00111 LINFO("quitting because %s reached EOF", 00112 mgr.getExtraArg(i).c_str()); 00113 done = true; 00114 } 00115 } 00116 00117 if (done) 00118 break; 00119 } 00120 00121 while (1) 00122 { 00123 if (signum != 0) 00124 { 00125 LINFO("quitting because %s was caught", signame(signum)); 00126 return -1; 00127 } 00128 00129 bool done = false; 00130 00131 for (uint i = 0; i < inputs.size(); ++i) 00132 { 00133 images[i] = inputs[i]->readRGB(); 00134 if (!images[i].initialized()) 00135 { 00136 LINFO("quitting because %s reached EOF", 00137 mgr.getExtraArg(i).c_str()); 00138 done = true; 00139 } 00140 else 00141 images[i] = decXY(lowPass3(images[i])); 00142 } 00143 00144 if (done) 00145 break; 00146 00147 const Image<PixRGB<byte> > thumb = 00148 concatArray(&images[0], images.size(), nx); 00149 00150 const FrameState os = out->updateNext(); 00151 00152 out->writeRGB(thumb, "thumbnail", 00153 FrameInfo(sformat("array of %"ZU" movies", 00154 inputs.size()), SRC_POS)); 00155 00156 if (os == FRAME_FINAL) 00157 { 00158 LINFO("quitting because output reached EOF"); 00159 break; 00160 } 00161 } 00162 00163 return 0; 00164 } 00165 00166 int main(const int argc, const char **argv) 00167 { 00168 try 00169 { 00170 return submain(argc, argv); 00171 } 00172 catch (...) 00173 { 00174 REPORT_CURRENT_EXCEPTION; 00175 } 00176 00177 return 1; 00178 } 00179 00180 // ###################################################################### 00181 /* So things look consistent in everyone's emacs... */ 00182 /* Local Variables: */ 00183 /* mode: c++ */ 00184 /* indent-tabs-mode: nil */ 00185 /* End: */ 00186 00187 #endif // APPMEDIA_APP_THUMBNAIL_MOVIES_C_DEFINED