3DiVi Face SDK  3.24.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
RawSample.h
1 
9 #ifndef __PBIO_API__PBIO__RAW_SAMPLE_H_
10 #define __PBIO_API__PBIO__RAW_SAMPLE_H_
11 
12 
13 #include <ostream>
14 
15 #include "ComplexObject.h"
16 #include "ExceptionCheck.h"
17 #include "Point.h"
18 #include "RawImage.h"
19 #ifndef WITHOUT_PROCESSING_BLOCK
20 #include "pbio/Context.h"
21 #endif
22 #include "SmartPtr.h"
23 #include "stl_wraps_impls/WrapOStreamImpl.h"
24 #include "stl_wraps_impls/WrapVectorImpl.h"
25 
26 
27 namespace pbio
28 {
29 class AgeGenderEstimator;
30 class Capturer;
31 class FacerecService;
32 class LivenessEstimator;
33 class QualityEstimator;
34 class FaceQualityEstimator;
35 class Recognizer;
36 class VideoWorker;
37 class EmotionsEstimator;
38 class DepthLivenessEstimator;
39 class IRLivenessEstimator;
40 class Liveness2DEstimator;
41 class FaceAttributesEstimator;
42 class RawSampleExtractor;
43 
49 class RawSample : public ComplexObject
50 {
51 public:
52 
59 
66  {
73 
80 
87  };
88 
95  {
102 
109 
116 
123  };
124 
131  {
138 
145 
152  };
153 
160 
167 
173  struct Angles
174  {
180  float yaw;
181 
187  float pitch;
188 
194  float roll;
195  };
196 
197 
213  Rectangle getRectangle() const;
214 
215 
231  std::vector<Point> getLandmarks() const;
232 
233 
249  std::vector<Point> getIrisLandmarks() const;
250 
251 
267  Point getLeftEye() const;
268 
269 
285  Point getRightEye() const;
286 
302  Angles getAngles() const;
303 
304 
322  int getID() const;
323 
324 
350  int getFrameID() const;
351 
352 
373  bool hasOriginalImage() const;
374 
396  float getScore() const;
397 
423  float getFaceVisibilityScore() const;
424 
462  void getOriginalImage(
463  int &rows,
464  int &cols,
465  IRawImage::Format &format,
466  void const* &data) const;
467 
483  SampleType getType() const;
484 
485 
486 
508  std::vector<Point> getFaceCutRectangle(FaceCutType cut_type) const;
509 
510 
540  void cutFaceImage(
541  std::ostream &binary_stream,
542  ImageFormat format,
543  FaceCutType cut_type) const;
544 
545 
572  RawImage::Format color_model,
573  FaceCutType cut_type) const;
574 
604  void cutFaceImage(
605  pbio::stl_wraps::WrapOStream &binary_stream,
606  ImageFormat format,
607  FaceCutType cut_type) const;
608 
644  void cutFaceImage(
645  const RawImage original_image,
646  std::ostream &binary_stream,
647  ImageFormat format,
648  FaceCutType cut_type) const;
649 
685  void cutFaceImage(
686  const RawImage original_image,
687  pbio::stl_wraps::WrapOStream &binary_stream,
688  ImageFormat format,
689  FaceCutType cut_type) const;
690 
724  void save(std::ostream &binary_stream, ImageFormat format) const;
725 
759  void save(pbio::stl_wraps::WrapOStream &binary_stream, ImageFormat format) const;
760 
761 
816  void saveWithoutImage(
817  pbio::stl_wraps::WrapOStream &binary_stream,
818  const double space_translation_x = 0,
819  const double space_translation_y = 0,
820  const double space_scale = 1) const;
821 
825  void saveWithoutImage(
826  std::ostream &binary_stream,
827  const double space_translation_x = 0,
828  const double space_translation_y = 0,
829  const double space_scale = 1) const;
830 
831 
863 
864 #ifndef WITHOUT_PROCESSING_BLOCK
865 
873  pbio::Context toContext() const;
874 #endif
875 
877  void* getPtr() const;
879 
880 private:
881 
882  RawSample(
883  const DHPtr &dll_handle,
884  void* impl);
885 
886  friend class AgeGenderEstimator;
887  friend class Capturer;
888  friend class FacerecService;
889  friend class LivenessEstimator;
890  friend class QualityEstimator;
891  friend class FaceQualityEstimator;
892  friend class Recognizer;
893  friend class VideoWorker;
894  friend class EmotionsEstimator;
895  friend class DepthLivenessEstimator;
896  friend class IRLivenessEstimator;
897  friend class Liveness2DEstimator;
898  friend class FaceAttributesEstimator;
899  friend class RawSampleExtractor;
900  friend class object_with_ref_counter<RawSample>;
901 };
902 
903 } // pbio namespace
904 
905 
909 
910 namespace pbio
911 {
912 
913 inline
914 RawSample::RawSample(
915  const DHPtr &dll_handle,
916  void* impl):
917 ComplexObject(dll_handle, impl)
918 {
919  // nothing else
920 }
921 
922 
923 inline
925 {
926  Rectangle rectangle;
927 
928  void* exception = NULL;
929 
930  _dll_handle->RawSample_getRectangle(
931  _impl,
932  &rectangle.x,
933  &rectangle.y,
934  &rectangle.width,
935  &rectangle.height,
936  &exception);
937 
938  checkException(exception, *_dll_handle);
939 
940  return rectangle;
941 }
942 
943 
944 inline
945 std::vector<RawSample::Point> RawSample::getLandmarks() const
946 {
947  std::vector<float> coordinates;
948 
949  void* exception = NULL;
950 
951  _dll_handle->RawSample_getLandmarks(
952  _impl,
953  &coordinates,
954  pbio::stl_wraps::assign_floats_vector_func,
955  &exception);
956 
957  checkException(exception, *_dll_handle);
958 
959  std::vector<Point> points(coordinates.size() / 3);
960 
961  for(size_t i = 0; i < points.size(); ++i)
962  {
963  points[i].x = coordinates[i * 3 + 0];
964  points[i].y = coordinates[i * 3 + 1];
965  points[i].z = coordinates[i * 3 + 2];
966  }
967 
968  return points;
969 }
970 
971 
972 inline
973 std::vector<RawSample::Point> RawSample::getIrisLandmarks() const
974 {
975  std::vector<float> coordinates;
976 
977  void* exception = NULL;
978 
979  _dll_handle->RawSample_getIrisLandmarks(
980  _impl,
981  &coordinates,
982  pbio::stl_wraps::assign_floats_vector_func,
983  &exception);
984 
985  checkException(exception, *_dll_handle);
986 
987  std::vector<Point> points(coordinates.size() / 3);
988 
989  for(size_t i = 0; i < points.size(); ++i)
990  {
991  points[i].x = coordinates[i * 3 + 0];
992  points[i].y = coordinates[i * 3 + 1];
993  points[i].z = coordinates[i * 3 + 2];
994  }
995 
996  return points;
997 }
998 
999 
1000 inline
1002 {
1003  Point p;
1004 
1005  void* exception = NULL;
1006 
1007  _dll_handle->RawSample_getLeftEye(
1008  _impl,
1009  &p.x,
1010  &p.y,
1011  &exception);
1012 
1013  checkException(exception, *_dll_handle);
1014 
1015  return p;
1016 }
1017 
1018 inline
1020 {
1021  Point p;
1022 
1023  void* exception = NULL;
1024 
1025  _dll_handle->RawSample_getRightEye(
1026  _impl,
1027  &p.x,
1028  &p.y,
1029  &exception);
1030 
1031  checkException(exception, *_dll_handle);
1032 
1033  return p;
1034 }
1035 
1036 inline
1038 {
1039  Angles angles;
1040 
1041  void* exception = NULL;
1042 
1043  _dll_handle->RawSample_getAngles(
1044  _impl,
1045  &angles.yaw,
1046  &angles.pitch,
1047  &angles.roll,
1048  &exception);
1049 
1050  checkException(exception, *_dll_handle);
1051 
1052  return angles;
1053 }
1054 
1055 inline
1056 int RawSample::getID() const
1057 {
1058  void* exception = NULL;
1059 
1060  const int result = _dll_handle->RawSample_getID(
1061  _impl,
1062  &exception);
1063 
1064  checkException(exception, *_dll_handle);
1065 
1066  return result;
1067 }
1068 
1069 inline
1071 {
1072  void* exception = NULL;
1073 
1074  const int result = _dll_handle->RawSample_getFrameID(
1075  _impl,
1076  &exception);
1077 
1078  checkException(exception, *_dll_handle);
1079 
1080  return result;
1081 }
1082 
1083 
1084 inline
1086 {
1087  void* exception = NULL;
1088 
1089  const int result = _dll_handle->RawSample_getType(
1090  _impl,
1091  &exception);
1092 
1093  checkException(exception, *_dll_handle);
1094 
1095  return (SampleType) result;
1096 }
1097 
1098 
1099 inline
1100 std::vector<RawSample::Point> RawSample::getFaceCutRectangle(
1101  FaceCutType cut_type) const
1102 {
1103  void* exception = NULL;
1104 
1105  float corners[8];
1106 
1107  _dll_handle->RawSample_getFaceCutRectangle(
1108  _impl,
1109  int(cut_type),
1110  corners,
1111  &exception);
1112 
1113  checkException(exception, *_dll_handle);
1114 
1115  std::vector<RawSample::Point> result(4);
1116  for(int i = 0; i < 4; ++i)
1117  {
1118  result[i].x = corners[i * 2 + 0];
1119  result[i].y = corners[i * 2 + 1];
1120  }
1121 
1122  return result;
1123 }
1124 
1125 
1126 inline
1128  std::ostream &binary_stream,
1129  RawSample::ImageFormat format,
1130  RawSample::FaceCutType cut_type) const
1131 {
1132  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1133 
1134  cutFaceImage(binary_stream_wrap, format, cut_type);
1135 }
1136 
1137 inline
1139  RawImage::Format color_model,
1140  FaceCutType cut_type) const
1141 {
1142  int32_t width, height;
1143  std::ostringstream stream;
1144  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(stream);
1145 
1146  void* exception = NULL;
1147 
1148  _dll_handle->RawSample_cutFaceImage(
1149  _impl,
1150  &binary_stream_wrap,
1151  pbio::stl_wraps::WrapOStream::write_func,
1152  &width,
1153  &height,
1154  -1,
1155  int(color_model),
1156  int(cut_type),
1157  &exception);
1158 
1159  checkException(exception, *_dll_handle);
1160 
1161  pbio::RawImage result(
1162  width,
1163  height,
1164  color_model,
1165  (unsigned char*) stream.str().c_str(),
1166  stream.str().size());
1167 
1168  return result;
1169 }
1170 
1171 inline
1173  pbio::stl_wraps::WrapOStream &binary_stream,
1174  ImageFormat format,
1175  FaceCutType cut_type) const
1176 {
1177  void* exception = NULL;
1178 
1179  int32_t w, h;
1180 
1181  _dll_handle->RawSample_cutFaceImage(
1182  _impl,
1183  &binary_stream,
1184  pbio::stl_wraps::WrapOStream::write_func,
1185  &w,
1186  &h,
1187  int(format),
1188  -1,
1189  int(cut_type),
1190  &exception);
1191 
1192  checkException(exception, *_dll_handle);
1193 }
1194 
1195 
1196 inline
1198  const RawImage original_image,
1199  std::ostream &binary_stream,
1200  ImageFormat format,
1201  FaceCutType cut_type) const
1202 {
1203  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1204 
1205  cutFaceImage(
1206  original_image,
1207  binary_stream_wrap,
1208  format,
1209  cut_type);
1210 }
1211 
1212 inline
1214  const RawImage original_image,
1215  pbio::stl_wraps::WrapOStream &binary_stream,
1216  ImageFormat format,
1217  FaceCutType cut_type) const
1218 {
1219  void* exception = NULL;
1220 
1221  const RawImage::CapiData cdata = original_image.makeCapiData();
1222 
1223  _dll_handle->RawSample_cutFaceImage_original_raw_image_with_crop(
1224  _impl,
1225  cdata.data,
1226  cdata.width,
1227  cdata.height,
1228  cdata.format,
1229  cdata.with_crop,
1230  cdata.crop_info_offset_x,
1231  cdata.crop_info_offset_y,
1232  cdata.crop_info_data_image_width,
1233  cdata.crop_info_data_image_height,
1234  &binary_stream,
1235  pbio::stl_wraps::WrapOStream::write_func,
1236  int(format),
1237  int(cut_type),
1238  &exception);
1239 
1240  checkException(exception, *_dll_handle);
1241 }
1242 
1243 
1244 inline
1246  std::ostream &binary_stream,
1247  ImageFormat format) const
1248 {
1249  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1250 
1251  save(binary_stream_wrap, format);
1252 }
1253 
1254 inline
1256  pbio::stl_wraps::WrapOStream &binary_stream,
1257  ImageFormat format) const
1258 {
1259  void* exception = NULL;
1260 
1261  _dll_handle->RawSample_save(
1262  _impl,
1263  &binary_stream,
1264  pbio::stl_wraps::WrapOStream::write_func,
1265  int(format),
1266  &exception);
1267 
1268  checkException(exception, *_dll_handle);
1269 }
1270 
1271 
1272 
1273 inline
1275 {
1276  void* exception = NULL;
1277 
1278  const bool result = _dll_handle->RawSample_hasOriginalImage(
1279  _impl,
1280  &exception);
1281 
1282  checkException(exception, *_dll_handle);
1283 
1284  return result;
1285 }
1286 
1287 inline
1288 float RawSample::getScore() const
1289 {
1290  void* exception = NULL;
1291 
1292  const float result = _dll_handle->RawSample_getScore(
1293  _impl,
1294  &exception);
1295 
1296  checkException(exception, *_dll_handle);
1297 
1298  return result;
1299 
1300 }
1301 
1302 inline
1304 {
1305  void* exception = NULL;
1306 
1307  const float result = _dll_handle->RawSample_getFaceVisibilityScore(
1308  _impl,
1309  &exception);
1310 
1311  checkException(exception, *_dll_handle);
1312 
1313  return result;
1314 
1315 }
1316 
1317 
1318 inline
1320  int &rows,
1321  int &cols,
1322  IRawImage::Format &format,
1323  void const* &data) const
1324 {
1325  int32_t rows_, cols_, format_;
1326 
1327  void* exception = NULL;
1328 
1329  _dll_handle->RawSample_getOriginalImage(
1330  _impl,
1331  &rows_,
1332  &cols_,
1333  &format_,
1334  &data,
1335  &exception);
1336 
1337  checkException(exception, *_dll_handle);
1338 
1339  rows = rows_;
1340  cols = cols_;
1341  format = (IRawImage::Format) format_;
1342 }
1343 
1344 
1345 inline
1347 {
1348  void* exception = NULL;
1349 
1350  pbio::facerec::RawSampleImpl* const raw_sampl_impl =
1351  _dll_handle->RawSample_downscaleToPreferredSize(
1352  _impl,
1353  &exception);
1354 
1355  checkException(exception, *_dll_handle);
1356 
1357  return RawSample::Ptr::make(_dll_handle, raw_sampl_impl);
1358 }
1359 
1360 #ifndef WITHOUT_PROCESSING_BLOCK
1361 inline
1363 {
1364  void* exception = NULL;
1365 
1366  HContext* handle = _dll_handle->RawSample_toContext(
1367  _impl,
1368  &exception);
1369 
1370  checkException(exception, *_dll_handle);
1371 
1372  return pbio::Context(_dll_handle, handle, false);
1373 }
1374 #endif
1375 
1376 
1377 inline
1379  pbio::stl_wraps::WrapOStream &binary_stream,
1380  const double space_translation_x,
1381  const double space_translation_y,
1382  const double space_scale) const
1383 {
1384  void* exception = NULL;
1385 
1386  _dll_handle->RawSample_save_without_image(
1387  _impl,
1388  &binary_stream,
1389  pbio::stl_wraps::WrapOStream::write_func,
1390  space_translation_x,
1391  space_translation_y,
1392  space_scale,
1393  &exception);
1394 
1395  checkException(exception, *_dll_handle);
1396 }
1397 
1398 inline
1400  std::ostream &binary_stream,
1401  const double space_translation_x,
1402  const double space_translation_y,
1403  const double space_scale) const
1404 {
1405  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1406 
1408  binary_stream_wrap,
1409  space_translation_x,
1410  space_translation_y,
1411  space_scale);
1412 }
1413 
1414 inline
1415 void* RawSample::getPtr() const
1416 {
1417  return _impl;
1418 }
1419 
1420 
1421 } // pbio namespace
1422 
1423 
1424 
1425 #endif // __PBIO_API__PBIO__RAW_SAMPLE_H_
int width
Width of the rectangle.
Definition: Rectangle.h:47
RawImage cutFaceRawImage(RawImage::Format color_model, FaceCutType cut_type) const
Crop face in RawImage format (with raw pixels). Thread-safe.
Definition: RawSample.h:1138
std::vector< Point > getFaceCutRectangle(FaceCutType cut_type) const
Get a cropping rectangle (for preview) that will be used in cutFaceImage. Thread-safe.
Definition: RawSample.h:1100
Interface object for sample quality estimation.
Definition: FaceQualityEstimator.h:41
Struct that provides raw image data and optional cropping information.
Definition: RawImage.h:28
ISO/IEC 19794-5 Token Frontal (fixed eye positions) (only frontal sample type).
Definition: RawSample.h:151
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 used to estimate attributes of the face.
Definition: FaceAttributesEstimator.h:28
Interface object used to estimate face liveness in order to prevent spoofing attacks.
Definition: Liveness2DEstimator.h:41
BMP (no compression).
Definition: RawSample.h:122
Interface object used to estimate face liveness to prevent spoofing attacks.
Definition: LivenessEstimator.h:33
Interface object that stores a captured face sample.
Definition: RawSample.h:49
SampleType
Sample types (see also Capturer::CapturerType).
Definition: RawSample.h:65
Interface object used to estimate face liveness in order to prevent spoofing attacks.
Definition: DepthLivenessEstimator.h:34
pbio::Point Point
2D point.
Definition: RawSample.h:166
void getOriginalImage(int &rows, int &cols, IRawImage::Format &format, void const *&data) const
Get an original image. Throws an exception if a sample doesn’t contain an original image (check with ...
Definition: RawSample.h:1319
JPEG (lossy compression).
Definition: RawSample.h:101
float getFaceVisibilityScore() const
Get the score of face visibility. Thread-safe.
Definition: RawSample.h:1303
std::vector< Point > getLandmarks() const
Get anthropometric landmarks. Only frontal samples. Thread-safe.
Definition: RawSample.h:945
The face is right-profile-oriented.
Definition: RawSample.h:86
float x
X coordinate.
Definition: Point.h:19
Definition: Recognizer.h:64
Interface object for creating and matching templates.
Definition: Recognizer.h:37
ImageFormat
Image formats for saving.
Definition: RawSample.h:94
LightSmartPtr< RawSample >::tPtr Ptr
Alias for the type of a smart pointer to RawSample.
Definition: RawSample.h:58
Angles getAngles() const
Get a face orientation. Only frontal samples. Thread-safe.
Definition: RawSample.h:1037
SampleType getType() const
Get a sample type. Thread-safe.
Definition: RawSample.h:1085
ISO/IEC 19794-5 Full Frontal (for ID, travel documents) (only frontal sample type).
Definition: RawSample.h:144
Rectangle getRectangle() const
Get a face bounding rectangle. Thread-safe.
Definition: RawSample.h:924
3D point.
Definition: Point.h:12
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
void save(std::ostream &binary_stream, ImageFormat format) const
Save (serialize) the sample. Original image will not be saved (i.e. only the part of an image contain...
Definition: RawSample.h:1245
void saveWithoutImage(pbio::stl_wraps::WrapOStream &binary_stream, const double space_translation_x=0, const double space_translation_y=0, const double space_scale=1) const
Save (serialize) all sample information except the image. You have to store the image on your own in ...
Definition: RawSample.h:1378
float yaw
Yaw angle in degrees.
Definition: RawSample.h:180
pbio::Rectangle Rectangle
Rectangle in an image.
Definition: RawSample.h:159
Definition: SmartPtr.h:84
std::vector< Point > getIrisLandmarks() const
Get the characteristic points of the eyes. Only frontal samples. Thread-safe.
Definition: RawSample.h:973
Rectangle in an image.
Definition: Rectangle.h:12
float y
Y coordinate.
Definition: Point.h:26
The face is frontal-oriented.
Definition: RawSample.h:72
Interface object for age and gender estimation.
Definition: AgeGenderEstimator.h:46
Point getRightEye() const
Get a point of the right eye. Only frontal samples. Thread-safe.
Definition: RawSample.h:1019
Interface object used to estimate sample quality.
Definition: QualityEstimator.h:41
int getFrameID() const
Get an ID of the frame, in which this RawSample is detected (for samples made with VideoWorker)...
Definition: RawSample.h:1070
Interface object for detecting or tracking of faces in the images or video sequences.
Definition: Capturer.h:16
Face orientation angles.
Definition: RawSample.h:173
VideoWorker is an interface object for tracking, processing and matching faces on multiple video stre...
Definition: VideoWorker.h:105
TIFF (lossless compression).
Definition: RawSample.h:115
Interface object for detecting or tracking of faces in the images or video sequences.
Definition: Capturer.h:36
pbio::Context toContext() const
will transform RawSample into a container-Context
Definition: RawSample.h:1362
FaceCutType
Face cropping types.
Definition: RawSample.h:130
float roll
Roll angle in degrees.
Definition: RawSample.h:194
Context is an interface object for storing data and interacting with methods from the Processing Bloc...
Definition: Context.h:51
Point getLeftEye() const
Get a point of the left eye. Only frontal samples. Thread-safe.
Definition: RawSample.h:1001
SmartPtr.
The face is left-profile-oriented.
Definition: RawSample.h:79
float pitch
Pitch angle in degrees.
Definition: RawSample.h:187
int y
Y coordinate of the top-left corner.
Definition: Rectangle.h:40
float getScore() const
Get the score of the detected face (for samples made with supported single-shot Capturers). Thread-safe.
Definition: RawSample.h:1288
Definition: FacerecService.mm:79
RawSample::Ptr downscaleToPreferredSize() const
Clone this RawSample with an internal face image downscaled to suitable size and without an original ...
Definition: RawSample.h:1346
int getID() const
Get a face ID. Thread-safe.
Definition: RawSample.h:1056
Format
Format of image data.
Definition: IRawImage.h:46
PNG (lossless compression).
Definition: RawSample.h:108
void cutFaceImage(std::ostream &binary_stream, ImageFormat format, FaceCutType cut_type) const
Crop the face and save in the specified format. Thread-safe.
Definition: RawSample.h:1127
Interface object used to estimate face liveness in order to prevent spoofing attacks.
Definition: IRLivenessEstimator.h:34
Unspecified cropping (any sample type).
Definition: RawSample.h:137
bool hasOriginalImage() const
Does the sample store the original image (true for samples made with VideoWorker with enabled store_o...
Definition: RawSample.h:1274
Interface object for estimation of emotions.
Definition: EmotionsEstimator.h:41