3DiVi Face SDK  3.24.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
CVRawImage.h
Go to the documentation of this file.
1 
9 #ifndef __PBIO_API__PBIO__EXAMPLE__CV_RAW_IMAGE_H_
10 #define __PBIO_API__PBIO__EXAMPLE__CV_RAW_IMAGE_H_
11 
12 #include <opencv2/opencv.hpp>
13 
14 #include "pbio/IRawImage.h"
15 
16 namespace pbio
17 {
18 
29 {
30 public:
31 
37 
42  virtual ~CVRawImage(){}
43 
61  virtual const unsigned char* data() const;
62 
63 
79  virtual int32_t width() const;
80 
96  virtual int32_t height() const;
97 
98 
118  virtual int32_t format() const;
119 
120 
136  cv::Mat& mat();
137 
138 
154  const cv::Mat& mat() const;
155 
156 
157 private:
162  cv::Mat _mat;
163 };
164 
165 } // pbio namespace
166 
167 
168 
172 
173 
174 namespace pbio
175 {
176 
177 inline
178 const unsigned char* CVRawImage::data() const
179 {
180  if( _mat.empty() ||
181  _mat.dims != 2 ||
182  ( _mat.type() != CV_8UC1 && _mat.type() != CV_8UC3 ) ||
183  !_mat.isContinuous() )
184  {
185  return NULL;
186  }
187 
188  return _mat.data;
189 }
190 
191 inline
192 int32_t CVRawImage::width() const
193 {
194  return _mat.cols;
195 }
196 
197 
198 inline
199 int32_t CVRawImage::height() const
200 {
201  return _mat.rows;
202 }
203 
204 
205 inline
206 int32_t CVRawImage::format() const
207 {
208  if(_mat.type() == CV_8UC1)
209  {
210  return (int32_t) FORMAT_GRAY;
211  }
212 
213  if(_mat.type() == CV_8UC3)
214  {
215  return (int32_t) FORMAT_BGR;
216  }
217 
218  return -1;
219 }
220 
221 
222 
223 inline
224 cv::Mat& CVRawImage::mat()
225 {
226  return _mat;
227 }
228 
229 inline
230 const cv::Mat& CVRawImage::mat() const
231 {
232  return _mat;
233 }
234 
235 } // pbio namespace
236 
237 #endif // __PBIO_API__PBIO__EXAMPLE__CV_RAW_IMAGE_H_
virtual ~CVRawImage()
Virtual destructor.
Definition: CVRawImage.h:42
Example of implementation of the pbio::IRawImage interface via OpenCV.
Definition: CVRawImage.h:28
virtual int32_t format() const
Get an image format.
Definition: CVRawImage.h:206
Grayscale, 8 bit per pixel.
Definition: IRawImage.h:53
IRawImage - Raw image interface.
BGR, 24 bit per pixel, 8 bit per channel.
Definition: IRawImage.h:67
Raw image interface. To use this interface, you need to inherit it and create your own implementation...
Definition: IRawImage.h:30
virtual int32_t width() const
Get an image width.
Definition: CVRawImage.h:192
cv::Mat & mat()
Get a reference to the stored cv::Mat object.
Definition: CVRawImage.h:224
CVRawImage()
Contructor.
Definition: CVRawImage.h:36
virtual const unsigned char * data() const
Get a pointer to the image data buffer.
Definition: CVRawImage.h:178
virtual int32_t height() const
Get an image height.
Definition: CVRawImage.h:199