| Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
RawCameraGenerator.hGo 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 #ifdef PLATFORM_APERIOS 00008 // to get the default camera resolution for the static allocation hack 00009 # include "Shared/RobotInfo.h" 00010 #endif 00011 00012 class OFbkImageInfo; 00013 00014 //! Generates FilterBankEvents containing raw camera images directly from the system (doesn't make a copy) 00015 class RawCameraGenerator : public FilterBankGenerator { 00016 public: 00017 //! constructor, numRawLayers is the number of real layers passed from the system, numCalcLayers is the total number of layers to make available 00018 /*! The extra calculated layers are simply created by giving larger 00019 * increments, they reference the same data (no computational cost, 00020 * marginal memory costs... it's just nice to have more layers in 00021 * the image pyramid. 00022 * 00023 * However you'll have to write your code to use the getIncrement() 00024 * value properly if you want it to work. Otherwise, you could 00025 * write a de-interlace generator which will do the resampling. 00026 * 00027 * The top most layer (largest index) is a double-scale image. For 00028 * the Y-channel, it is reconstructed from the 4 Y channels. For 00029 * the other channels, it just does a fast scaling (but these 00030 * operations do cost, so use the top layer conservatively. 00031 * 00032 * @see FilterBankGenerator for information on serialization format 00033 */ 00034 RawCameraGenerator(unsigned int numRawLayers, unsigned int numCalcLayers, unsigned int mysid, EventBase::EventGeneratorID_t gid, unsigned int sid); 00035 00036 //! destructor 00037 virtual ~RawCameraGenerator() { 00038 freeCaches(); 00039 destruct(); 00040 } 00041 00042 static std::string getClassDescription() { return "Translates OFbkImageVectorData objects from the system into a slightly more accessible FilterBankEvent for further processing"; } 00043 00044 //! holds id values for specifying image channel/bands 00045 enum channel_id_t { 00046 CHAN_Y, //!< Y (intensity) channel 00047 CHAN_U, //!< Cb (approx. blue,green,yellow) channel 00048 CHAN_V, //!< Cr (approx. pink,red,yellow) channel 00049 CHAN_Y_DY, //!< vertical derivative of Y channel (aka LH) 00050 CHAN_Y_DX, //!< horizontal derivative of Y channel (aka HL) 00051 CHAN_Y_DXDY, //!< vert. & horiz. derivatives of Y channel (aka HH) 00052 NUM_CHANNELS //!< number of channels per resolution layer 00053 }; 00054 00055 //! need to override EventGeneratorBase's lazy listening -- as a root stage, need to remember each frame, just in case it might be used 00056 virtual void doStart() { FilterBankGenerator::doStart(); addSrcListener(); } 00057 00058 //! called with system's image info 00059 virtual void doEvent(); 00060 00061 //! 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 00062 virtual void freeCaches(); 00063 00064 virtual unsigned int getBinSize() const; 00065 00066 virtual unsigned int loadBuffer(const char buf[], unsigned int len, const char* filename=NULL); 00067 00068 virtual unsigned int saveBuffer(char buf[], unsigned int len) const; 00069 00070 virtual unsigned int saveFileStream(FILE* f) const; //!< overrridden to allow saving direct to file without an extra buffer copy 00071 00072 protected: 00073 #ifdef PLATFORM_APERIOS 00074 //! ohh, this is so yucky. But we need to get around heap allocation bugs with large regions in Aperios :( 00075 /*! So we store the double size images statically within the class. 00076 * What a waste of memory since we're probably not using these very 00077 * much, and they are rather large... :( 00078 * 00079 * The 2.0 release had the proper dynamic allocation 00080 * implementation, but has been replaced in 2.0.1 with this static 00081 * allocation so it won't crash.*/ 00082 unsigned char dblRes[NUM_CHANNELS][CameraResolutionX*2][CameraResolutionY*2]; 00083 #endif 00084 00085 virtual void setNumImages(unsigned int nLayers, unsigned int nChannels); 00086 00087 virtual void setDimensions(); //!< resets the width, height, skip and stride values 00088 virtual unsigned char * createImageCache(unsigned int layer, unsigned int chan) const; 00089 virtual void calcImage(unsigned int layer, unsigned int chan); 00090 virtual void destruct(); 00091 00092 //! returns the value to pass to OPENR functions corresponding to the desired channel_id_t. 00093 inline static unsigned int mapChannelID(channel_id_t chan); 00094 00095 //! Creates a double resolution version of a channel, doesn't do any smoothing 00096 void upsampleImage(channel_id_t chan); 00097 00098 //! Creates a double resolution Y-channel from the Y and Y gradient channels 00099 void reconstructImage(); 00100 00101 //! helper functions for reconstructImage() - see documentation for that function 00102 static inline unsigned char clipRange(int val) { 00103 if (val < 0) { return 0; } 00104 else if (val > 255) { return 255; } 00105 else { return (unsigned char)val; } 00106 } 00107 00108 unsigned int numRealLayers; //!< the number of "real" layers being sent from the system 00109 00110 unsigned char ** layers; //!< points to the image data supplied by the system, one per layer (all channels are interleaved by row) 00111 const OFbkImageInfo ** imageInfos; //!< image info provided by the system 00112 00113 private: 00114 RawCameraGenerator(const RawCameraGenerator& fbk); //!< don't call 00115 const RawCameraGenerator& operator=(const RawCameraGenerator& fbk); //!< don't call 00116 }; 00117 00118 /*! @file 00119 * @brief Describes RawCameraGenerator, which generates FilterBankEvents containing raw camera images 00120 * @author ejt (Creator) 00121 */ 00122 00123 #endif |
|
Tekkotsu v5.1CVS |
Generated Tue Jan 31 04:32:05 2012 by Doxygen 1.6.3 |