1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
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 |
|
---|
19 |
|
---|
20 | namespace flair {
|
---|
21 | namespace sensor {
|
---|
22 | class V4LCamera;
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 |
|
---|
27 | namespace flair {
|
---|
28 | namespace 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 | */
|
---|
36 | class cvimage : public io_data {
|
---|
37 | public:
|
---|
38 | friend class flair::sensor::V4LCamera;
|
---|
39 | class Type : public DataType {
|
---|
40 | public:
|
---|
41 | /*!
|
---|
42 | \enum Format_t
|
---|
43 | \brief Picture formats
|
---|
44 | */
|
---|
45 | enum class Format {
|
---|
46 | YUYV, /*!< YUYV 16 bits */
|
---|
47 | UYVY, /*!< UYVY 16 bits */
|
---|
48 | BGR, /*!< BGR 24 bits */
|
---|
49 | Gray, /*!< gray 8 bits */
|
---|
50 | };
|
---|
51 | Type(uint16_t _width, uint16_t _height, Format _format)
|
---|
52 | : width(_width), height(_height), format(_format) {}
|
---|
53 |
|
---|
54 | size_t GetSize() const {
|
---|
55 | size_t pixelSize;
|
---|
56 | switch (format) {
|
---|
57 | case Format::Gray:
|
---|
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"; };
|
---|
73 |
|
---|
74 | Format GetFormat() const { return format; };
|
---|
75 | uint16_t GetWidth() const { return width; };
|
---|
76 | uint16_t GetHeight() const { return height; };
|
---|
77 |
|
---|
78 | private:
|
---|
79 | uint16_t width;
|
---|
80 | uint16_t height;
|
---|
81 | Format format;
|
---|
82 | };
|
---|
83 |
|
---|
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);
|
---|
100 |
|
---|
101 | /*!
|
---|
102 | * \brief Destructor
|
---|
103 | *
|
---|
104 | */
|
---|
105 | ~cvimage();
|
---|
106 |
|
---|
107 |
|
---|
108 | char *buffer;
|
---|
109 |
|
---|
110 | Type const &GetDataType() const { return dataType; };
|
---|
111 |
|
---|
112 | static void RegisterAllocFunction(char*(*func)(ssize_t size));
|
---|
113 | static void RegisterFreeFunction(void(*func)(char* buffer));
|
---|
114 |
|
---|
115 | private:
|
---|
116 | /*!
|
---|
117 | * \brief Raw read datas
|
---|
118 | *
|
---|
119 | * Reimplemented from io_data. \n
|
---|
120 | * See io_data::RawRead.
|
---|
121 | *
|
---|
122 | * \param dst destination buffer
|
---|
123 | */
|
---|
124 | void RawRead(char *dst) const;
|
---|
125 |
|
---|
126 | bool allocate_data;
|
---|
127 | Type dataType;
|
---|
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 |
|
---|
133 | };
|
---|
134 |
|
---|
135 | } // end namespace core
|
---|
136 | } // end namespace flair
|
---|
137 |
|
---|
138 | #endif // CVIMAGE_H
|
---|