libalvision  1.12
alvision/alimage.h
Go to the documentation of this file.
00001 
00006 #pragma once
00007 #ifndef _LIBALVISION_ALVISION_ALIMAGE_H_
00008 #define _LIBALVISION_ALVISION_ALIMAGE_H_
00009 
00010 // upstream opencv headers need cstddef
00011 #include <cstddef>
00012 #include <string>
00013 #include <iostream>
00014 #include <vector>
00015 #include <opencv/cv.h>
00016 
00017 #include <alvision/alvisiondefinitions.h>
00018 #include <qi/os.hpp>
00019 
00024 namespace AL
00025 {
00026   class ALValue;
00027 
00028   class ALImage
00029   {
00030   public:
00031     struct ROI {
00032       ROI(int left, int top, int width, int height);
00033       ROI(int left, int top, int width, int height,
00034           float leftAngle,  float topAngle,
00035           float rightAngle, float bottomAngle);
00036       int x;
00037       int y;
00038       int w;
00039       int h;
00040       float leftAngle;
00041       float topAngle;
00042       float rightAngle;
00043       float bottomAngle;
00044     };
00045 
00046   // .:: methods ::
00047 
00048   public:
00061     ALImage(int pWidth, int pHeight, int pColorSpace, bool pDataAreExternal = false,
00062             float pLeftAngle = 0.f, float pTopAngle = 0.f,
00063             float pRightAngle = 0.f, float pBottomAngle = 0.f);
00064 
00076     ALImage(int pResolution, int pColorSpace, bool pDataAreExternal = false,
00077             float pLeftAngle = 0.f, float pTopAngle = 0.f,
00078             float pRightAngle = 0.f, float pBottomAngle = 0.f);
00079 
00080     ~ALImage();
00081 
00098     ALValue toALValue();
00099 
00100     inline void setWidth( const int width )   { fWidth = width; }
00101     inline void setHeight( const int height ) { fHeight = height; }
00102     inline void setLeftAngle( const float leftAngle )     { fFOV.leftAngle = leftAngle; }
00103     inline void setTopAngle( const float topAngle )       { fFOV.topAngle = topAngle; }
00104     inline void setRightAngle( const float rightAngle )   { fFOV.rightAngle = rightAngle; }
00105     inline void setBottomAngle( const float bottomAngle ) { fFOV.bottomAngle = bottomAngle; }
00106     inline void setAngles( const float leftAngle,  const float topAngle,
00107                            const float rightAngle, const float bottomAngle )
00108                 { fFOV.leftAngle = leftAngle;   fFOV.topAngle = topAngle;
00109                   fFOV.rightAngle = rightAngle; fFOV.bottomAngle = bottomAngle; }
00110 
00116     bool setSize(int pResolution) { return setResolution(pResolution); }
00117 
00123     bool setResolution(int pResolution);
00124 
00130     bool setColorSpace(int pColorSpace);
00131 
00137     inline const unsigned char* getFrame() const
00138     { assert( fData != 0);
00139       std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl;
00140       return fData; }
00141 
00147     inline const unsigned char* getData() const { assert( fData != 0); return fData; }
00148 
00149     // for the camera
00155     inline unsigned char* getFrame()
00156     { assert( fData != 0);
00157       std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl;
00158       return fData; }
00159 
00165     inline unsigned char* getData() { assert( fData != 0); return fData; }
00166 
00172     inline void setData(unsigned char* pData) { fData = pData; }
00173 
00179     inline void setTimeStamp(const qi::os::timeval pTimeStamp)
00180     {
00181       if( (pTimeStamp.tv_usec < 0) || (pTimeStamp.tv_sec < 0) )
00182       {
00183         fTimeStamp = -1;
00184       }
00185       setTimeStamp(pTimeStamp.tv_sec, pTimeStamp.tv_usec);
00186     }
00187 
00193     inline void setTimeStamp(long long pTimeStamp) { fTimeStamp = pTimeStamp; }
00194 
00201     inline void setTimeStamp(int pSeconds, int pMicroSeconds)
00202     {
00203       fTimeStamp = (long long)pSeconds*1000000LL + (long long)pMicroSeconds;
00204     }
00205 
00206 
00212     inline void setCameraId(char pCameraId) { fCameraId = pCameraId; }
00213 
00214 
00219     inline unsigned int getSize() const { return fWidth*fHeight*fNbLayers; }
00220 
00221     /*
00222      * Accessor
00223      */
00224     inline int getWidth( void )  const { return fWidth; }
00225     inline int getHeight( void ) const { return fHeight; }
00226     inline int getResolution( void ) const { return (fWidth==640) ? kVGA : (fWidth==320)?kQVGA:kQQVGA; }
00227     inline int getColorSpace( void ) const { return fColorSpace; }
00228     inline int getNbLayers( void ) const { return fNbLayers; }
00229     inline long long getTimeStamp( void ) const { return fTimeStamp; }
00230     inline char getCameraId() const { return fCameraId; }
00231     inline int getMaxResolution( void ) const { return fMaxResolution; }
00232     inline int getNbOfLayersMax( void ) const { return fMaxNumberOfLayers; }
00233     inline bool areDataExternal( void ) const { return fDataAreExternal; }
00234     int getAllocatedSize() const { return fAllocatedSize; }
00235     inline float getLeftAngle( void )   const { return fFOV.leftAngle; }
00236     inline float getTopAngle( void )    const { return fFOV.topAngle; }
00237     inline float getRightAngle( void )  const { return fFOV.rightAngle; }
00238     inline float getBottomAngle( void ) const { return fFOV.bottomAngle; }
00239     inline void getAngles( float& leftAngle, float& topAngle, float& rightAngle, float& bottomAngle )
00240     { leftAngle = fFOV.leftAngle; topAngle = fFOV.topAngle;
00241       rightAngle = fFOV.rightAngle; bottomAngle = fFOV.bottomAngle; }
00242 
00243     /*
00244      * For debug purpose: print the object in an human format
00245      */
00246     std::string toString( void ) const;
00247 
00248     int getNumOfROIs() const { return (int)fROIs.size(); }
00249 
00250     const ROI* getROI(int index) const {
00251       if (index < 0 || index >= getNumOfROIs())
00252         return NULL;
00253       return &(fROIs[index]);
00254     }
00255 
00256     void addROI(const ROI& rect) {
00257       fROIs.push_back(rect);
00258     }
00259 
00260     void cleanROIs() {
00261       fROIs.clear();
00262     }
00263 
00264     void setEnableROIs(bool enable) {
00265       fROIEnabled = enable;
00266     }
00267 
00268     bool isROIEnabled() const {
00269       return fROIEnabled;
00270     }
00271 
00272 
00273     int writeFile(const char* _fileNameAndPath);
00274     int readFile(const char* _fileNameAndPath);
00275     int savePPM(const char* _fileNameAndPath);
00276     bool computeYUV422imageFromBGR(IplImage* _src); //TODO(pev): replace argument for compatibility with ALImage by data pointer and sizes
00277     bool computeBGRimageFromYUV422(const unsigned char* _dest);
00278     bool computeYYYUUUVVVimageFromYUV422(const unsigned char* _dest);
00279     bool computeYYYYUUVVimageFromYUV422(const unsigned char* _dest);
00280 
00281   private:
00282     bool reallocateDataSize(const int resolution, const int nbLayers);
00283 
00284 
00285   // .:: members ::
00286   private:
00288     int fWidth;
00289 
00291     int fHeight;
00292 
00294     int fNbLayers;
00295 
00297     int fColorSpace;
00298 
00300     long long fTimeStamp;
00301 
00303     unsigned char* fData;
00304 
00306     char fCameraId;
00307 
00309     int fAllocatedSize;
00310 
00312     int fMaxResolution;
00313 
00315     int fMaxNumberOfLayers;
00316 
00319     bool fDataAreExternal;
00320 
00322     struct FOV {
00323       float leftAngle;
00324       float topAngle;
00325       float rightAngle;
00326       float bottomAngle;
00327     };
00328     struct FOV fFOV;
00329 
00330     std::vector<ROI> fROIs;
00331 
00332     bool fROIEnabled;
00333   };
00334 }
00335 
00336 // take a pixel in YUV and compute its RGB Value. RGB value are returned directly in params
00337 void computeRgbFromYuv( unsigned char * pYR, unsigned char * pUG, unsigned char * pVB );
00338 
00339 
00340 #endif  // _LIBALVISION_ALVISION_ALIMAGE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends