source: flair-src/trunk/lib/FlairCore/src/cvimage.h@ 335

Last change on this file since 335 was 330, checked in by Sanahuja Guillaume, 5 years ago

use less bandwidth in vprnlite

File size: 3.0 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]4// %flair:license}
5/*!
6 * \file cvimage.h
7 * \brief Class defining an image of kind IplImage
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2012/03/20
10 * \version 4.0
11 */
12
13#ifndef CVIMAGE_H
14#define CVIMAGE_H
15
16#include <io_data.h>
17#include <stdint.h>
18
[330]19
[15]20namespace flair {
[330]21namespace sensor {
22class V4LCamera;
23}
24}
25
26
27namespace flair {
[15]28namespace core {
29/*! \class cvimage
30*
31* \brief Class defining an image of kind IplImage
32*
33* IplImage is an image struct defined in OpenCV.
34*
35*/
36class cvimage : public io_data {
[330]37 public:
38 friend class flair::sensor::V4LCamera;
[15]39 class Type : public DataType {
40 public:
41 /*!
42 \enum Format_t
43 \brief Picture formats
[2]44 */
[15]45 enum class Format {
46 YUYV, /*!< YUYV 16 bits */
47 UYVY, /*!< UYVY 16 bits */
48 BGR, /*!< BGR 24 bits */
[124]49 Gray, /*!< gray 8 bits */
[15]50 };
51 Type(uint16_t _width, uint16_t _height, Format _format)
52 : width(_width), height(_height), format(_format) {}
[2]53
[15]54 size_t GetSize() const {
55 size_t pixelSize;
56 switch (format) {
[124]57 case Format::Gray:
[15]58 pixelSize = 1;
59 break;
60 case Format::YUYV:
61 case Format::UYVY:
62 pixelSize = 2;
63 break;
64 case Format::BGR:
65 pixelSize = 3;
66 break;
67 default:
68 pixelSize = 0; // TODO should throw an exception instead
69 }
70 return pixelSize * width * height;
71 }
72 std::string GetDescription() const { return "cv image"; };
[2]73
[15]74 Format GetFormat() const { return format; };
75 uint16_t GetWidth() const { return width; };
76 uint16_t GetHeight() const { return height; };
[2]77
[15]78 private:
79 uint16_t width;
80 uint16_t height;
81 Format format;
82 };
[2]83
[15]84 /*!
85 * \brief Constructor
86 *
87 * Construct an io_data representing an IplImage.
88 *
89 * \param parent parent
90 * \param width image width
91 * \param height image height
92 * \param name name
93 * \param allocate_data if true, IplImage image data is allocated; otherwise
94 *img->imagedata must be changed
95 * \param n number of samples
96 */
97 cvimage(const Object *parent, uint16_t width, uint16_t height,
98 Type::Format format, std::string name = "", bool allocate_data = true,
99 int n = 1);
[2]100
[15]101 /*!
102 * \brief Destructor
103 *
104 */
105 ~cvimage();
[2]106
[330]107
108 char *buffer;
[2]109
[15]110 Type const &GetDataType() const { return dataType; };
[330]111
112 static void RegisterAllocFunction(char*(*func)(ssize_t size));
113 static void RegisterFreeFunction(void(*func)(char* buffer));
[2]114
[15]115private:
116 /*!
[252]117 * \brief Raw read datas
[15]118 *
119 * Reimplemented from io_data. \n
[252]120 * See io_data::RawRead.
[15]121 *
122 * \param dst destination buffer
123 */
[252]124 void RawRead(char *dst) const;
[2]125
[15]126 bool allocate_data;
127 Type dataType;
[330]128 static char* (*allocFunction)(ssize_t);
129 static void (*freeFunction)(char*);
130 static char* DefaultAllocFunction(ssize_t size);
131 static void DefaultFreeFunction(char* buffer);
132
[15]133};
[2]134
135} // end namespace core
136} // end namespace flair
137
138#endif // CVIMAGE_H
Note: See TracBrowser for help on using the repository browser.