- Aldebaran documentation |
- C++ Libraries |
- index

libalvision 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Friends 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
15 #include <boost/shared_ptr.hpp>
16
17 #include <alvision/alvisiondefinitions.h>
18 #include <qi/os.hpp>
19
24 namespace AL
25 {
26 class ALValue;
27
28 class ALImage
29 {
30 public:
31 struct ROI {
32 ROI(int left, int top, int width, int height);
33 ROI(int left, int top, int width, int height,
34 float leftAngle, float topAngle,
35 float rightAngle, float bottomAngle);
36 int x;
37 int y;
38 int w;
39 int h;
40 float leftAngle;
41 float topAngle;
42 float rightAngle;
43 float bottomAngle;
44 };
45
46 // .:: methods ::
47
48 public:
61 ALImage(int pWidth, int pHeight, int pColorSpace, bool pDataAreExternal = false,
62 float pLeftAngle = 0.f, float pTopAngle = 0.f,
63 float pRightAngle = 0.f, float pBottomAngle = 0.f);
64
76 ALImage(int pResolution, int pColorSpace, bool pDataAreExternal = false,
77 float pLeftAngle = 0.f, float pTopAngle = 0.f,
78 float pRightAngle = 0.f, float pBottomAngle = 0.f);
79
80 ~ALImage();
81
88 ALImage deepCopy() const;
89
106 ALValue toALValue();
107
125 static ALImage* fromALValue(const ALValue& image);
126
127 inline void setWidth( const int width ) { fWidth = width; }
128 inline void setHeight( const int height ) { fHeight = height; }
129 inline void setLeftAngle( const float leftAngle ) { fFOV.leftAngle = leftAngle; }
130 inline void setTopAngle( const float topAngle ) { fFOV.topAngle = topAngle; }
131 inline void setRightAngle( const float rightAngle ) { fFOV.rightAngle = rightAngle; }
132 inline void setBottomAngle( const float bottomAngle ) { fFOV.bottomAngle = bottomAngle; }
133 inline void setAngles( const float leftAngle, const float topAngle,
134 const float rightAngle, const float bottomAngle )
135 { fFOV.leftAngle = leftAngle; fFOV.topAngle = topAngle;
136 fFOV.rightAngle = rightAngle; fFOV.bottomAngle = bottomAngle; }
137
141 bool setSize(int pResolution) { return setResolution(pResolution); }
142
148 bool setResolution(int pResolution);
149
155 bool setColorSpace(int pColorSpace);
156
162 inline const unsigned char* getFrame() const
163 { std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl;
164 return rawData(); }
165
171 inline const unsigned char* getData() const { return rawData(); }
172
173 // for the camera
179 inline unsigned char* getFrame()
180 { std::cout << "getFrame() is deprecated. Please replace by getData()." << std::endl;
181 return rawData(); }
182
188 inline unsigned char* getData() { return rawData(); }
189
196 inline void setData(unsigned char* pData) { fData = externalData(pData); }
197
203 inline void setTimeStamp(const qi::os::timeval pTimeStamp)
204 {
205 if( (pTimeStamp.tv_usec < 0) || (pTimeStamp.tv_sec < 0) )
206 {
207 fTimeStamp = -1;
208 return;
209 }
210 setTimeStamp(static_cast<int>(pTimeStamp.tv_sec), static_cast<int>(pTimeStamp.tv_usec));
211 }
212
218 inline void setTimeStamp(long long pTimeStamp) { fTimeStamp = pTimeStamp; }
219
226 inline void setTimeStamp(int pSeconds, int pMicroSeconds)
227 {
228 fTimeStamp = (long long)pSeconds*1000000LL + (long long)pMicroSeconds;
229 }
230
231
237 inline void setCameraId(char pCameraId) { fCameraId = pCameraId; }
238
239
244 inline unsigned int getSize() const { return fWidth*fHeight*fNbLayers; }
245
246 /*
247 * Accessor
248 */
249 inline int getWidth( void ) const { return fWidth; }
250 inline int getHeight( void ) const { return fHeight; }
251 inline int getResolution( void ) const { return getResolutionFromSize(fWidth, fHeight); }
252 inline int getColorSpace( void ) const { return fColorSpace; }
253 inline int getNbLayers( void ) const { return fNbLayers; }
254 inline long long getTimeStamp( void ) const { return fTimeStamp; }
255 inline char getCameraId() const { return fCameraId; }
256 inline int getMaxResolution( void ) const { return fMaxResolution; }
257 inline int getNbOfLayersMax( void ) const { return fMaxNumberOfLayers; }
258 inline bool areDataExternal( void ) const { return !fData || getDeleter().external; }
259 int getAllocatedSize() const { return fAllocatedSize; }
260 inline float getLeftAngle( void ) const { return fFOV.leftAngle; }
261 inline float getTopAngle( void ) const { return fFOV.topAngle; }
262 inline float getRightAngle( void ) const { return fFOV.rightAngle; }
263 inline float getBottomAngle( void ) const { return fFOV.bottomAngle; }
264 inline void getAngles( float& leftAngle, float& topAngle, float& rightAngle, float& bottomAngle )
265 const { leftAngle = fFOV.leftAngle; topAngle = fFOV.topAngle;
266 rightAngle = fFOV.rightAngle; bottomAngle = fFOV.bottomAngle; }
267
268 /*
269 * For debug purpose: print the object in an human format
270 */
271 std::string toString( void ) const;
272
273 int getNumOfROIs() const { return (int)fROIs.size(); }
274
275 const ROI* getROI(int index) const {
276 if (index < 0 || index >= getNumOfROIs())
277 return NULL;
278 return &(fROIs[index]);
279 }
280
281 void addROI(const ROI& rect) {
282 fROIs.push_back(rect);
283 }
284
285 void cleanROIs() {
286 fROIs.clear();
287 }
288
289 void setEnableROIs(bool enable) {
290 fROIEnabled = enable;
291 }
292
293 bool isROIEnabled() const {
294 return fROIEnabled;
295 }
296
297
298 int writeFile(const char* _fileNameAndPath);
299 int readFile(const char* _fileNameAndPath);
300 int savePPM(const char* _fileNameAndPath);
301
302 bool computeYUV422imageFromBGR(int height, int width, char *data);
303 bool computeBGRimageFromYUV422(const unsigned char* _dest);
304 bool computeYYYUUUVVVimageFromYUV422(const unsigned char* _dest);
305 bool computeYYYYUUVVimageFromYUV422(const unsigned char* _dest);
306 private:
327 class deleter
328 {
329 public:
330 deleter(bool external) : external(external) {}
331 void operator()(unsigned char* p)
332 {
333 if (!external && p != NULL)
334 delete[] p;
335 }
336 bool external;
337 };
338 friend class deleter;
339
340 bool reallocateDataSize(const int resolution, const int nbLayers);
341 inline unsigned char* rawData() const { assert( fData ); return fData.get(); }
349 inline ALImage::deleter& getDeleter() const
350 {
351 assert( fData );
352 assert( boost::get_deleter<ALImage::deleter>(fData) != NULL );
353 return *boost::get_deleter<ALImage::deleter>(fData);
354 }
355 static boost::shared_ptr<unsigned char[]> internalDataUninitialized(size_t size);
356 static boost::shared_ptr<unsigned char[]> internalDataZeroInitialized(size_t size);
357 static boost::shared_ptr<unsigned char[]> externalData(unsigned char[]);
358 static boost::shared_ptr<unsigned char[]> emptyData(bool external);
359
360
361 // .:: members ::
362 private:
364 int fWidth;
365
367 int fHeight;
368
370 int fNbLayers;
371
373 int fColorSpace;
374
376 long long fTimeStamp;
377
379 boost::shared_ptr<unsigned char[]> fData;
380
382 char fCameraId;
383
385 int fAllocatedSize;
386
388 int fMaxResolution;
389
391 int fMaxNumberOfLayers;
392
394 struct FOV {
395 float leftAngle;
396 float topAngle;
397 float rightAngle;
398 float bottomAngle;
399 };
400 struct FOV fFOV;
401
402 std::vector<ROI> fROIs;
403
404 bool fROIEnabled;
405 };
406 }
407
408 // take a pixel in YUV and compute its RGB Value. RGB value are returned directly in params
409 void computeRgbFromYuv( unsigned char * pYR, unsigned char * pUG, unsigned char * pVB );
410
411
412 #endif // _LIBALVISION_ALVISION_ALIMAGE_H_
AL::ALImage
Definition: alimage.h:28
computeRgbFromYuv
void computeRgbFromYuv(unsigned char *pYR, unsigned char *pUG, unsigned char *pVB)
AL::ALImage::setData
void setData(unsigned char *pData)
set the image data pointer to point to the specified buffer.
Definition: alimage.h:196
AL::ALImage::computeYYYUUUVVVimageFromYUV422
bool computeYYYUUUVVVimageFromYUV422(const unsigned char *_dest)
AL::ALImage::setResolution
bool setResolution(int pResolution)
set the Resolution of the image without changing the allocation size.
AL::ALImage::ROI::x
int x
Definition: alimage.h:36
AL::ALImage::getSize
unsigned int getSize() const
Definition: alimage.h:244
AL::ALImage::ROI::rightAngle
float rightAngle
Definition: alimage.h:42
AL::ALImage::setColorSpace
bool setColorSpace(int pColorSpace)
set the ColorSpace of the image without changing the allocation size.
AL::ALImage::setTimeStamp
void setTimeStamp(int pSeconds, int pMicroSeconds)
set the image timestamp
Definition: alimage.h:226
AL::ALImage::ROI::w
int w
Definition: alimage.h:38
AL::ALImage::ROI::ROI
ROI(int left, int top, int width, int height)
AL::ALImage::setBottomAngle
void setBottomAngle(const float bottomAngle)
Definition: alimage.h:132
AL::getResolutionFromSize
int getResolutionFromSize(const int width, const int height)
Utility function that takes width and height as inputs and returns the corresponding resolution index...
AL::ALImage::getRightAngle
float getRightAngle(void) const
Definition: alimage.h:262
AL::ALImage::~ALImage
~ALImage()
AL::ALImage::getMaxResolution
int getMaxResolution(void) const
Definition: alimage.h:256
AL::ALImage::setCameraId
void setCameraId(char pCameraId)
set the ID of the camera that shot the picture
Definition: alimage.h:237
AL::ALImage::setSize
bool setSize(int pResolution)
set the Resolution of the image without changing the allocation size.
Definition: alimage.h:141
alvisiondefinitions.h
vision defines
AL::ALImage::computeYYYYUUVVimageFromYUV422
bool computeYYYYUUVVimageFromYUV422(const unsigned char *_dest)
AL::ALImage::setAngles
void setAngles(const float leftAngle, const float topAngle, const float rightAngle, const float bottomAngle)
Definition: alimage.h:133
AL::ALImage::setTopAngle
void setTopAngle(const float topAngle)
Definition: alimage.h:130
AL::ALImage::ROI::topAngle
float topAngle
Definition: alimage.h:41
AL::ALImage::setTimeStamp
void setTimeStamp(const qi::os::timeval pTimeStamp)
set the image timestamp.
Definition: alimage.h:203
AL::ALImage::getData
const unsigned char * getData() const
return the reference to the image data.
Definition: alimage.h:171
AL::ALImage::readFile
int readFile(const char *_fileNameAndPath)
AL::ALImage::setWidth
void setWidth(const int width)
Definition: alimage.h:127
AL::ALImage::writeFile
int writeFile(const char *_fileNameAndPath)
AL::ALImage::getAngles
void getAngles(float &leftAngle, float &topAngle, float &rightAngle, float &bottomAngle) const
Definition: alimage.h:264
AL::ALImage::getNbOfLayersMax
int getNbOfLayersMax(void) const
Definition: alimage.h:257
AL::ALImage::getROI
const ROI * getROI(int index) const
Definition: alimage.h:275
AL::ALImage::getLeftAngle
float getLeftAngle(void) const
Definition: alimage.h:260
AL::ALImage::getBottomAngle
float getBottomAngle(void) const
Definition: alimage.h:263
AL::ALImage::ROI::y
int y
Definition: alimage.h:37
AL::ALImage::toALValue
ALValue toALValue()
return an ALValue containing image structure
AL::ALImage::setHeight
void setHeight(const int height)
Definition: alimage.h:128
AL::ALImage::savePPM
int savePPM(const char *_fileNameAndPath)
AL::ALImage::setRightAngle
void setRightAngle(const float rightAngle)
Definition: alimage.h:131
AL::ALImage::cleanROIs
void cleanROIs()
Definition: alimage.h:285
AL::ALImage::getResolution
int getResolution(void) const
Definition: alimage.h:251
AL::ALImage::ROI::bottomAngle
float bottomAngle
Definition: alimage.h:43
AL::ALImage::deleter
friend class deleter
Definition: alimage.h:338
AL::ALImage::getWidth
int getWidth(void) const
Definition: alimage.h:249
AL::ALImage::computeYUV422imageFromBGR
bool computeYUV422imageFromBGR(int height, int width, char *data)
AL::ALImage::areDataExternal
bool areDataExternal(void) const
Definition: alimage.h:258
AL::ALImage::getNumOfROIs
int getNumOfROIs() const
Definition: alimage.h:273
AL::ALImage::ROI
Definition: alimage.h:31
AL::ALImage::getHeight
int getHeight(void) const
Definition: alimage.h:250
AL::ALImage::toString
std::string toString(void) const
AL::ALImage::setTimeStamp
void setTimeStamp(long long pTimeStamp)
set the image timestamp
Definition: alimage.h:218
AL::ALImage::getColorSpace
int getColorSpace(void) const
Definition: alimage.h:252
AL::ALImage::isROIEnabled
bool isROIEnabled() const
Definition: alimage.h:293
AL::ALImage::ALImage
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
AL::ALImage::setLeftAngle
void setLeftAngle(const float leftAngle)
Definition: alimage.h:129
AL::ALImage::fromALValue
static ALImage * fromALValue(const ALValue &image)
Allocate an ALImage and return an (owning) pointer on it using an ALValue to fill it...
AL::ALImage::getData
unsigned char * getData()
return the pointer to the image data.
Definition: alimage.h:188
AL::ALImage::getTopAngle
float getTopAngle(void) const
Definition: alimage.h:261
AL::ALImage::getFrame
const unsigned char * getFrame() const
return the reference to the image data.
Definition: alimage.h:162
AL::ALImage::ROI::h
int h
Definition: alimage.h:39
AL::ALImage::getAllocatedSize
int getAllocatedSize() const
Definition: alimage.h:259
AL::ALImage::computeBGRimageFromYUV422
bool computeBGRimageFromYUV422(const unsigned char *_dest)
AL::ALImage::ROI::leftAngle
float leftAngle
Definition: alimage.h:40
AL::ALImage::getNbLayers
int getNbLayers(void) const
Definition: alimage.h:253
AL::ALImage::getCameraId
char getCameraId() const
Definition: alimage.h:255
AL::ALImage::getTimeStamp
long long getTimeStamp(void) const
Definition: alimage.h:254
AL::ALImage::getFrame
unsigned char * getFrame()
return the pointer to the image data.
Definition: alimage.h:179
AL::ALImage::setEnableROIs
void setEnableROIs(bool enable)
Definition: alimage.h:289
AL::ALImage::addROI
void addROI(const ROI &rect)
Definition: alimage.h:281
AL::ALImage::deepCopy
ALImage deepCopy() const
data-ownership copy creation