
00001 /*!@file Transport/FrameIstream.H */ 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/Transport/FrameIstream.H $ 00035 // $Id: FrameIstream.H 10353 2008-10-15 23:05:53Z ilab24 $ 00036 // 00037 00038 #ifndef TRANSPORT_FRAMEISTREAM_H_DEFINED 00039 #define TRANSPORT_FRAMEISTREAM_H_DEFINED 00040 00041 #include "Component/ModelComponent.H" 00042 #include "Util/Types.H" // for byte 00043 00044 class Dims; 00045 class GenericFrame; 00046 class GenericFrameSpec; 00047 class SimTime; 00048 template <class T> class Image; 00049 template <class T> class PixRGB; 00050 00051 // ###################################################################### 00052 /// Listener class that can get called each time a FrameIstream grabs a frame 00053 /** Different FrameIstream subclasses may use their FrameListener 00054 differently, or possibly even ignore the FrameListener. */ 00055 class FrameListener 00056 { 00057 public: 00058 virtual ~FrameListener(); 00059 00060 virtual void onRawFrame(const GenericFrame& frame) = 0; 00061 }; 00062 00063 //! Abstract interface class representing a source of Image frames 00064 /*! Concrete classes might implement this interface so that the real 00065 source is a series of bitmap files (RasterInputSeries), or a movie 00066 file (InputMPEGSeries), or an external device (V4Lgrabber, 00067 IEEE1394grabber). 00068 00069 See also FrameOstream for the analogous output interface. */ 00070 class FrameIstream : public ModelComponent 00071 { 00072 public: 00073 //! Constructor 00074 FrameIstream(OptionManager& mgr, 00075 const std::string& descrName, 00076 const std::string& tagName); 00077 00078 //! Virtual destructor 00079 virtual ~FrameIstream(); 00080 00081 //! Configure the FrameIstream object in a type-dependent manner 00082 /*! The string is expected to be some piece of user input (e.g. from 00083 the command-line) specifying key information for the 00084 FrameIstream (e.g., the filename for an input movie). 00085 00086 The default implementation does nothing; derived classes can 00087 override if they need to receive such user input. 00088 */ 00089 virtual void setConfigInfo(const std::string& cfg); 00090 00091 /// Install a FrameListener; default implementation does nothing 00092 /** Subclasses may override this method if they want to actually 00093 pass some information to the listener. */ 00094 virtual void setListener(rutz::shared_ptr<FrameListener> listener); 00095 00096 //! Advise the FrameIstream object of the current frame number 00097 /*! NOTE: the default implementation does nothing -- it just ignores 00098 the frame number. This is allowed for subclasses, too, since for 00099 certain input formats (e.g., framegrabbers) it doesn't make any 00100 sense to specify a frame number, since the format doesn't 00101 support random-access reading. On the other hand, certain 00102 subclasses require a frame number to function properly (e.g., 00103 for writing a series of consecutively-numbered raster 00104 files). So, the bottom line is: clients of FrameIstream must be 00105 sure to call setFrameNumber(), but should make no assumptions 00106 about what it will actually do. 00107 00108 @return Whether the frame number was succesfully set as 00109 requested. The function may fail, for instance, in the case of 00110 an input source like a movie file that has only a limited number 00111 of frames. 00112 */ 00113 virtual bool setFrameNumber(int n); 00114 00115 //! Return the specifications of the next frame 00116 /*! Subclasses may have to load the next frame in order to peek at 00117 the dimensions, then cache that frame and return it the next 00118 time readRGB(), readGray(), or readFloat() is called. */ 00119 virtual GenericFrameSpec peekFrameSpec() = 0; 00120 00121 //! Get the natural inter-frame time for this frame source 00122 /*! A return value of 0 means that there is no particular natural 00123 inter-frame time; the default implementation returns 0 so 00124 subclasses should override if they need to specify a different 00125 inter-frame time. 00126 00127 This information should be treated as advisory only; for 00128 instance, callers might use this information to try to display 00129 frames to the user at the "natural" framerate. 00130 */ 00131 virtual SimTime getNaturalFrameTime() const; 00132 00133 //! Convenience function to get the frame dims from peekFrameSpec() 00134 Dims peekDims(); 00135 00136 //! Convenience function to get the frame width from peekFrameSpec() 00137 int getWidth(); 00138 00139 //! Convenience function to get the frame height from peekFrameSpec() 00140 int getHeight(); 00141 00142 //! Optional call to efficiently prepare for frame streaming 00143 /*! Some FrameIstream subclasses may require some preparatory work 00144 before they can start returning image frames, and this function 00145 lets that work be done outside of the application's main 00146 frame-reading loop. 00147 00148 A good example of this is streaming-mode frame-grabbers, such as 00149 the video4linux driver. To use that driver in streaming mode, 00150 each of the internal frame buffers must be started, but they 00151 shouldn't be started "too soon" either; so, it's best to call 00152 startStream() just before the main loops starts calling 00153 readFrame() (or readRGB(), etc.). 00154 00155 Subclass authors should design their classes so that readFrame() 00156 always "just works", regardless of whether the user has called 00157 startStream() or not, typically by keeping a flag to mark 00158 whether startStream() has been called, and then calling 00159 startStream() from within the first readFrame() call, if 00160 needed. 00161 00162 The default implementation of startStream() is a no-op. 00163 */ 00164 virtual void startStream(); 00165 00166 //! Read a frame from the input source 00167 /*! The actual input source could be a raster file, a movie file, or 00168 some external device, etc., depending on the concrete subclass. */ 00169 virtual GenericFrame readFrame() = 0; 00170 00171 //! Read an image from the input source 00172 /*! The actual input source could be a raster file, a movie file, or 00173 some external device, etc., depending on the concrete subclass. 00174 00175 The default implementation just returns readFrame().asRgb(). */ 00176 virtual Image<PixRGB<byte> > readRGB(); 00177 00178 //! the specific 12 bit depth (actually any uint16 data type) implemtation 00179 //! return from readFrame().asRgb16(). 00180 virtual Image<PixRGB<uint16> > readRGBU16(); 00181 00182 //! Read an image from the input source 00183 /*! The actual input source could be a raster file, a movie file, or 00184 some external device, etc., depending on the concrete subclass. 00185 00186 The default implementation just returns readFrame().asGray(). */ 00187 virtual Image<byte> readGray(); 00188 00189 //! the specific 12 bit depth (actually any uint16 data type) implemtation 00190 //! return from readFrame().asRgb16(). 00191 virtual Image<uint16> readGrayU16(); 00192 00193 //! Read an image from the input source 00194 /*! The actual input source could be a raster file, a movie file, or 00195 some external device, etc., depending on the concrete subclass. 00196 00197 The default implementation just returns readFrame().asFloat(). */ 00198 virtual Image<float> readFloat(); 00199 00200 //! Read a frame from the stream and discard it 00201 /*! Subclasses may be able to implement this function more 00202 efficiently than the other functions that actually return an 00203 Image object (since they might avoid converting from some raw 00204 representation to Image). So, if you know you are going to 00205 discard the frame (e.g. to skip ahead to a certain frame number, 00206 or to count the frame), then it is more efficient to call 00207 readAndDiscardFrame() than to call readVideoFrame() or readRGB() 00208 but ignore the result. 00209 00210 The return value will be true if a frame was actually read, or 00211 false if no frame was found (e.g., end-of-stream was reached). 00212 00213 The default implementation just calls readRGB() but ignores the 00214 result. 00215 */ 00216 virtual bool readAndDiscardFrame(); 00217 }; 00218 00219 // ###################################################################### 00220 /* So things look consistent in everyone's emacs... */ 00221 /* Local Variables: */ 00222 /* indent-tabs-mode: nil */ 00223 /* End: */ 00224 00225 #endif // TRANSPORT_FRAMEISTREAM_H_DEFINED
1.4.4