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