3DiVi Face SDK  3.21.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups
RawSample.h
Go to the documentation of this file.
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 "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  Context toContext() const;
866 #endif
867 
869  void* getPtr() const;
871 
872 private:
873 
874  RawSample(
875  const DHPtr &dll_handle,
876  void* impl);
877 
878  friend class AgeGenderEstimator;
879  friend class Capturer;
880  friend class FacerecService;
881  friend class LivenessEstimator;
882  friend class QualityEstimator;
883  friend class FaceQualityEstimator;
884  friend class Recognizer;
885  friend class VideoWorker;
886  friend class EmotionsEstimator;
887  friend class DepthLivenessEstimator;
888  friend class IRLivenessEstimator;
889  friend class Liveness2DEstimator;
890  friend class FaceAttributesEstimator;
891  friend class RawSampleExtractor;
892  friend class object_with_ref_counter<RawSample>;
893 };
894 
895 } // pbio namespace
896 
897 
901 
902 namespace pbio
903 {
904 
905 inline
906 RawSample::RawSample(
907  const DHPtr &dll_handle,
908  void* impl):
909 ComplexObject(dll_handle, impl)
910 {
911  // nothing else
912 }
913 
914 
915 inline
917 {
918  Rectangle rectangle;
919 
920  void* exception = NULL;
921 
922  _dll_handle->RawSample_getRectangle(
923  _impl,
924  &rectangle.x,
925  &rectangle.y,
926  &rectangle.width,
927  &rectangle.height,
928  &exception);
929 
930  checkException(exception, *_dll_handle);
931 
932  return rectangle;
933 }
934 
935 
936 inline
937 std::vector<RawSample::Point> RawSample::getLandmarks() const
938 {
939  std::vector<float> coordinates;
940 
941  void* exception = NULL;
942 
943  _dll_handle->RawSample_getLandmarks(
944  _impl,
945  &coordinates,
946  pbio::stl_wraps::assign_floats_vector_func,
947  &exception);
948 
949  checkException(exception, *_dll_handle);
950 
951  std::vector<Point> points(coordinates.size() / 3);
952 
953  for(size_t i = 0; i < points.size(); ++i)
954  {
955  points[i].x = coordinates[i * 3 + 0];
956  points[i].y = coordinates[i * 3 + 1];
957  points[i].z = coordinates[i * 3 + 2];
958  }
959 
960  return points;
961 }
962 
963 
964 inline
965 std::vector<RawSample::Point> RawSample::getIrisLandmarks() const
966 {
967  std::vector<float> coordinates;
968 
969  void* exception = NULL;
970 
971  _dll_handle->RawSample_getIrisLandmarks(
972  _impl,
973  &coordinates,
974  pbio::stl_wraps::assign_floats_vector_func,
975  &exception);
976 
977  checkException(exception, *_dll_handle);
978 
979  std::vector<Point> points(coordinates.size() / 3);
980 
981  for(size_t i = 0; i < points.size(); ++i)
982  {
983  points[i].x = coordinates[i * 3 + 0];
984  points[i].y = coordinates[i * 3 + 1];
985  points[i].z = coordinates[i * 3 + 2];
986  }
987 
988  return points;
989 }
990 
991 
992 inline
994 {
995  Point p;
996 
997  void* exception = NULL;
998 
999  _dll_handle->RawSample_getLeftEye(
1000  _impl,
1001  &p.x,
1002  &p.y,
1003  &exception);
1004 
1005  checkException(exception, *_dll_handle);
1006 
1007  return p;
1008 }
1009 
1010 inline
1012 {
1013  Point p;
1014 
1015  void* exception = NULL;
1016 
1017  _dll_handle->RawSample_getRightEye(
1018  _impl,
1019  &p.x,
1020  &p.y,
1021  &exception);
1022 
1023  checkException(exception, *_dll_handle);
1024 
1025  return p;
1026 }
1027 
1028 inline
1030 {
1031  Angles angles;
1032 
1033  void* exception = NULL;
1034 
1035  _dll_handle->RawSample_getAngles(
1036  _impl,
1037  &angles.yaw,
1038  &angles.pitch,
1039  &angles.roll,
1040  &exception);
1041 
1042  checkException(exception, *_dll_handle);
1043 
1044  return angles;
1045 }
1046 
1047 inline
1048 int RawSample::getID() const
1049 {
1050  void* exception = NULL;
1051 
1052  const int result = _dll_handle->RawSample_getID(
1053  _impl,
1054  &exception);
1055 
1056  checkException(exception, *_dll_handle);
1057 
1058  return result;
1059 }
1060 
1061 inline
1063 {
1064  void* exception = NULL;
1065 
1066  const int result = _dll_handle->RawSample_getFrameID(
1067  _impl,
1068  &exception);
1069 
1070  checkException(exception, *_dll_handle);
1071 
1072  return result;
1073 }
1074 
1075 
1076 inline
1078 {
1079  void* exception = NULL;
1080 
1081  const int result = _dll_handle->RawSample_getType(
1082  _impl,
1083  &exception);
1084 
1085  checkException(exception, *_dll_handle);
1086 
1087  return (SampleType) result;
1088 }
1089 
1090 
1091 inline
1092 std::vector<RawSample::Point> RawSample::getFaceCutRectangle(
1093  FaceCutType cut_type) const
1094 {
1095  void* exception = NULL;
1096 
1097  float corners[8];
1098 
1099  _dll_handle->RawSample_getFaceCutRectangle(
1100  _impl,
1101  int(cut_type),
1102  corners,
1103  &exception);
1104 
1105  checkException(exception, *_dll_handle);
1106 
1107  std::vector<RawSample::Point> result(4);
1108  for(int i = 0; i < 4; ++i)
1109  {
1110  result[i].x = corners[i * 2 + 0];
1111  result[i].y = corners[i * 2 + 1];
1112  }
1113 
1114  return result;
1115 }
1116 
1117 
1118 inline
1120  std::ostream &binary_stream,
1121  RawSample::ImageFormat format,
1122  RawSample::FaceCutType cut_type) const
1123 {
1124  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1125 
1126  cutFaceImage(binary_stream_wrap, format, cut_type);
1127 }
1128 
1129 inline
1131  RawImage::Format color_model,
1132  FaceCutType cut_type) const
1133 {
1134  int32_t width, height;
1135  std::ostringstream stream;
1136  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(stream);
1137 
1138  void* exception = NULL;
1139 
1140  _dll_handle->RawSample_cutFaceImage(
1141  _impl,
1142  &binary_stream_wrap,
1143  pbio::stl_wraps::WrapOStream::write_func,
1144  &width,
1145  &height,
1146  -1,
1147  int(color_model),
1148  int(cut_type),
1149  &exception);
1150 
1151  checkException(exception, *_dll_handle);
1152 
1153  pbio::RawImage result(
1154  width,
1155  height,
1156  color_model,
1157  (unsigned char*) stream.str().c_str(),
1158  stream.str().size());
1159 
1160  return result;
1161 }
1162 
1163 inline
1165  pbio::stl_wraps::WrapOStream &binary_stream,
1166  ImageFormat format,
1167  FaceCutType cut_type) const
1168 {
1169  void* exception = NULL;
1170 
1171  int32_t w, h;
1172 
1173  _dll_handle->RawSample_cutFaceImage(
1174  _impl,
1175  &binary_stream,
1176  pbio::stl_wraps::WrapOStream::write_func,
1177  &w,
1178  &h,
1179  int(format),
1180  -1,
1181  int(cut_type),
1182  &exception);
1183 
1184  checkException(exception, *_dll_handle);
1185 }
1186 
1187 
1188 inline
1190  const RawImage original_image,
1191  std::ostream &binary_stream,
1192  ImageFormat format,
1193  FaceCutType cut_type) const
1194 {
1195  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1196 
1197  cutFaceImage(
1198  original_image,
1199  binary_stream_wrap,
1200  format,
1201  cut_type);
1202 }
1203 
1204 inline
1206  const RawImage original_image,
1207  pbio::stl_wraps::WrapOStream &binary_stream,
1208  ImageFormat format,
1209  FaceCutType cut_type) const
1210 {
1211  void* exception = NULL;
1212 
1213  const RawImage::CapiData cdata = original_image.makeCapiData();
1214 
1215  _dll_handle->RawSample_cutFaceImage_original_raw_image_with_crop(
1216  _impl,
1217  cdata.data,
1218  cdata.width,
1219  cdata.height,
1220  cdata.format,
1221  cdata.with_crop,
1222  cdata.crop_info_offset_x,
1223  cdata.crop_info_offset_y,
1224  cdata.crop_info_data_image_width,
1225  cdata.crop_info_data_image_height,
1226  &binary_stream,
1227  pbio::stl_wraps::WrapOStream::write_func,
1228  int(format),
1229  int(cut_type),
1230  &exception);
1231 
1232  checkException(exception, *_dll_handle);
1233 }
1234 
1235 
1236 inline
1238  std::ostream &binary_stream,
1239  ImageFormat format) const
1240 {
1241  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1242 
1243  save(binary_stream_wrap, format);
1244 }
1245 
1246 inline
1248  pbio::stl_wraps::WrapOStream &binary_stream,
1249  ImageFormat format) const
1250 {
1251  void* exception = NULL;
1252 
1253  _dll_handle->RawSample_save(
1254  _impl,
1255  &binary_stream,
1256  pbio::stl_wraps::WrapOStream::write_func,
1257  int(format),
1258  &exception);
1259 
1260  checkException(exception, *_dll_handle);
1261 }
1262 
1263 
1264 
1265 inline
1267 {
1268  void* exception = NULL;
1269 
1270  const bool result = _dll_handle->RawSample_hasOriginalImage(
1271  _impl,
1272  &exception);
1273 
1274  checkException(exception, *_dll_handle);
1275 
1276  return result;
1277 }
1278 
1279 inline
1280 float RawSample::getScore() const
1281 {
1282  void* exception = NULL;
1283 
1284  const float result = _dll_handle->RawSample_getScore(
1285  _impl,
1286  &exception);
1287 
1288  checkException(exception, *_dll_handle);
1289 
1290  return result;
1291 
1292 }
1293 
1294 inline
1296 {
1297  void* exception = NULL;
1298 
1299  const float result = _dll_handle->RawSample_getFaceVisibilityScore(
1300  _impl,
1301  &exception);
1302 
1303  checkException(exception, *_dll_handle);
1304 
1305  return result;
1306 
1307 }
1308 
1309 
1310 inline
1312  int &rows,
1313  int &cols,
1314  IRawImage::Format &format,
1315  void const* &data) const
1316 {
1317  int32_t rows_, cols_, format_;
1318 
1319  void* exception = NULL;
1320 
1321  _dll_handle->RawSample_getOriginalImage(
1322  _impl,
1323  &rows_,
1324  &cols_,
1325  &format_,
1326  &data,
1327  &exception);
1328 
1329  checkException(exception, *_dll_handle);
1330 
1331  rows = rows_;
1332  cols = cols_;
1333  format = (IRawImage::Format) format_;
1334 }
1335 
1336 
1337 inline
1339 {
1340  void* exception = NULL;
1341 
1342  pbio::facerec::RawSampleImpl* const raw_sampl_impl =
1343  _dll_handle->RawSample_downscaleToPreferredSize(
1344  _impl,
1345  &exception);
1346 
1347  checkException(exception, *_dll_handle);
1348 
1349  return RawSample::Ptr::make(_dll_handle, raw_sampl_impl);
1350 }
1351 
1352 #ifndef WITHOUT_PROCESSING_BLOCK
1353 inline
1354 Context RawSample::toContext() const
1355 {
1356  void* exception = NULL;
1357 
1358  HContext* handle = _dll_handle->RawSample_toContext(
1359  _impl,
1360  &exception);
1361 
1362  checkException(exception, *_dll_handle);
1363 
1364  return Context(_dll_handle, handle, false);
1365 }
1366 #endif
1367 
1368 
1369 inline
1371  pbio::stl_wraps::WrapOStream &binary_stream,
1372  const double space_translation_x,
1373  const double space_translation_y,
1374  const double space_scale) const
1375 {
1376  void* exception = NULL;
1377 
1378  _dll_handle->RawSample_save_without_image(
1379  _impl,
1380  &binary_stream,
1381  pbio::stl_wraps::WrapOStream::write_func,
1382  space_translation_x,
1383  space_translation_y,
1384  space_scale,
1385  &exception);
1386 
1387  checkException(exception, *_dll_handle);
1388 }
1389 
1390 inline
1392  std::ostream &binary_stream,
1393  const double space_translation_x,
1394  const double space_translation_y,
1395  const double space_scale) const
1396 {
1397  pbio::stl_wraps::WrapOStreamImpl binary_stream_wrap(binary_stream);
1398 
1400  binary_stream_wrap,
1401  space_translation_x,
1402  space_translation_y,
1403  space_scale);
1404 }
1405 
1406 inline
1407 void* RawSample::getPtr() const
1408 {
1409  return _impl;
1410 }
1411 
1412 
1413 } // pbio namespace
1414 
1415 
1416 
1417 #endif // __PBIO_API__PBIO__RAW_SAMPLE_H_
int width
Width of the rectangle.
Definition: Rectangle.h:47
float getFaceVisibilityScore() const
Get the score of face visibility. Thread-safe.
Definition: RawSample.h:1295
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
float getScore() const
Get the score of the detected face (for samples made with supported single-shot Capturers). Thread-safe.
Definition: RawSample.h:1280
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
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:1092
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
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:1119
Rectangle getRectangle() const
Get a face bounding rectangle. Thread-safe.
Definition: RawSample.h:916
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
JPEG (lossy compression).
Definition: RawSample.h:101
The face is right-profile-oriented.
Definition: RawSample.h:86
float x
X coordinate.
Definition: Point.h:19
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:1311
SampleType getType() const
Get a sample type. Thread-safe.
Definition: RawSample.h:1077
Interface object for creating and matching templates.
Definition: Recognizer.h:37
RawSample::Ptr downscaleToPreferredSize() const
Clone this RawSample with an internal face image downscaled to suitable size and without an original ...
Definition: RawSample.h:1338
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
ISO/IEC 19794-5 Full Frontal (for ID, travel documents) (only frontal sample type).
Definition: RawSample.h:144
Point getRightEye() const
Get a point of the right eye. Only frontal samples. Thread-safe.
Definition: RawSample.h:1011
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
RawImage cutFaceRawImage(RawImage::Format color_model, FaceCutType cut_type) const
Crop face in RawImage format (with raw pixels). Thread-safe.
Definition: RawSample.h:1130
std::vector< Point > getIrisLandmarks() const
Get the characteristic points of the eyes. Only frontal samples. Thread-safe.
Definition: RawSample.h:965
int height
Height of the rectangle.
Definition: Rectangle.h:54
int getID() const
Get a face ID. Thread-safe.
Definition: RawSample.h:1048
float yaw
Yaw angle in degrees.
Definition: RawSample.h:180
std::vector< Point > getLandmarks() const
Get anthropometric landmarks. Only frontal samples. Thread-safe.
Definition: RawSample.h:937
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:1370
pbio::Rectangle Rectangle
Rectangle in an image.
Definition: RawSample.h:159
Definition: SmartPtr.h:84
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
Interface object used to estimate sample quality.
Definition: QualityEstimator.h:41
Face orientation angles.
Definition: RawSample.h:173
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
FaceCutType
Face cropping types.
Definition: RawSample.h:130
Point getLeftEye() const
Get a point of the left eye. Only frontal samples. Thread-safe.
Definition: RawSample.h:993
float roll
Roll angle in degrees.
Definition: RawSample.h:194
bool hasOriginalImage() const
Does the sample store the original image (true for samples made with VideoWorker with enabled store_o...
Definition: RawSample.h:1266
Definition: Context.h:37
SmartPtr.
The face is left-profile-oriented.
Definition: RawSample.h:79
float pitch
Pitch angle in degrees.
Definition: RawSample.h:187
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:1237
int y
Y coordinate of the top-left corner.
Definition: Rectangle.h:40
int getFrameID() const
Get an ID of the frame, in which this RawSample is detected (for samples made with VideoWorker)...
Definition: RawSample.h:1062
Format
Format of image data.
Definition: IRawImage.h:46
PNG (lossless compression).
Definition: RawSample.h:108
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
Angles getAngles() const
Get a face orientation. Only frontal samples. Thread-safe.
Definition: RawSample.h:1029
Interface object for estimation of emotions.
Definition: EmotionsEstimator.h:41