Homepage
Demos
Overview
Downloads
Dev. Resources
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 #include "Shared/RobotInfo.h"
00007 
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, unsigned int mysid, EventBase::EventGeneratorID_t gid, unsigned int sid);
00031 
00032   //! destructor
00033   virtual ~RawCameraGenerator() {
00034     freeCaches();
00035     destruct();
00036   }
00037 
00038   static std::string getClassDescription() { return "Translates OFbkImageVectorData objects from the system into a slightly more accessible FilterBankEvent for further processing"; }
00039 
00040   //! holds id values for specifying image channel/bands
00041   enum channel_id_t {
00042     CHAN_Y,      //!< Y (intensity) channel
00043     CHAN_U,      //!< Cr (approx. pink,red,yellow) channel
00044     CHAN_V,      //!< Cb (approx. blue,green,yellow) channel
00045     CHAN_Y_DY,   //!< vertical derivative of Y channel (aka LH)
00046     CHAN_Y_DX,   //!< horizontal derivative of Y channel (aka HL)
00047     CHAN_Y_DXDY, //!< vert. & horiz. derivatives of Y channel (aka HH)
00048     NUM_CHANNELS //!< number of channels per resolution layer
00049   };
00050 
00051   //! need to override EventGeneratorBase's lazy listening -- as a root stage, need to remember each frame, just in case it might be used
00052   virtual void DoStart() { FilterBankGenerator::DoStart(); addSrcListener(); }
00053 
00054   //! called with system's image info
00055   virtual void processEvent(const EventBase& event);
00056   
00057   //! 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
00058   virtual void freeCaches();
00059 
00060   virtual unsigned int getBinSize() const;
00061 
00062   virtual unsigned int LoadBuffer(const char buf[], unsigned int len);
00063 
00064   virtual unsigned int SaveBuffer(char buf[], unsigned int len) const;
00065 
00066   virtual unsigned int SaveFileStream(FILE* f) const; //!< overrridden to allow saving direct to file without an extra buffer copy
00067 
00068 protected:
00069   //! ohh, this is so yucky.  But we need to get around heap allocation bugs with large regions in Aperios :(
00070   /*! So we store the double size images statically within the class.
00071    *  What a waste of memory since we're probably not using these very
00072    *  much, and they are rather large... :(
00073    * 
00074    *  The 2.0 release had the proper dynamic allocation
00075    *  implementation, but has been replaced in 2.0.1 with this static
00076    *  allocation so it won't crash.*/
00077   unsigned char dblRes[NUM_CHANNELS][CameraResolutionX*2][CameraResolutionY*2]; 
00078 
00079   virtual void setNumImages(unsigned int nLayers, unsigned int nChannels);
00080 
00081   virtual void setDimensions(); //!< resets the width, height, skip and stride values
00082   virtual unsigned char * createImageCache(unsigned int layer, unsigned int chan) const;
00083   virtual void calcImage(unsigned int layer, unsigned int chan);
00084   virtual void destruct();
00085 
00086   //! returns the value to pass to OPENR functions corresponding to the desired channel_id_t.
00087   inline static unsigned int mapChannelID(channel_id_t chan);
00088 
00089   //! Creates a double resolution version of a channel, doesn't do any smoothing
00090   void upsampleImage(channel_id_t chan);
00091 
00092   //! Creates a double resolution Y-channel from the Y and Y gradient channels
00093   void reconstructImage();
00094 
00095   //! helper functions for reconstructImage() - see documentation for that function
00096   static inline unsigned char clipRange(int val) {
00097     if (val < 0)        { return 0;         }
00098     else if (val > 255) { return 255;       }
00099     else                { return (unsigned char)val; }
00100   }
00101 
00102   unsigned int numRealLayers; //!< the number of "real" layers being sent from the system
00103 
00104   unsigned char ** layers; //!< points to the image data supplied by the system, one per layer (all channels are interleaved by row)
00105   const OFbkImageInfo ** imageInfos; //!< image info provided by the system
00106 
00107 private:
00108   RawCameraGenerator(const RawCameraGenerator& fbk); //!< don't call
00109   const RawCameraGenerator& operator=(const RawCameraGenerator& fbk); //!< don't call
00110 };
00111 
00112 /*! @file 
00113  * @brief Describes RawCameraGenerator, which generates FilterBankEvents containing raw camera images
00114  * @author ejt (Creator)
00115  *
00116  * $Author: ejt $
00117  * $Name: tekkotsu-2_4_1 $
00118  * $Revision: 1.17 $
00119  * $State: Exp $
00120  * $Date: 2005/06/03 22:56:30 $
00121  */
00122 
00123 #endif

Tekkotsu v2.4.1
Generated Tue Aug 16 16:32:48 2005 by Doxygen 1.4.4