libalvision
1.14.5
|
00001 00006 #pragma once 00007 #ifndef _LIBALVISION_ALVISION_ALIMAGE_H_ 00008 #define _LIBALVISION_ALVISION_ALIMAGE_H_ 00009 00010 #include <string> 00011 #include <iostream> 00012 #include <vector> 00013 #include <cassert> 00014 00015 #include <alvision/alvisiondefinitions.h> 00016 #include <qi/os.hpp> 00017 00021 struct _IplImage; 00022 typedef struct _IplImage IplImage; 00023 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 static ALImage* fromALValue(const ALValue& image); 00101 00102 inline void setWidth( const int width ) { fWidth = width; } 00103 inline void setHeight( const int height ) { fHeight = height; } 00104 inline void setLeftAngle( const float leftAngle ) { fFOV.leftAngle = leftAngle; } 00105 inline void setTopAngle( const float topAngle ) { fFOV.topAngle = topAngle; } 00106 inline void setRightAngle( const float rightAngle ) { fFOV.rightAngle = rightAngle; } 00107 inline void setBottomAngle( const float bottomAngle ) { fFOV.bottomAngle = bottomAngle; } 00108 inline void setAngles( const float leftAngle, const float topAngle, 00109 const float rightAngle, const float bottomAngle ) 00110 { fFOV.leftAngle = leftAngle; fFOV.topAngle = topAngle; 00111 fFOV.rightAngle = rightAngle; fFOV.bottomAngle = bottomAngle; } 00112 00118 bool setSize(int pResolution) { return setResolution(pResolution); } 00119 00125 bool setResolution(int pResolution); 00126 00132 bool setColorSpace(int pColorSpace); 00133 00139 inline const unsigned char* getFrame() const 00140 { assert( fData != 0); 00141 std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl; 00142 return fData; } 00143 00149 inline const unsigned char* getData() const { assert( fData != 0); return fData; } 00150 00151 // for the camera 00157 inline unsigned char* getFrame() 00158 { assert( fData != 0); 00159 std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl; 00160 return fData; } 00161 00167 inline unsigned char* getData() { assert( fData != 0); return fData; } 00168 00174 inline void setData(unsigned char* pData) { fData = pData; } 00175 00181 inline void setTimeStamp(const qi::os::timeval pTimeStamp) 00182 { 00183 if( (pTimeStamp.tv_usec < 0) || (pTimeStamp.tv_sec < 0) ) 00184 { 00185 fTimeStamp = -1; 00186 } 00187 setTimeStamp(pTimeStamp.tv_sec, pTimeStamp.tv_usec); 00188 } 00189 00195 inline void setTimeStamp(long long pTimeStamp) { fTimeStamp = pTimeStamp; } 00196 00203 inline void setTimeStamp(int pSeconds, int pMicroSeconds) 00204 { 00205 fTimeStamp = (long long)pSeconds*1000000LL + (long long)pMicroSeconds; 00206 } 00207 00208 00214 inline void setCameraId(char pCameraId) { fCameraId = pCameraId; } 00215 00216 00221 inline unsigned int getSize() const { return fWidth*fHeight*fNbLayers; } 00222 00223 /* 00224 * Accessor 00225 */ 00226 inline int getWidth( void ) const { return fWidth; } 00227 inline int getHeight( void ) const { return fHeight; } 00228 inline int getResolution( void ) const { return (fWidth==640) ? kVGA : (fWidth==320)?kQVGA:kQQVGA; } 00229 inline int getColorSpace( void ) const { return fColorSpace; } 00230 inline int getNbLayers( void ) const { return fNbLayers; } 00231 inline long long getTimeStamp( void ) const { return fTimeStamp; } 00232 inline char getCameraId() const { return fCameraId; } 00233 inline int getMaxResolution( void ) const { return fMaxResolution; } 00234 inline int getNbOfLayersMax( void ) const { return fMaxNumberOfLayers; } 00235 inline bool areDataExternal( void ) const { return fDataAreExternal; } 00236 int getAllocatedSize() const { return fAllocatedSize; } 00237 inline float getLeftAngle( void ) const { return fFOV.leftAngle; } 00238 inline float getTopAngle( void ) const { return fFOV.topAngle; } 00239 inline float getRightAngle( void ) const { return fFOV.rightAngle; } 00240 inline float getBottomAngle( void ) const { return fFOV.bottomAngle; } 00241 inline void getAngles( float& leftAngle, float& topAngle, float& rightAngle, float& bottomAngle ) 00242 { leftAngle = fFOV.leftAngle; topAngle = fFOV.topAngle; 00243 rightAngle = fFOV.rightAngle; bottomAngle = fFOV.bottomAngle; } 00244 00245 /* 00246 * For debug purpose: print the object in an human format 00247 */ 00248 std::string toString( void ) const; 00249 00250 int getNumOfROIs() const { return (int)fROIs.size(); } 00251 00252 const ROI* getROI(int index) const { 00253 if (index < 0 || index >= getNumOfROIs()) 00254 return NULL; 00255 return &(fROIs[index]); 00256 } 00257 00258 void addROI(const ROI& rect) { 00259 fROIs.push_back(rect); 00260 } 00261 00262 void cleanROIs() { 00263 fROIs.clear(); 00264 } 00265 00266 void setEnableROIs(bool enable) { 00267 fROIEnabled = enable; 00268 } 00269 00270 bool isROIEnabled() const { 00271 return fROIEnabled; 00272 } 00273 00274 00275 int writeFile(const char* _fileNameAndPath); 00276 int readFile(const char* _fileNameAndPath); 00277 int savePPM(const char* _fileNameAndPath); 00278 00279 //deprecated 00280 bool computeYUV422imageFromBGR(IplImage* _src); //TODO(pev): replace argument for compatibility with ALImage by data pointer and sizes 00281 bool computeYUV422imageFromBGR(int height, int width, char *data); 00282 bool computeBGRimageFromYUV422(const unsigned char* _dest); 00283 bool computeYYYUUUVVVimageFromYUV422(const unsigned char* _dest); 00284 bool computeYYYYUUVVimageFromYUV422(const unsigned char* _dest); 00285 private: 00286 bool reallocateDataSize(const int resolution, const int nbLayers); 00287 00288 00289 // .:: members :: 00290 private: 00292 int fWidth; 00293 00295 int fHeight; 00296 00298 int fNbLayers; 00299 00301 int fColorSpace; 00302 00304 long long fTimeStamp; 00305 00307 unsigned char* fData; 00308 00310 char fCameraId; 00311 00313 int fAllocatedSize; 00314 00316 int fMaxResolution; 00317 00319 int fMaxNumberOfLayers; 00320 00323 bool fDataAreExternal; 00324 00326 struct FOV { 00327 float leftAngle; 00328 float topAngle; 00329 float rightAngle; 00330 float bottomAngle; 00331 }; 00332 struct FOV fFOV; 00333 00334 std::vector<ROI> fROIs; 00335 00336 bool fROIEnabled; 00337 }; 00338 } 00339 00340 // take a pixel in YUV and compute its RGB Value. RGB value are returned directly in params 00341 void computeRgbFromYuv( unsigned char * pYR, unsigned char * pUG, unsigned char * pVB ); 00342 00343 00344 #endif // _LIBALVISION_ALVISION_ALIMAGE_H_