libalvision  2.1.4.13
 All Classes Namespaces Files Functions Variables Macros Pages
alimage.h
Go to the documentation of this file.
1 
6 #pragma once
7 #ifndef _LIBALVISION_ALVISION_ALIMAGE_H_
8 #define _LIBALVISION_ALVISION_ALIMAGE_H_
9 
10 #include <string>
11 #include <iostream>
12 #include <vector>
13 #include <cassert>
14 
16 #include <qi/os.hpp>
17 
22 namespace AL
23 {
24 class ALValue;
25 
26 class ALImage
27 {
28 public:
29  struct ROI {
30  ROI(int left, int top, int width, int height);
31  ROI(int left, int top, int width, int height,
32  float leftAngle, float topAngle,
33  float rightAngle, float bottomAngle);
34  int x;
35  int y;
36  int w;
37  int h;
38  float leftAngle;
39  float topAngle;
40  float rightAngle;
41  float bottomAngle;
42  };
43 
44  // .:: methods ::
45 
46 public:
59  ALImage(int pWidth, int pHeight, int pColorSpace, bool pDataAreExternal = false,
60  float pLeftAngle = 0.f, float pTopAngle = 0.f,
61  float pRightAngle = 0.f, float pBottomAngle = 0.f);
62 
74  ALImage(int pResolution, int pColorSpace, bool pDataAreExternal = false,
75  float pLeftAngle = 0.f, float pTopAngle = 0.f,
76  float pRightAngle = 0.f, float pBottomAngle = 0.f);
77 
78  ~ALImage();
79 
96  ALValue toALValue();
97 
115  static ALImage* fromALValue(const ALValue& image);
116 
117  inline void setWidth( const int width ) { fWidth = width; }
118  inline void setHeight( const int height ) { fHeight = height; }
119  inline void setLeftAngle( const float leftAngle ) { fFOV.leftAngle = leftAngle; }
120  inline void setTopAngle( const float topAngle ) { fFOV.topAngle = topAngle; }
121  inline void setRightAngle( const float rightAngle ) { fFOV.rightAngle = rightAngle; }
122  inline void setBottomAngle( const float bottomAngle ) { fFOV.bottomAngle = bottomAngle; }
123  inline void setAngles( const float leftAngle, const float topAngle,
124  const float rightAngle, const float bottomAngle )
125  { fFOV.leftAngle = leftAngle; fFOV.topAngle = topAngle;
126  fFOV.rightAngle = rightAngle; fFOV.bottomAngle = bottomAngle; }
127 
131  bool setSize(int pResolution) { return setResolution(pResolution); }
132 
138  bool setResolution(int pResolution);
139 
145  bool setColorSpace(int pColorSpace);
146 
152  inline const unsigned char* getFrame() const
153  { assert( fData != 0);
154  std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl;
155  return fData; }
156 
162  inline const unsigned char* getData() const { assert( fData != 0); return fData; }
163 
164  // for the camera
170  inline unsigned char* getFrame()
171  { assert( fData != 0);
172  std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl;
173  return fData; }
174 
180  inline unsigned char* getData() { assert( fData != 0); return fData; }
181 
187  inline void setData(unsigned char* pData) { fData = pData; }
188 
194  inline void setTimeStamp(const qi::os::timeval pTimeStamp)
195  {
196  if( (pTimeStamp.tv_usec < 0) || (pTimeStamp.tv_sec < 0) )
197  {
198  fTimeStamp = -1;
199  return;
200  }
201  setTimeStamp(static_cast<int>(pTimeStamp.tv_sec), static_cast<int>(pTimeStamp.tv_usec));
202  }
203 
209  inline void setTimeStamp(long long pTimeStamp) { fTimeStamp = pTimeStamp; }
210 
217  inline void setTimeStamp(int pSeconds, int pMicroSeconds)
218  {
219  fTimeStamp = (long long)pSeconds*1000000LL + (long long)pMicroSeconds;
220  }
221 
222 
228  inline void setCameraId(char pCameraId) { fCameraId = pCameraId; }
229 
230 
235  inline unsigned int getSize() const { return fWidth*fHeight*fNbLayers; }
236 
237  /*
238  * Accessor
239  */
240  inline int getWidth( void ) const { return fWidth; }
241  inline int getHeight( void ) const { return fHeight; }
242  inline int getResolution( void ) const { return getResolutionFromSize(fWidth, fHeight); }
243  inline int getColorSpace( void ) const { return fColorSpace; }
244  inline int getNbLayers( void ) const { return fNbLayers; }
245  inline long long getTimeStamp( void ) const { return fTimeStamp; }
246  inline char getCameraId() const { return fCameraId; }
247  inline int getMaxResolution( void ) const { return fMaxResolution; }
248  inline int getNbOfLayersMax( void ) const { return fMaxNumberOfLayers; }
249  inline bool areDataExternal( void ) const { return fDataAreExternal; }
250  int getAllocatedSize() const { return fAllocatedSize; }
251  inline float getLeftAngle( void ) const { return fFOV.leftAngle; }
252  inline float getTopAngle( void ) const { return fFOV.topAngle; }
253  inline float getRightAngle( void ) const { return fFOV.rightAngle; }
254  inline float getBottomAngle( void ) const { return fFOV.bottomAngle; }
255  inline void getAngles( float& leftAngle, float& topAngle, float& rightAngle, float& bottomAngle )
256  const { leftAngle = fFOV.leftAngle; topAngle = fFOV.topAngle;
257  rightAngle = fFOV.rightAngle; bottomAngle = fFOV.bottomAngle; }
258 
259  /*
260  * For debug purpose: print the object in an human format
261  */
262  std::string toString( void ) const;
263 
264  int getNumOfROIs() const { return (int)fROIs.size(); }
265 
266  const ROI* getROI(int index) const {
267  if (index < 0 || index >= getNumOfROIs())
268  return NULL;
269  return &(fROIs[index]);
270  }
271 
272  void addROI(const ROI& rect) {
273  fROIs.push_back(rect);
274  }
275 
276  void cleanROIs() {
277  fROIs.clear();
278  }
279 
280  void setEnableROIs(bool enable) {
281  fROIEnabled = enable;
282  }
283 
284  bool isROIEnabled() const {
285  return fROIEnabled;
286  }
287 
288 
289  int writeFile(const char* _fileNameAndPath);
290  int readFile(const char* _fileNameAndPath);
291  int savePPM(const char* _fileNameAndPath);
292 
293  bool computeYUV422imageFromBGR(int height, int width, char *data);
294  bool computeBGRimageFromYUV422(const unsigned char* _dest);
295  bool computeYYYUUUVVVimageFromYUV422(const unsigned char* _dest);
296  bool computeYYYYUUVVimageFromYUV422(const unsigned char* _dest);
297 private:
298  bool reallocateDataSize(const int resolution, const int nbLayers);
299 
300 
301  // .:: members ::
302 private:
304  int fWidth;
305 
307  int fHeight;
308 
310  int fNbLayers;
311 
313  int fColorSpace;
314 
316  long long fTimeStamp;
317 
319  unsigned char* fData;
320 
322  char fCameraId;
323 
325  int fAllocatedSize;
326 
328  int fMaxResolution;
329 
331  int fMaxNumberOfLayers;
332 
335  bool fDataAreExternal;
336 
338  struct FOV {
339  float leftAngle;
340  float topAngle;
341  float rightAngle;
342  float bottomAngle;
343  };
344  struct FOV fFOV;
345 
346  std::vector<ROI> fROIs;
347 
348  bool fROIEnabled;
349 };
350 }
351 
352 // take a pixel in YUV and compute its RGB Value. RGB value are returned directly in params
353 void computeRgbFromYuv( unsigned char * pYR, unsigned char * pUG, unsigned char * pVB );
354 
355 
356 #endif // _LIBALVISION_ALVISION_ALIMAGE_H_
int getMaxResolution(void) const
Definition: alimage.h:247
int getResolution(void) const
Definition: alimage.h:242
bool setResolution(int pResolution)
set the Resolution of the image without changing the allocation size.
int getNumOfROIs() const
Definition: alimage.h:264
void getAngles(float &leftAngle, float &topAngle, float &rightAngle, float &bottomAngle) const
Definition: alimage.h:255
bool computeBGRimageFromYUV422(const unsigned char *_dest)
bool areDataExternal(void) const
Definition: alimage.h:249
int savePPM(const char *_fileNameAndPath)
float getBottomAngle(void) const
Definition: alimage.h:254
bool setColorSpace(int pColorSpace)
set the ColorSpace of the image without changing the allocation size.
unsigned char * getData()
return the pointer to the image data.
Definition: alimage.h:180
float rightAngle
Definition: alimage.h:40
void setLeftAngle(const float leftAngle)
Definition: alimage.h:119
const unsigned char * getData() const
return the reference to the image data.
Definition: alimage.h:162
void setTimeStamp(long long pTimeStamp)
set the image timestamp
Definition: alimage.h:209
void setBottomAngle(const float bottomAngle)
Definition: alimage.h:122
int getResolutionFromSize(const int width, const int height)
Utility function that takes width and height as inputs and returns the corresponding resolution index...
void setTimeStamp(const qi::os::timeval pTimeStamp)
set the image timestamp.
Definition: alimage.h:194
void setHeight(const int height)
Definition: alimage.h:118
float leftAngle
Definition: alimage.h:38
void setRightAngle(const float rightAngle)
Definition: alimage.h:121
void computeRgbFromYuv(unsigned char *pYR, unsigned char *pUG, unsigned char *pVB)
bool computeYYYYUUVVimageFromYUV422(const unsigned char *_dest)
float getRightAngle(void) const
Definition: alimage.h:253
char getCameraId() const
Definition: alimage.h:246
void setEnableROIs(bool enable)
Definition: alimage.h:280
long long getTimeStamp(void) const
Definition: alimage.h:245
void addROI(const ROI &rect)
Definition: alimage.h:272
bool setSize(int pResolution)
set the Resolution of the image without changing the allocation size.
Definition: alimage.h:131
int writeFile(const char *_fileNameAndPath)
void setData(unsigned char *pData)
set the image data pointer to point to the specified buffer.
Definition: alimage.h:187
void cleanROIs()
Definition: alimage.h:276
float bottomAngle
Definition: alimage.h:41
ALImage(int pWidth, int pHeight, int pColorSpace, bool pDataAreExternal=false, float pLeftAngle=0.f, float pTopAngle=0.f, float pRightAngle=0.f, float pBottomAngle=0.f)
constructor
int getColorSpace(void) const
Definition: alimage.h:243
static ALImage * fromALValue(const ALValue &image)
Allocate an ALImage and return a pointer on it using an ALValue to fill it.
const ROI * getROI(int index) const
Definition: alimage.h:266
int getNbOfLayersMax(void) const
Definition: alimage.h:248
int getWidth(void) const
Definition: alimage.h:240
unsigned int getSize() const
Definition: alimage.h:235
bool computeYUV422imageFromBGR(int height, int width, char *data)
const unsigned char * getFrame() const
return the reference to the image data.
Definition: alimage.h:152
float topAngle
Definition: alimage.h:39
void setWidth(const int width)
Definition: alimage.h:117
float getLeftAngle(void) const
Definition: alimage.h:251
void setTimeStamp(int pSeconds, int pMicroSeconds)
set the image timestamp
Definition: alimage.h:217
vision defines
void setTopAngle(const float topAngle)
Definition: alimage.h:120
unsigned char * getFrame()
return the pointer to the image data.
Definition: alimage.h:170
int getHeight(void) const
Definition: alimage.h:241
bool computeYYYUUUVVVimageFromYUV422(const unsigned char *_dest)
int readFile(const char *_fileNameAndPath)
bool isROIEnabled() const
Definition: alimage.h:284
ROI(int left, int top, int width, int height)
int getNbLayers(void) const
Definition: alimage.h:244
std::string toString(void) const
void setCameraId(char pCameraId)
set the ID of the camera that shot the picture
Definition: alimage.h:228
int getAllocatedSize() const
Definition: alimage.h:250
ALValue toALValue()
return an ALValue containing image structure
void setAngles(const float leftAngle, const float topAngle, const float rightAngle, const float bottomAngle)
Definition: alimage.h:123
float getTopAngle(void) const
Definition: alimage.h:252