Homepage Demos Overview Downloads Tutorials Reference
Credits

RawCameraGenerator.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_RawCameraGenerator_h_
00003 #define INCLUDED_RawCameraGenerator_h_
00004 
00005 #include "Vision/FilterBankGenerator.h"
00006 
00007 class OFbkImageVectorData;
00008 class OFbkImageInfo;
00009 
00010 //! Generates FilterBankEvents containing raw camera images directly from the system (doesn't make a copy)
00011 class RawCameraGenerator : public FilterBankGenerator {
00012 public:
00013   //! constructor, numRawLayers is the number of real layers passed from the system, numCalcLayers is the total number of layers to make available
00014   /*! The extra calculated layers are simply created by giving larger
00015    *  increments, they reference the same data (no computational cost,
00016    *  marginal memory costs... it's just nice to have more layers in
00017    *  the image pyramid.
00018    *  
00019    *  However you'll have to write your code to use the getIncrement()
00020    *  value properly if you want it to work.  Otherwise, you could
00021    *  write a de-interlace generator which will do the resampling.
00022    *
00023    *  The top most layer (largest index) is a double-scale image.  For
00024    *  the Y-channel, it is reconstructed from the 4 Y channels.  For
00025    *  the other channels, it just does a fast scaling (but these
00026    *  operations do cost, so use the top layer conservatively.
00027    *
00028    *  @see FilterBankGenerator for information on serialization format
00029    */
00030   RawCameraGenerator(unsigned int numRawLayers, unsigned int numCalcLayers, EventBase::EventGeneratorID_t gid, unsigned int sid, unsigned int mysid);
00031 
00032   //! destructor
00033   virtual ~RawCameraGenerator();
00034 
00035   static std::string getClassDescription() { return "Translates OFbkImageVectorData objects from the system into a slightly more accessible FilterBankEvent for further processing"; }
00036 
00037   //! holds id values for specifying image channel/bands
00038   enum channel_id_t {
00039     CHAN_Y,      //!< Y (intensity) channel
00040     CHAN_U,      //!< Cr (approx. pink,red,yellow) channel
00041     CHAN_V,      //!< Cb (approx. blue,green,yellow) channel
00042     CHAN_Y_DY,   //!< vertical derivative of Y channel (aka LH)
00043     CHAN_Y_DX,   //!< horizontal derivative of Y channel (aka HL)
00044     CHAN_Y_DXDY, //!< vert. & horiz. derivatives of Y channel (aka HH)
00045     NUM_CHANNELS //!< number of channels per resolution layer
00046   };
00047 
00048   //! called with system's image info
00049   virtual void processEvent(const EventBase& event);
00050   
00051   //! the memory for all layers except the double layer was allocated by system, so we just set them to NULL before calling FilterBankGenerator::freeCaches() so it won't try to delete them
00052   virtual void freeCaches();
00053 
00054   virtual unsigned int getBinSize() const;
00055 
00056   virtual unsigned int LoadBuffer(const char buf[], unsigned int len);
00057 
00058   virtual unsigned int SaveBuffer(char buf[], unsigned int len) const;
00059 
00060   virtual unsigned int SaveFileStream(FILE* f) const; //!< overrridden to allow saving direct to file without an extra buffer copy
00061 
00062 protected:
00063   //! ohh, this is so yucky.  But we need to get around heap allocation bugs with large regions in Aperios :(
00064   /*! So we store the double size images statically within the class.
00065    *  What a waste of memory since we're probably not using these very
00066    *  much, and they are rather large... :(
00067    * 
00068    *  The 2.0 release had the proper dynamic allocation
00069    *  implementation, but has been replaced in 2.0.1 with this static
00070    *  allocation so it won't crash.
00071    *
00072    *  Of course, if the memory allocation bug is never fixed, and
00073    *  camera sizes increase in later models, this will have to be
00074    *  modified. */
00075   unsigned char dblRes[NUM_CHANNELS][416][320]; 
00076 
00077   virtual void setNumImages(unsigned int nLayers, unsigned int nChannels);
00078 
00079   virtual void setDimensions(); //!< resets the width, height, skip and stride values
00080   virtual unsigned char * createImageCache(unsigned int layer, unsigned int chan) const;
00081   virtual void calcImage(unsigned int layer, unsigned int chan) const;
00082   virtual void destruct();
00083 
00084   //! returns the value to pass to OPENR functions corresponding to the desired channel_id_t.
00085   inline static unsigned int mapChannelID(channel_id_t chan);
00086 
00087   //! Creates a double resolution version of a channel, doesn't do any smoothing
00088   void upsampleImage(channel_id_t chan) const;
00089 
00090   //! Creates a double resolution Y-channel from the Y and Y gradient channels
00091   void reconstructImage() const;
00092 
00093   //! helper functions for reconstructImage() - see documentation for that function
00094   static inline unsigned char clipRange(int val) {
00095     if (val < 0)        { return 0;         }
00096     else if (val > 255) { return 255;       }
00097     else                { return (unsigned char)val; }
00098   }
00099 
00100   unsigned int numRealLayers; //!< the number of "real" layers being sent from the system
00101 
00102   unsigned char ** layers; //!< points to the image data supplied by the system, one per layer (all channels are interleaved by row)
00103   const OFbkImageInfo ** imageInfos; //!< image info provided by the system
00104 
00105 private:
00106   RawCameraGenerator(const RawCameraGenerator& fbk); //!< don't call
00107   const RawCameraGenerator& operator=(const RawCameraGenerator& fbk); //!< don't call
00108 };
00109 
00110 /*! @file 
00111  * @brief Describes RawCameraGenerator, which generates FilterBankEvents containing raw camera images
00112  * @author ejt (Creator)
00113  *
00114  * $Author: ejt $
00115  * $Name: tekkotsu-2_0_1+Doc $
00116  * $Revision: 1.13 $
00117  * $State: Exp $
00118  * $Date: 2004/02/05 23:33:48 $
00119  */
00120 
00121 #endif

Tekkotsu v2.0.1+Doc
Generated Mon Feb 9 22:16:50 2004 by Doxygen 1.3.5