3DiVi Face SDK  3.21.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
RawImage.h
1 #ifndef __PBIO_API__PBIO__RAW_IMAGE_H_409ecb3ab16c416ea44ca0828ae7d624
2 #define __PBIO_API__PBIO__RAW_IMAGE_H_409ecb3ab16c416ea44ca0828ae7d624
3 
4 #include <cstring>
5 #include <vector>
6 
7 #include "IRawImage.h"
8 #include "Rectangle.h"
9 #include "InternalImageBuffer.h"
10 
11 namespace pbio
12 {
13 
14 class RawSample;
15 class CameraCalibrator;
16 class Capturer;
17 class VideoWorker;
18 class FacerecService;
19 
28 struct RawImage
29 {
30 public:
31 
39 
46  RawImage();
47 
48 
55  RawImage(const IRawImage&);
56 
64 
71  RawImage(
72  const int width,
73  const int height,
74  const Format format,
75  unsigned char const* data,
76  std::size_t size = 0); // if size is passed, data will be copied to internal buffer
77 
87  RawImage crop(
88  const Rectangle rectangle) const;
89 
101  unsigned char const* data;
102 
109  int width;
110 
117  int height;
118 
126 
127 
134  bool with_crop;
135 
143 
151 
159 
167 
168 
169 
170 
171 private:
172 
173  struct CapiData
174  {
175  void const* data;
176  int width;
177  int height;
178  int format;
179  int with_crop;
180  int crop_info_offset_x;
181  int crop_info_offset_y;
184  };
185 
186  CapiData makeCapiData() const;
187 
188  // if not empty then, data is owned by this buffer
189  InternalImageBuffer::Ptr internal_image_buffer;
190 
191  std::vector<unsigned char> buffer;
192 
193  friend class RawSample;
194  friend class CameraCalibrator;
195  friend class Capturer;
196  friend class VideoWorker;
197  friend class FacerecService;
198 };
199 
200 
201 
202 inline
204 : data(NULL)
205 , width(0)
206 , height(0)
207 , format((Format) -1)
208 , with_crop(false)
209 , crop_info_offset_x(-1)
210 , crop_info_offset_y(-1)
211 , crop_info_data_image_width(-1)
212 , crop_info_data_image_height(-1)
213 {
214  // nothing else
215 }
216 
217 inline
219 : data(a.data())
220 , width(a.width())
221 , height(a.height())
222 , format((Format) a.format())
223 , with_crop(false)
224 , crop_info_offset_x(-1)
225 , crop_info_offset_y(-1)
226 , crop_info_data_image_width(-1)
227 , crop_info_data_image_height(-1)
228 {
229  // nothing else
230 }
231 
232 inline
234 : data(a->data)
235 , width(a->width)
236 , height(a->height)
237 , format(a->format)
238 , with_crop(false)
239 , crop_info_offset_x(-1)
240 , crop_info_offset_y(-1)
241 , crop_info_data_image_width(-1)
242 , crop_info_data_image_height(-1)
243 , internal_image_buffer(a)
244 {
245  // nothing else
246 }
247 
248 
249 inline
251  const int width,
252  const int height,
253  const Format format,
254  unsigned char const* data,
255  const std::size_t size)
256 : width(width)
257 , height(height)
258 , format(format)
259 , with_crop(false)
260 , crop_info_offset_x(-1)
261 , crop_info_offset_y(-1)
262 , crop_info_data_image_width(-1)
263 , crop_info_data_image_height(-1)
264 {
265  if (size) {
266  buffer.resize(size);
267  memcpy(&buffer[0], data, size);
268  this->data = buffer.data();
269  }else{
270  this->data = data;
271  }
272 }
273 
274 
275 
276 inline
278  const Rectangle rectangle) const
279 {
280  const int offset_x = with_crop ? crop_info_offset_x : 0;
281  const int offset_y = with_crop ? crop_info_offset_y : 0;
282  const int data_width = with_crop ? crop_info_data_image_width : width;
283  const int data_height = with_crop ? crop_info_data_image_height : height;
284 
285  RawImage result = *this;
286 
287  result.width = rectangle.width;
288  result.height = rectangle.height;
289 
290  result.with_crop = true;
291  result.crop_info_offset_x = rectangle.x + offset_x;
292  result.crop_info_offset_y = rectangle.y + offset_y;
293  result.crop_info_data_image_width = data_width;
294  result.crop_info_data_image_height = data_height;
295 
296  return result;
297 }
298 
299 
300 
301 inline
302 RawImage::CapiData RawImage::makeCapiData() const
303 {
304  CapiData result;
305  result.data = data;
306  result.width = width;
307  result.height = height;
308  result.format = format;
309  result.with_crop = with_crop;
310  result.crop_info_offset_x = crop_info_offset_x;
311  result.crop_info_offset_y = crop_info_offset_y;
312  result.crop_info_data_image_width = crop_info_data_image_width;
313  result.crop_info_data_image_height = crop_info_data_image_height;
314 
315  PBI0x3dfb4fe3Assert(0x02a169c4, data, "RawImage with NULL data used");
316 
317  if(internal_image_buffer)
318  {
319  PBI0x3dfb4fe3Assert(0xb0be4ddd, data == internal_image_buffer->data,
320  "RawImage data does not match corresponding InternalImageBuffer");
321 
322  PBI0x3dfb4fe3Assert(0x951aadf1, width == internal_image_buffer->width,
323  "RawImage width does not match corresponding InternalImageBuffer");
324 
325  PBI0x3dfb4fe3Assert(0x88d7c6fc, height == internal_image_buffer->height,
326  "RawImage height does not match corresponding InternalImageBuffer");
327 
328  PBI0x3dfb4fe3Assert(0xd7008c02, format == internal_image_buffer->format,
329  "RawImage format does not match corresponding InternalImageBuffer");
330 
331  result.format |= InternalImageBuffer::FORMAT_FLAG__DATA_IMAGET;
332 
333  result.data = internal_image_buffer->imagetptr_ptr;
334  }
335 
336  return result;
337 }
338 
339 
340 } // pbio namespace
341 
342 #endif // __PBIO_API__PBIO__RAW_IMAGE_H_409ecb3ab16c416ea44ca0828ae7d624
int width
Width of the rectangle.
Definition: Rectangle.h:47
int crop_info_offset_x
Cropping offset along the x axis. This value is set in the RawImage::crop member function.
Definition: RawImage.h:142
Struct that provides raw image data and optional cropping information.
Definition: RawImage.h:28
Interface object for creating other interface objects.
Definition: FacerecService.h:64
int x
X coordinate of the top-left corner.
Definition: Rectangle.h:33
Interface object that stores a captured face sample.
Definition: RawSample.h:49
LightSmartPtr< InternalImageBuffer >::tPtr Ptr
Alias for the type of a smart pointer to InternalImageBuffer.
Definition: InternalImageBuffer.h:34
int crop_info_data_image_width
Image width before RawImage::crop. This value is set in the RawImage::crop member function...
Definition: RawImage.h:158
IRawImage - Raw image interface.
pbio::IRawImage::Format Format
Format of image data.
Definition: RawImage.h:38
int width
Image width.
Definition: RawImage.h:109
bool with_crop
Flag, which indicates that croppping info is initialized. This value is set in the RawImage::crop mem...
Definition: RawImage.h:134
int crop_info_offset_y
Cropping offset along the y axis. This value is set in the RawImage::crop member function.
Definition: RawImage.h:150
Format format
Format of image data.
Definition: RawImage.h:125
VideoWorker is an interface object for tracking, processing and matching faces on multiple video stre...
Definition: VideoWorker.h:63
int height
Height of the rectangle.
Definition: Rectangle.h:54
Raw image interface. To use this interface, you need to inherit it and create your own implementation...
Definition: IRawImage.h:30
unsigned char const * data
Pointer to the image data buffer. All pixels must be stored continuously, row by row, without gaps at the end of each row.
Definition: RawImage.h:101
Rectangle in an image.
Definition: Rectangle.h:12
RawImage()
Default constructor.
Definition: RawImage.h:203
int crop_info_data_image_height
Image height before RawImage::crop. This value is set in the RawImage::crop member function...
Definition: RawImage.h:166
int height
Image height.
Definition: RawImage.h:117
Interface object for detecting or tracking of faces in the images or video sequences.
Definition: Capturer.h:36
RawImage crop(const Rectangle rectangle) const
Create RawImage that represents the specified rectangle area of this image.
Definition: RawImage.h:277
Interface object for camera calibration and correction of image distortion.
Definition: CameraCalibrator.h:39
int y
Y coordinate of the top-left corner.
Definition: Rectangle.h:40
Format
Format of image data.
Definition: IRawImage.h:46