3DiVi Face SDK  3.21.0
 Указатель Классы Пространства имен Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Свойства Группы
FacerecService.h
См. документацию.
1 
9 #ifndef __PBIO_API__PBIO__FACEREC_SERVICE_H_
10 #define __PBIO_API__PBIO__FACEREC_SERVICE_H_
11 
12 
13 #include <istream>
14 #include <stdexcept>
15 #include <utility>
16 #include <vector>
17 #include <facerec/libfacerec.h>
18 
19 #ifdef ANDROID
20 #include <jni.h>
21 #endif
22 
23 #include "stl_wraps_impls/WrapIStreamImpl.h"
24 #include "stl_wraps_impls/WrapOStreamImpl.h"
25 
26 
27 #include "AgeGenderEstimator.h"
28 #include "CameraCalibrator.h"
29 #include "Capturer.h"
30 #include "ComplexObject.h"
31 #include "DepthLivenessEstimator.h"
32 #include "IRLivenessEstimator.h"
33 #include "ActiveLiveness.h"
34 #include "Liveness2DEstimator.h"
36 #include "EmotionsEstimator.h"
37 #include "Error.h"
38 #include "ExceptionCheck.h"
39 #include "FaceQualityEstimator.h"
40 #include "LivenessEstimator.h"
41 #include "QualityEstimator.h"
42 #include "RawSample.h"
43 #include "Recognizer.h"
44 #include "SmartPtr.h"
45 #include "Template.h"
46 #include "VideoWorker.h"
47 #include "StructStorage.h"
48 #include "Config.h"
49 #include "ProcessingUnit.h"
50 
51 #ifndef WITHOUT_PROCESSING_BLOCK
52 #include "Context.h"
53 #include "ProcessingBlock.h"
54 #endif
55 
56 namespace pbio
57 {
58 
64 class FacerecService : ComplexObject
65 {
66 public:
67 
73  typedef LightSmartPtr<FacerecService>::tPtr Ptr;
74 
75  typedef pbio::Config Config;
76 
81  struct License
82  {
87  const std::string license_body;
88 
89  License(std::string license_body) : license_body(license_body) { }
90  };
91 
97  struct LicenseState
98  {
104  {
109  std::string name;
110 
115  int64_t max_value;
116 
121  int64_t value;
122  };
123 
128  bool online;
129 
130 
135  std::string android_app_id;
136 
141  std::string android_serial;
142 
147  std::string ios_app_id;
148 
153  std::string hardware_reg;
154 
159  std::vector<CounterState> counters;
160  };
161 
200  const std::string dll_path,
201  std::string facerec_conf_dir,
202  const std::string license_dir = std::string());
203 
238  const std::string dll_path,
239  std::string facerec_conf_dir,
240  const pbio::FacerecService::License license);
241 
243 
244  // internal usage only
246  void* const ae_ptr,
247  const std::string dll_path,
248  std::string facerec_conf_dir,
249  const std::string license,
250  const bool is_license_dir);
251 
253 
254 
272  std::string getVersion() const;
273 
283  void forceOnlineLicenseUpdate() const;
284 
311 
335  AgeGenderEstimator::Ptr createAgeGenderEstimator(const std::string ini_file) const;
336 
360  QualityEstimator::Ptr createQualityEstimator(const std::string ini_file) const;
361 
385  FaceQualityEstimator::Ptr createFaceQualityEstimator(const std::string ini_file) const;
386 
405 
429  EmotionsEstimator::Ptr createEmotionsEstimator(const std::string ini_file) const;
430 
475  const char* ini_file,
476  const bool processing = true,
477  const bool matching = true,
478  const bool processing_less_memory_consumption = false) const;
479 
480 
525  const pbio::FacerecService::Config recognizer_config,
526  const bool processing = true,
527  const bool matching = true,
528  const bool processing_less_memory_consumption = false) const;
529 
562  const pbio::VideoWorker::Params params) const;
563 
564 
607  const pbio::FacerecService::Config video_worker_config,
608  const char* recognizer_ini_file,
609  const int streams_count,
610  const int processing_threads_count,
611  const int matching_threads_count) const;
612 
613 
656  const pbio::FacerecService::Config video_worker_config,
657  const pbio::FacerecService::Config recognizer_config,
658  const int streams_count,
659  const int processing_threads_count,
660  const int matching_threads_count) const;
661 
662 
663 
691  RawSample::Ptr loadRawSample(std::istream &binary_stream) const;
692 
720  RawSample::Ptr loadRawSample(pbio::stl_wraps::WrapIStream &binary_stream) const;
721 
722 
786  pbio::stl_wraps::WrapIStream &binary_stream,
787  const RawImage image,
788  const double space_translation_x = 0,
789  const double space_translation_y = 0,
790  const double space_scale = 1) const;
791 
796  std::istream &binary_stream,
797  const RawImage image,
798  const double space_translation_x = 0,
799  const double space_translation_y = 0,
800  const double space_scale = 1) const;
801 
856  pbio::stl_wraps::WrapIStream &binary_stream,
857  const unsigned char *image_data,
858  int image_data_size,
859  const double space_translation_x = 0,
860  const double space_translation_y = 0,
861  const double space_scale = 1) const;
862 
868  std::istream &binary_stream,
869  const unsigned char *image_data,
870  int image_data_size,
871  const double space_translation_x = 0,
872  const double space_translation_y = 0,
873  const double space_scale = 1) const;
874 
875 
894 
895 
920  const std::string ini_file) const;
921 
922 
947  const pbio::FacerecService::Config config) const;
948 
949 
974  const std::string ini_file) const;
975 
976 
1001  const pbio::FacerecService::Config config) const;
1002 
1003 
1028  const std::string ini_file) const;
1029 
1030 
1055  const pbio::FacerecService::Config config) const;
1056 
1081  const std::string ini_file) const;
1082 
1084 
1085  ProcessingUnit::Ptr createProcessingUnit(
1086  const int block_type,
1087  const char* serializedConfig) const;
1088 
1089 #ifndef WITHOUT_PROCESSING_BLOCK
1090  Context createContext() const;
1091 
1092  ProcessingBlock createProcessingBlock(const Context& config) const;
1093 #endif
1094 
1096 
1114  LicenseState getLicenseState() const;
1115 
1116 
1130  void keepAlgorithmsCache() const;
1131 
1143  void freeAlgorithmsCache() const;
1144 
1145 
1186  const int width,
1187  const int height,
1188  const RawImage::Format format);
1189 
1190 
1191 #ifdef ANDROID
1192 
1232  JNIEnv *env,
1233  jobject android_media_image);
1234 #endif // ifdef ANDROID
1235 
1236 
1277  void convertYUV2ARGB(
1278  const RawImage image,
1279  const bool downscale_x2,
1280  void* const result_buffer);
1281 
1282 
1283  void convertYUV2RGB(
1284  const RawImage image,
1285  const bool downscale_x2,
1286  const int base_angle,
1287  void* const result_buffer);
1288 
1289 
1290 private:
1291 
1292  const std::string _facerec_conf_dir;
1293 
1294  friend class object_with_ref_counter<FacerecService>;
1295 protected:
1297  const DHPtr &dll_handle,
1298  const std::string &facerec_conf_dir,
1299  void* impl);
1300 };
1301 
1302 } // pbio namespace
1303 
1304 
1305 
1306 
1310 
1311 
1312 namespace pbio
1313 {
1314 
1315 
1316 // static
1317 inline
1319  const std::string dll_path,
1320  std::string facerec_conf_dir,
1321  const std::string license_dir)
1322 {
1323  return createService(NULL, dll_path, facerec_conf_dir, license_dir, true);
1324 }
1325 
1326 // static
1327 inline
1329  const std::string dll_path,
1330  std::string facerec_conf_dir,
1331  const pbio::FacerecService::License license)
1332 {
1333  return createService(NULL, dll_path, facerec_conf_dir, license.license_body, false);
1334 }
1335 
1336 // static
1337 inline
1339  void* const ae_ptr,
1340  const std::string dll_path,
1341  std::string facerec_conf_dir,
1342  const std::string license,
1343  const bool is_license_dir)
1344 {
1345 
1346 #ifdef __STATIC_LIBFACEREC_BUILD__
1347  (void) dll_path;
1348 
1349  const DHPtr dll_handle( DHPtr::make() );
1350 #else
1351  const DHPtr dll_handle( DHPtr::make(dll_path.c_str()) );
1352 #endif
1353 
1354  if(facerec_conf_dir.empty())
1355  {
1356  facerec_conf_dir = "./";
1357  }
1358  else if(facerec_conf_dir[facerec_conf_dir.length() - 1] != '/')
1359  {
1360  facerec_conf_dir += '/';
1361  }
1362 
1363  void* exception = NULL;
1364 
1365  void* the_impl;
1366 
1367  if (is_license_dir)
1368  {
1369  the_impl = dll_handle->FacerecService_constructor3(
1370  ae_ptr,
1371  facerec_conf_dir.c_str(),
1372  license.empty() ?
1373  NULL :
1374  license.c_str(),
1375  dll_path.c_str(),
1376  &exception);
1377  }else
1378  {
1379  the_impl = dll_handle->FacerecService_constructor5(
1380  ae_ptr,
1381  facerec_conf_dir.c_str(),
1382  license.c_str(),
1383  dll_path.c_str(),
1384  &exception);
1385  }
1386 
1387  checkException(exception, *dll_handle);
1388 
1389  return FacerecService::Ptr::make(
1390  dll_handle,
1391  facerec_conf_dir,
1392  the_impl);
1393 }
1394 
1395 
1396 inline
1397 FacerecService::FacerecService(
1398  const DHPtr &dll_handle,
1399  const std::string &facerec_conf_dir,
1400  void* impl):
1401 ComplexObject(dll_handle, impl),
1402 _facerec_conf_dir(facerec_conf_dir)
1403 {
1404  std::string lib_version = getVersion();
1405 
1406  if (LIBFACEREC_VERSION != lib_version)
1407  std::cerr << "WARNING: The version in the header does not match the version in the library. Header version: "
1408  << LIBFACEREC_VERSION << ", library version: " << lib_version << std::endl;
1409 }
1410 
1411 
1412 inline
1413 std::string FacerecService::getVersion() const
1414 {
1415  std::ostringstream version_stream;
1416  pbio::stl_wraps::WrapOStreamImpl version_stream_wrap(version_stream);
1417 
1418  void* exception = NULL;
1419 
1420  _dll_handle->get_version(
1421  &version_stream_wrap,
1422  pbio::stl_wraps::WrapOStream::write_func,
1423  &exception);
1424 
1425  checkException(exception, *_dll_handle);
1426 
1427  return version_stream.str();
1428 }
1429 
1430 
1431 inline
1433 {
1434  void* exception = NULL;
1435 
1436  _dll_handle->FacerecService_forceOnlineLicenseUpdate(
1437  _impl,
1438  &exception);
1439 
1440  checkException(exception, *_dll_handle);
1441 }
1442 
1443 inline
1445  const pbio::FacerecService::Config config) const
1446 {
1447  const std::string file_path = _facerec_conf_dir + config.config_filepath;
1448 
1449  std::vector<char const*> overridden_keys;
1450  std::vector<double> overridden_values;
1451 
1452  config.prepare(overridden_keys, overridden_values);
1453 
1454  void* exception = NULL;
1455 
1456  pbio::facerec::CapturerImpl* const capturer_impl =
1457  _dll_handle->FacerecService_createCapturerE(
1458  _impl,
1459  file_path.c_str(),
1460  overridden_keys.size(),
1461  overridden_keys.empty() ? NULL : &(overridden_keys[0]),
1462  overridden_values.empty() ? NULL : &(overridden_values[0]),
1463  &exception);
1464 
1465  checkException(exception, *_dll_handle);
1466 
1467  return Capturer::Ptr::make(_dll_handle, capturer_impl);
1468 }
1469 
1470 inline
1472 {
1473  const std::string file_path = _facerec_conf_dir + ini_file;
1474 
1475  void* exception = NULL;
1476 
1477  pbio::facerec::AgeGenderEstimatorImpl* const the_impl =
1478  _dll_handle->FacerecService_createAgeGenderEstimator(
1479  _impl,
1480  file_path.c_str(),
1481  &exception);
1482 
1483  checkException(exception, *_dll_handle);
1484 
1485  return AgeGenderEstimator::Ptr::make(_dll_handle, the_impl);
1486 }
1487 
1488 
1489 inline
1491 {
1492  const std::string file_path = _facerec_conf_dir + ini_file;
1493 
1494  void* exception = NULL;
1495 
1496  pbio::facerec::QualityEstimatorImpl* const the_impl =
1497  _dll_handle->FacerecService_createQualityEstimator(
1498  _impl,
1499  file_path.c_str(),
1500  &exception);
1501 
1502  checkException(exception, *_dll_handle);
1503 
1504  return QualityEstimator::Ptr::make(_dll_handle, the_impl);
1505 }
1506 
1507 
1508 inline
1510 {
1511  const std::string file_path = _facerec_conf_dir + ini_file;
1512 
1513  void* exception = NULL;
1514 
1515  pbio::facerec::FaceQualityEstimatorImpl* const the_impl =
1516  _dll_handle->FacerecService_createFaceQualityEstimator(
1517  _impl,
1518  file_path.c_str(),
1519  &exception);
1520 
1521  checkException(exception, *_dll_handle);
1522 
1523  return FaceQualityEstimator::Ptr::make(_dll_handle, the_impl);
1524 }
1525 
1526 inline
1528 {
1529  void* exception = NULL;
1530 
1531  pbio::facerec::LivenessEstimatorImpl* const the_impl =
1532  _dll_handle->FacerecService_createLivenessEstimator(
1533  _impl,
1534  &exception);
1535 
1536  checkException(exception, *_dll_handle);
1537 
1538  return LivenessEstimator::Ptr::make(_dll_handle, the_impl);
1539 }
1540 
1541 
1542 inline
1544  const std::string ini_file) const
1545 {
1546  const std::string file_path = _facerec_conf_dir + ini_file;
1547 
1548  void* exception = NULL;
1549 
1550  pbio::facerec::EmotionsEstimatorImpl* const the_impl =
1551  _dll_handle->FacerecService_createEmotionsEstimator(
1552  _impl,
1553  file_path.c_str(),
1554  &exception);
1555 
1556  checkException(exception, *_dll_handle);
1557 
1558  return EmotionsEstimator::Ptr::make(_dll_handle, the_impl);
1559 }
1560 
1561 
1562 inline
1564  const char* ini_file,
1565  const bool processing,
1566  const bool matching,
1567  const bool processing_less_memory_consumption) const
1568 {
1569  const std::string file_path = _facerec_conf_dir + ini_file;
1570 
1571  void* exception = NULL;
1572 
1573  pbio::facerec::RecognizerImpl* const recognizer_impl =
1574  _dll_handle->FacerecService_createRecognizer2(
1575  _impl,
1576  file_path.c_str(),
1577  0,
1578  NULL,
1579  NULL,
1580  (int) processing,
1581  (int) matching,
1582  (int) processing_less_memory_consumption,
1583  &exception);
1584 
1585  checkException(exception, *_dll_handle);
1586 
1587  return Recognizer::Ptr::make(_dll_handle, recognizer_impl);
1588 }
1589 
1590 
1591 inline
1593  const pbio::FacerecService::Config recognizer_config,
1594  const bool processing,
1595  const bool matching,
1596  const bool processing_less_memory_consumption) const
1597 {
1598  const std::string file_path = _facerec_conf_dir + recognizer_config.config_filepath;
1599 
1600  std::vector<char const*> overridden_keys;
1601  std::vector<double> overridden_values;
1602 
1603  recognizer_config.prepare(overridden_keys, overridden_values);
1604 
1605  void* exception = NULL;
1606 
1607  pbio::facerec::RecognizerImpl* const recognizer_impl =
1608  _dll_handle->FacerecService_createRecognizer2(
1609  _impl,
1610  file_path.c_str(),
1611  overridden_keys.size(),
1612  overridden_keys.empty() ? NULL : &(overridden_keys[0]),
1613  overridden_values.empty() ? NULL : &(overridden_values[0]),
1614  (int) processing,
1615  (int) matching,
1616  (int) processing_less_memory_consumption,
1617  &exception);
1618 
1619  checkException(exception, *_dll_handle);
1620 
1621  return Recognizer::Ptr::make(_dll_handle, recognizer_impl);
1622 }
1623 
1624 
1625 
1626 inline
1628  const pbio::FacerecService::Config video_worker_ini_file,
1629  const char* recognizer_ini_file,
1630  const int streams_count,
1631  const int processing_threads_count,
1632  const int matching_threads_count) const
1633 {
1634  return createVideoWorker(
1636  .video_worker_config(video_worker_ini_file)
1637  .recognizer_ini_file(recognizer_ini_file)
1638  .streams_count(streams_count)
1639  .processing_threads_count(processing_threads_count)
1640  .matching_threads_count(matching_threads_count)
1641  );
1642 }
1643 
1644 inline
1646  const pbio::FacerecService::Config video_worker_ini_file,
1647  const pbio::FacerecService::Config recognizer_config,
1648  const int streams_count,
1649  const int processing_threads_count,
1650  const int matching_threads_count) const
1651 {
1652  return createVideoWorker(
1654  .video_worker_config(video_worker_ini_file)
1655  .recognizer_config(recognizer_config)
1656  .streams_count(streams_count)
1657  .processing_threads_count(processing_threads_count)
1658  .matching_threads_count(matching_threads_count)
1659  );
1660 }
1661 
1662 inline
1664  const VideoWorker::Params params) const
1665 {
1666  std::vector<char const*> vw_overridden_keys;
1667  std::vector<double> vw_overridden_values;
1668 
1669  params._video_worker_config.prepare(vw_overridden_keys, vw_overridden_values);
1670  std::vector<std::string> extra_over_params;
1671 
1672  if(!params._active_liveness_checks_order.empty()){
1673  bool is_unique = true;
1674  for (auto it = params._active_liveness_checks_order.begin(); it != params._active_liveness_checks_order.end(); ++it)
1675  if (std::find(it + 1, params._active_liveness_checks_order.end(), *it) != params._active_liveness_checks_order.end()) {
1676  is_unique = false;
1677  break;
1678  }
1679  if(!is_unique)
1680  throw pbio::Error(0x3302330e,
1681  "Error 0x3302330e: Set a unique order of `active_liveness_checks_order` for Active Liveness.");
1682  for (size_t i = 0; i < params._active_liveness_checks_order.size(); i++){
1683  ActiveLiveness::CheckType check = params._active_liveness_checks_order[i];
1684  std::string check_str = ActiveLiveness::CheckTypeToString(check);
1685  extra_over_params.push_back("active_liveness.check_" + check_str);
1686  vw_overridden_keys.push_back(extra_over_params.back().c_str());
1687  vw_overridden_values.push_back(-(double)(i+1));
1688  }
1689  }
1690 
1691 
1692  if (!params._recognizer_ini_file.empty() && !params._recognizer_config.config_filepath.empty())
1693  throw pbio::Error(0xb3fe4d07, "Error: 0xed877a99 You must use either recognizer_config or recognizer_ini_file.");
1694 
1695  pbio::FacerecService::Config recognizer_config =
1696  params._recognizer_ini_file.empty() ?
1697  params._recognizer_config :
1698  pbio::FacerecService::Config(params._recognizer_ini_file);
1699 
1700  std::vector<char const*> rec_overridden_keys;
1701  std::vector<double> rec_overridden_values;
1702 
1703  recognizer_config.prepare(rec_overridden_keys, rec_overridden_values);
1704 
1705  void* exception = NULL;
1706 
1707  pbio::facerec::VideoWorkerImpl* const vw_impl =
1708  _dll_handle->FacerecService_createVideoWorker_sti_age_gender_emotions(
1709  _impl,
1710 
1711  VideoWorker::STrackingCallback,
1712  VideoWorker::STemplateCreatedCallback,
1713  VideoWorker::SMatchFoundCallback,
1714  VideoWorker::STrackingLostCallback,
1715  VideoWorker::SStiPersonOutdatedCallback,
1716 
1717  (_facerec_conf_dir + params._video_worker_config.config_filepath).c_str(),
1718  vw_overridden_keys.size(),
1719  vw_overridden_keys.empty() ? NULL : &(vw_overridden_keys[0]),
1720  vw_overridden_values.empty() ? NULL : &(vw_overridden_values[0]),
1721 
1722  (_facerec_conf_dir + recognizer_config.config_filepath).c_str(),
1723  rec_overridden_keys.size(),
1724  rec_overridden_keys.empty() ? NULL : &(rec_overridden_keys[0]),
1725  rec_overridden_values.empty() ? NULL : &(rec_overridden_values[0]),
1726 
1727  params._streams_count,
1728  params._processing_threads_count,
1729  params._matching_threads_count,
1730  params._short_time_identification_enabled,
1731  params._short_time_identification_distance_threshold,
1732  params._short_time_identification_outdate_time_seconds,
1733  params._age_gender_estimation_threads_count,
1734  params._emotions_estimation_threads_count,
1735  &exception);
1736 
1737  checkException(exception, *_dll_handle);
1738 
1739  return VideoWorker::Ptr::make(_dll_handle, vw_impl);
1740 }
1741 
1742 
1743 inline
1744 RawSample::Ptr FacerecService::loadRawSample(std::istream &binary_stream) const
1745 {
1746  pbio::stl_wraps::WrapIStreamImpl binary_stream_wrap(binary_stream);
1747 
1748  return loadRawSample(binary_stream_wrap);
1749 }
1750 
1751 inline
1752 RawSample::Ptr FacerecService::loadRawSample(pbio::stl_wraps::WrapIStream &binary_stream) const
1753 {
1754  void* exception = NULL;
1755 
1756  pbio::facerec::RawSampleImpl* const raw_sampl_impl =
1757  _dll_handle->FacerecService_loadRawSample(
1758  _impl,
1759  &binary_stream,
1760  pbio::stl_wraps::WrapIStream::read_func,
1761  &exception);
1762 
1763  checkException(exception, *_dll_handle);
1764 
1765  return RawSample::Ptr::make(_dll_handle, raw_sampl_impl);
1766 }
1767 
1768 inline
1770  pbio::stl_wraps::WrapIStream &binary_stream,
1771  const RawImage image,
1772  const double space_translation_x,
1773  const double space_translation_y,
1774  const double space_scale) const
1775 {
1776  void* exception = NULL;
1777 
1778  const RawImage::CapiData cdata = image.makeCapiData();
1779 
1780  pbio::facerec::RawSampleImpl* const raw_sampl_impl =
1781  _dll_handle->FacerecService_loadRawSampleWithoutImage_raw_image(
1782  _impl,
1783  &binary_stream,
1784  pbio::stl_wraps::WrapIStream::read_func,
1785 
1786  cdata.data,
1787  cdata.width,
1788  cdata.height,
1789  cdata.format,
1790  cdata.with_crop,
1791  cdata.crop_info_offset_x,
1792  cdata.crop_info_offset_y,
1793  cdata.crop_info_data_image_width,
1794  cdata.crop_info_data_image_height,
1795 
1796  space_translation_x,
1797  space_translation_y,
1798  space_scale,
1799 
1800  &exception);
1801 
1802  checkException(exception, *_dll_handle);
1803 
1804  return RawSample::Ptr::make(_dll_handle, raw_sampl_impl);
1805 }
1806 
1807 inline
1809  std::istream &binary_stream,
1810  const RawImage image,
1811  const double space_translation_x,
1812  const double space_translation_y,
1813  const double space_scale) const
1814 {
1815  pbio::stl_wraps::WrapIStreamImpl binary_stream_wrap(binary_stream);
1816 
1818  binary_stream_wrap,
1819  image,
1820  space_translation_x,
1821  space_translation_y,
1822  space_scale);
1823 }
1824 
1825 inline
1827  pbio::stl_wraps::WrapIStream &binary_stream,
1828  const unsigned char *image_data,
1829  int image_data_size,
1830  const double space_translation_x,
1831  const double space_translation_y,
1832  const double space_scale) const
1833 {
1834  void* exception = NULL;
1835 
1836  pbio::facerec::RawSampleImpl* const raw_sampl_impl =
1837  _dll_handle->FacerecService_loadRawSampleWithoutImage_encoded_image(
1838  _impl,
1839  &binary_stream,
1840  pbio::stl_wraps::WrapIStream::read_func,
1841 
1842  image_data,
1843  image_data_size,
1844 
1845  space_translation_x,
1846  space_translation_y,
1847  space_scale,
1848 
1849  &exception);
1850 
1851  checkException(exception, *_dll_handle);
1852 
1853  return RawSample::Ptr::make(_dll_handle, raw_sampl_impl);
1854 }
1855 
1856 inline
1858  std::istream &binary_stream,
1859  const unsigned char *image_data,
1860  int image_data_size,
1861  const double space_translation_x,
1862  const double space_translation_y,
1863  const double space_scale) const
1864 {
1865  pbio::stl_wraps::WrapIStreamImpl binary_stream_wrap(binary_stream);
1866 
1867 
1869  binary_stream_wrap,
1870  image_data,
1871  image_data_size,
1872  space_translation_x,
1873  space_translation_y,
1874  space_scale);
1875 }
1876 
1877 
1878 inline
1880 {
1881  void* exception = NULL;
1882 
1883  pbio::facerec::CameraCalibratorImpl* const calibrator_impl =
1884  _dll_handle->FacerecService_createCameraCalibrator(
1885  _impl,
1886  &exception);
1887 
1888  checkException(exception, *_dll_handle);
1889 
1890  return CameraCalibrator::Ptr::make(_dll_handle, calibrator_impl);
1891 }
1892 
1893 
1894 
1895 inline
1897  const std::string ini_file) const
1898 {
1899  const std::string file_path = _facerec_conf_dir + ini_file;
1900 
1901  void* exception = NULL;
1902 
1903  pbio::facerec::DepthLivenessEstimatorImpl* const the_impl =
1904  _dll_handle->FacerecService_createDepthLivenessEstimatorE(
1905  _impl,
1906  file_path.c_str(),
1907  0, // overridden keys size
1908  NULL, // overridden keys
1909  NULL, // overriden values
1910  &exception);
1911 
1912  checkException(exception, *_dll_handle);
1913 
1914  return DepthLivenessEstimator::Ptr::make(_dll_handle, the_impl);
1915 }
1916 
1917 
1918 inline
1920  const pbio::FacerecService::Config config) const
1921 {
1922  const std::string file_path = _facerec_conf_dir + config.config_filepath;
1923 
1924  std::vector<char const*> overridden_keys;
1925  std::vector<double> overridden_values;
1926 
1927  config.prepare(overridden_keys, overridden_values);
1928 
1929  void* exception = NULL;
1930 
1931  pbio::facerec::DepthLivenessEstimatorImpl* const the_impl =
1932  _dll_handle->FacerecService_createDepthLivenessEstimatorE(
1933  _impl,
1934  file_path.c_str(),
1935  overridden_keys.size(),
1936  overridden_keys.empty() ? NULL : &(overridden_keys[0]),
1937  overridden_values.empty() ? NULL : &(overridden_values[0]),
1938  &exception);
1939 
1940  checkException(exception, *_dll_handle);
1941 
1942  return DepthLivenessEstimator::Ptr::make(_dll_handle, the_impl);
1943 }
1944 
1945 inline
1947  const std::string ini_file) const
1948 {
1949  const std::string file_path = _facerec_conf_dir + ini_file;
1950 
1951  void* exception = NULL;
1952 
1953  pbio::facerec::IRLivenessEstimatorImpl* const the_impl =
1954  _dll_handle->FacerecService_createIRLivenessEstimatorE(
1955  _impl,
1956  file_path.c_str(),
1957  0, // overridden keys size
1958  NULL, // overridden keys
1959  NULL, // overriden values
1960  &exception);
1961 
1962  checkException(exception, *_dll_handle);
1963 
1964  return IRLivenessEstimator::Ptr::make(_dll_handle, the_impl);
1965 }
1966 
1967 inline
1969  const pbio::FacerecService::Config config) const
1970 {
1971  const std::string file_path = _facerec_conf_dir + config.config_filepath;
1972 
1973  std::vector<char const*> overridden_keys;
1974  std::vector<double> overridden_values;
1975 
1976  config.prepare(overridden_keys, overridden_values);
1977 
1978  void* exception = NULL;
1979 
1980  pbio::facerec::IRLivenessEstimatorImpl* const the_impl =
1981  _dll_handle->FacerecService_createIRLivenessEstimatorE(
1982  _impl,
1983  file_path.c_str(),
1984  overridden_keys.size(),
1985  overridden_keys.empty() ? NULL : &(overridden_keys[0]),
1986  overridden_values.empty() ? NULL : &(overridden_values[0]),
1987  &exception);
1988 
1989  checkException(exception, *_dll_handle);
1990 
1991  return IRLivenessEstimator::Ptr::make(_dll_handle, the_impl);
1992 }
1993 
1994 inline
1996  const std::string ini_file) const
1997 {
1998  const std::string file_path = _facerec_conf_dir + ini_file;
1999 
2000  void* exception = NULL;
2001 
2002  pbio::facerec::Liveness2DEstimatorImpl* const the_impl =
2003  _dll_handle->FacerecService_createLiveness2DEstimatorE(
2004  _impl,
2005  file_path.c_str(),
2006  0, // overridden keys size
2007  NULL, // overridden keys
2008  NULL, // overriden values
2009  &exception);
2010 
2011  checkException(exception, *_dll_handle);
2012 
2013  return Liveness2DEstimator::Ptr::make(_dll_handle, the_impl);
2014 }
2015 
2016 inline
2018  const pbio::FacerecService::Config config) const
2019 {
2020  const std::string file_path = _facerec_conf_dir + config.config_filepath;
2021 
2022  std::vector<char const*> overridden_keys;
2023  std::vector<double> overridden_values;
2024 
2025  config.prepare(overridden_keys, overridden_values);
2026 
2027  void* exception = NULL;
2028 
2029  pbio::facerec::Liveness2DEstimatorImpl* const the_impl =
2030  _dll_handle->FacerecService_createLiveness2DEstimatorE(
2031  _impl,
2032  file_path.c_str(),
2033  overridden_keys.size(),
2034  overridden_keys.empty() ? NULL : &(overridden_keys[0]),
2035  overridden_values.empty() ? NULL : &(overridden_values[0]),
2036  &exception);
2037 
2038  checkException(exception, *_dll_handle);
2039 
2040  return Liveness2DEstimator::Ptr::make(_dll_handle, the_impl);
2041 }
2042 
2043 inline
2045  const std::string ini_file) const
2046 {
2047  const std::string file_path = _facerec_conf_dir + ini_file;
2048 
2049  void* exception = NULL;
2050 
2051  pbio::facerec::FaceAttributesEstimatorImpl* const the_impl =
2052  _dll_handle->FacerecService_createFaceAttributesEstimator(
2053  _impl,
2054  file_path.c_str(),
2055  0, // overridden keys size
2056  NULL, // overridden keys
2057  NULL, // overriden values
2058  &exception);
2059 
2060  checkException(exception, *_dll_handle);
2061 
2062  return FaceAttributesEstimator::Ptr::make(_dll_handle, the_impl);
2063 }
2064 
2066 
2067 inline
2068 ProcessingUnit::Ptr FacerecService::createProcessingUnit(
2069  const int block_type,
2070  const char* serializedConfig) const
2071 {
2072  return ProcessingUnit::Ptr::make(_dll_handle, block_type, serializedConfig);
2073 }
2074 
2075 #ifndef WITHOUT_PROCESSING_BLOCK
2076 inline Context FacerecService::createContext() const
2077 {
2078  return Context(_dll_handle);
2079 }
2080 
2081 inline ProcessingBlock FacerecService::createProcessingBlock(const Context& config) const
2082 {
2083  return ProcessingBlock(_impl, _dll_handle, config);
2084 }
2085 #endif
2086 
2088 
2089 inline
2091 {
2092  void* exception = NULL;
2093 
2094  void* struct_storage_impl = _dll_handle->FacerecService_getLicenseState(_impl, &exception);
2095 
2096  checkException(exception, *_dll_handle);
2097 
2098  const StructStorage struct_storage(_dll_handle, struct_storage_impl);
2099 
2100  LicenseState result;
2101 
2102  result.online = struct_storage.get_int64(StructStorageFields::license_state_online_t);
2103 
2104  result.android_app_id = (char const*) struct_storage.get_pointer(StructStorageFields::license_state_android_app_id_t);
2105  result.android_serial = (char const*) struct_storage.get_pointer(StructStorageFields::license_state_android_serial_t);
2106  result.ios_app_id = (char const*) struct_storage.get_pointer(StructStorageFields::license_state_ios_app_id_t);
2107  result.hardware_reg = (char const*) struct_storage.get_pointer(StructStorageFields::license_state_hardware_reg_t);
2108 
2109  result.counters.resize( struct_storage.get_int64(
2110  StructStorageFields::license_state_licenses_count_t) );
2111 
2112  for(size_t i = 0; i < result.counters.size(); ++i)
2113  {
2114  result.counters[i].name = (char const*) struct_storage.get_pointer(
2115  (i << 16) | size_t(StructStorageFields::license_state_licenses_names_int16_t) );
2116 
2117  result.counters[i].max_value = struct_storage.get_int64(
2118  (i << 16) | size_t(StructStorageFields::license_state_licenses_total_counts_int16_t) );
2119 
2120  result.counters[i].value = struct_storage.get_int64(
2121  (i << 16) | size_t(StructStorageFields::license_state_licenses_in_use_counts_int16_t) );
2122  }
2123 
2124  return result;
2125 }
2126 
2127 
2128 inline
2130 {
2131  void* exception = NULL;
2132 
2133  _dll_handle->FacerecService_toggleAlgorithmsCacheKepp(1, &exception);
2134 
2135  checkException(exception, *_dll_handle);
2136 }
2137 
2138 inline
2140 {
2141  void* exception = NULL;
2142 
2143  _dll_handle->FacerecService_toggleAlgorithmsCacheKepp(0, &exception);
2144 
2145  checkException(exception, *_dll_handle);
2146 }
2147 
2148 
2149 
2150 inline
2152  const int width,
2153  const int height,
2154  const RawImage::Format format)
2155 {
2156  void* exception = NULL;
2157 
2158  int32_t data_size;
2159  void* data_ptr;
2160  void* imagetptr_ptr;
2161 
2162  void* const the_impl = _dll_handle->InternalImageBuffer_constructor(
2163  width,
2164  height,
2165  format,
2166  &data_size,
2167  &data_ptr,
2168  &imagetptr_ptr,
2169  &exception);
2170 
2171  checkException(exception, *_dll_handle);
2172 
2173  return InternalImageBuffer::Ptr::make(
2174  _dll_handle,
2175  the_impl,
2176  (unsigned char*) data_ptr,
2177  data_size,
2178  width,
2179  height,
2180  format,
2181  imagetptr_ptr);
2182 }
2183 
2184 
2185 #ifdef ANDROID
2186 inline
2188  JNIEnv *env,
2189  jobject android_media_image)
2190 {
2191  void* exception = NULL;
2192 
2193  int32_t width;
2194  int32_t height;
2195  int32_t format;
2196  int32_t data_size;
2197  void* data_ptr;
2198  void* imagetptr_ptr;
2199 
2200  void* const the_impl = _dll_handle->InternalImageBuffer_constructor_from_android_image(
2201  env,
2202  android_media_image,
2203  &width,
2204  &height,
2205  &format,
2206  &data_size,
2207  &data_ptr,
2208  &imagetptr_ptr,
2209  &exception);
2210 
2211  checkException(exception, *_dll_handle);
2212 
2213  return InternalImageBuffer::Ptr::make(
2214  _dll_handle,
2215  the_impl,
2216  (unsigned char*) data_ptr,
2217  data_size,
2218  width,
2219  height,
2220  (InternalImageBuffer::Format) format,
2221  imagetptr_ptr);
2222 }
2223 #endif
2224 
2225 inline
2227  const RawImage image,
2228  const bool downscale_x2,
2229  void* const result_buffer)
2230 {
2231  void* exception = NULL;
2232 
2233  const RawImage::CapiData cdata = image.makeCapiData();
2234 
2235  _dll_handle->RawImage_convertYUV2ARGB(
2236  cdata.data,
2237  cdata.width,
2238  cdata.height,
2239  cdata.format,
2240  cdata.with_crop,
2241  cdata.crop_info_offset_x,
2242  cdata.crop_info_offset_y,
2243  cdata.crop_info_data_image_width,
2244  cdata.crop_info_data_image_height,
2245  downscale_x2,
2246  result_buffer,
2247  &exception);
2248 
2249  checkException(exception, *_dll_handle);
2250 }
2251 
2252 inline
2253 void FacerecService::convertYUV2RGB(
2254  const RawImage image,
2255  const bool downscale_x2,
2256  const int base_angle,
2257  void* const result_buffer)
2258 {
2259  void* exception = NULL;
2260 
2261  const RawImage::CapiData cdata = image.makeCapiData();
2262 
2263  _dll_handle->RawImage_convertYUV2RGB(
2264  cdata.data,
2265  cdata.width,
2266  cdata.height,
2267  cdata.format,
2268  cdata.with_crop,
2269  cdata.crop_info_offset_x,
2270  cdata.crop_info_offset_y,
2271  cdata.crop_info_data_image_width,
2272  cdata.crop_info_data_image_height,
2273  downscale_x2,
2274  base_angle,
2275  result_buffer,
2276  &exception);
2277 
2278  checkException(exception, *_dll_handle);
2279 }
2280 
2281 
2282 } // pbio namespace
2283 
2284 
2285 
2286 
2287 
2288 #endif // __PBIO_API__PBIO__FACEREC_SERVICE_H_
Интерфейсный объект для взаимодействия с методами из Processing Block API.
Definition: ProcessingBlock.h:29
std::string android_serial
Серийный номер Android-устройства. Доступен только на Android (тэг <android_serial>).
Definition: FacerecService.h:141
void keepAlgorithmsCache() const
Включить удержание данных для алгоритмов в памяти, даже если не осталось владельцев. Это ускорит повторную инициализацию алгоритмов. Потокобезопасный.
Definition: FacerecService.h:2129
Структура, предоставляющая данные изображения в "сыром" формате и опциональную информацию для обрезки...
Definition: RawImage.h:28
Интерфейсный объект для создания других интерфейсных объектов.
Definition: FacerecService.h:64
ProcessingBlock - Интерфейсный объект для взаимодействия с методами из Processing Block API...
QualityEstimator - Интерфейсный объект для определения качества образца лица.
VideoWorker - интерфейсный объект для трекинга, обработки и распознавания лиц на нескольких видеопото...
LightSmartPtr< InternalImageBuffer >::tPtr Ptr
Псевдоним для типа умного указателя на InternalImageBuffer.
Definition: InternalImageBuffer.h:34
CameraCalibrator - Интерфейсный объект для калибровки камеры и коррекции дисторсии.
RawSample::Ptr loadRawSample(std::istream &binary_stream) const
Загрузить объект RawSample, сохраненный с помощью метода RawSample::save. Формат платформонезависимый...
Definition: FacerecService.h:1744
static FacerecService::Ptr createService(const std::string dll_path, std::string facerec_conf_dir, const std::string license_dir=std::string())
Инициализировать работу с библиотекой libfacerec (нельзя вызывать более одного раза).
Definition: FacerecService.h:1318
LightSmartPtr< EmotionsEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на EmotionsEstimator.
Definition: EmotionsEstimator.h:50
Recognizer - Интерфейсный объект для создания и сравнения шаблонов.
int64_t max_value
Максимальное значение счетчика (совпадает со значением тэга).
Definition: FacerecService.h:115
Статус счетчика, назначенного определенному элементу лицензии.
Definition: FacerecService.h:103
std::string android_app_id
ID Android приложения. Доступен только на Android (тэг <android_app_id>).
Definition: FacerecService.h:135
LightSmartPtr< IRLivenessEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на IRLivenessEstimator.
Definition: IRLivenessEstimator.h:43
LightSmartPtr< FaceQualityEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на FaceQualityEstimator.
Definition: FaceQualityEstimator.h:50
LightSmartPtr< VideoWorker >::tPtr Ptr
Псевдоним для типа умного указателя на VideoWorker.
Definition: VideoWorker.h:72
Liveness2DEstimator - интерфейсный объект для определения принадлежности лица реальному человеку...
Capturer - Интерфейсный объект для детекции и трекинга лиц на изображениях или видеопоследовательност...
LightSmartPtr< CameraCalibrator >::tPtr Ptr
Псевдоним для типа умного указателя на CameraCalibrator.
Definition: CameraCalibrator.h:48
LightSmartPtr< Capturer >::tPtr Ptr
Псевдоним для типа умного указателя на Capturer.
Definition: Capturer.h:45
Параметры конструктора VideoWorker.
Definition: VideoWorker.h:89
DepthLivenessEstimator - Интерфейсный объект для определения принадлежности лица реальному человеку...
EmotionsEstimator - интерфейсный объект для определения эмоций.
Класс для переопределения параметров конфигурации во время выполнения.
Definition: Config.h:19
IRLivenessEstimator::Ptr createIRLivenessEstimator(const std::string ini_file) const
Создать объект IRLivenessEstimator. Потокобезопасный.
Definition: FacerecService.h:1946
LightSmartPtr< RawSample >::tPtr Ptr
Псевдоним для типа умного указателя на RawSample.
Definition: RawSample.h:58
LightSmartPtr< QualityEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на QualityEstimator.
Definition: QualityEstimator.h:50
FaceQualityEstimator::Ptr createFaceQualityEstimator(const std::string ini_file) const
Создать объект FaceQualityEstimator. Потокобезопасный.
Definition: FacerecService.h:1509
Error - класс исключений, выбрасываемых при возникновении ошибок.
Template - Интерфейсный объект для сохранения шаблона лица.
RawSample - Интерфейсный объект, хранящий образец лица.
CameraCalibrator::Ptr createCameraCalibrator() const
Создать объект CameraCalibrator. Потокобезопасный.
Definition: FacerecService.h:1879
LivenessEstimator - Интерфейсный объект для определения принадлежности лица реальному человеку...
Liveness2DEstimator::Ptr createLiveness2DEstimator(const std::string ini_file) const
Создать объект Liveness2DEstimator. Потокобезопасный.
Definition: FacerecService.h:1995
AgeGenderEstimator - интерфейсный объект для определения пола и возраста
EmotionsEstimator::Ptr createEmotionsEstimator(const std::string ini_file) const
Создать объект EmotionsEstimator. Потокобезопасный.
Definition: FacerecService.h:1543
const std::string license_body
Содержимое лицензии.
Definition: FacerecService.h:87
std::vector< CounterState > counters
Статус всех счетчиков лицензии.
Definition: FacerecService.h:159
LightSmartPtr< Recognizer >::tPtr Ptr
Псевдоним для типа умного указателя на Recognizer.
Definition: Recognizer.h:46
InternalImageBuffer::Ptr createInternalImageBuffer(const int width, const int height, const RawImage::Format format)
Создать InternalImageBuffer для указанного размера и формата изображения. Потокобезопасный. Всегда создавайте новый InternalImageBuffer для каждого изображения или кадра видео. Никогда не изменяйте данные изображения после первого использования.
Definition: FacerecService.h:2151
LightSmartPtr< FacerecService >::tPtr Ptr
Псевдоним для типа умного указателя на FacerecService.
Definition: FacerecService.h:73
Класс исключений, выбрасываемых при возникновении ошибок.
Definition: Error.h:26
std::string ios_app_id
ID iOS приложения. Доступен только на iOS (тэг <ios_app_id>).
Definition: FacerecService.h:147
Capturer::Ptr createCapturer(const pbio::FacerecService::Config config) const
Создать объект Capturer. Тип и возможности зависят от указанного конфигурационного файла...
Definition: FacerecService.h:1444
VideoWorker::Ptr createVideoWorker(const pbio::VideoWorker::Params params) const
Создать объект VideoWorker. Потокобезопасный. Если при создании VideoWorker указаны параметры matchi...
Definition: FacerecService.h:1663
Главный заголовочный файл библиотеки
Recognizer::Ptr createRecognizer(const char *ini_file, const bool processing=true, const bool matching=true, const bool processing_less_memory_consumption=false) const
Создать объект Recognizer. Потокобезопасный.
Definition: FacerecService.h:1563
std::string hardware_reg
Ключ оборудования (тэг <Reg>).
Definition: FacerecService.h:153
void forceOnlineLicenseUpdate() const
Принудительно обновить онлайн-лицензию.
Definition: FacerecService.h:1432
LicenseState getLicenseState() const
Получить статус лицензии. Потокобезопасный.
Definition: FacerecService.h:2090
DepthLivenessEstimator::Ptr createDepthLivenessEstimator(const std::string ini_file) const
Создать объект DepthLivenessEstimator. Потокобезопасный.
Definition: FacerecService.h:1896
bool online
Флаг онлайн-лицензии.
Definition: FacerecService.h:128
int64_t value
Текущее значение (количество используемых элементов).
Definition: FacerecService.h:121
std::string name
Имя элемента (совпадает с именем тэга).
Definition: FacerecService.h:109
Хранение лицензии в виде строковой переменной.
Definition: FacerecService.h:81
FaceAttributesEstimator - интерфейсный объект для определения аттрибутов лица.
AgeGenderEstimator::Ptr createAgeGenderEstimator(const std::string ini_file) const
Создать объект AgeGenderEstimator. Потокобезопасный.
Definition: FacerecService.h:1471
Definition: Context.h:37
LightSmartPtr< Liveness2DEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на Liveness2DEstimator.
Definition: Liveness2DEstimator.h:50
SmartPtr.
void freeAlgorithmsCache() const
Отключить удержание данных для алгоритмов в памяти. Потокобезопасный.
Definition: FacerecService.h:2139
IRLivenessEstimator - интерфейсный объект для определения принадлежности лица реальному человеку...
std::string getVersion() const
Получить версию библиотеки. Потокобезопасный.
Definition: FacerecService.h:1413
LightSmartPtr< FaceAttributesEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на FaceAttributesEstimator.
Definition: FaceAttributesEstimator.h:37
FaceAttributesEstimator::Ptr createFaceAttributesEstimator(const std::string ini_file) const
Создать объект FaceAttributesEstimator. Потокобезопасный.
Definition: FacerecService.h:2044
LightSmartPtr< LivenessEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на LivenessEstimator.
Definition: LivenessEstimator.h:42
Format
Формат данных изображения.
Definition: IRawImage.h:46
LightSmartPtr< AgeGenderEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на AgeGenderEstimator.
Definition: AgeGenderEstimator.h:55
CheckType
Тип проверки для активной (сценарной) оценки принадлежности лица живому человеку. ...
Definition: ActiveLiveness.h:14
void convertYUV2ARGB(const RawImage image, const bool downscale_x2, void *const result_buffer)
Конвертировать входное изображение в формат android.graphics.Bitmap.Config.ARGB_8888. Формат входного изображения должен быть YUV_NV21 или YUV_NV12. Замечание: в действительности порядок байт BGRA, а название ARGB_8888 похоже предполагает нотацию 32-битного little-endian целого числа. Потокобезопасный.
Definition: FacerecService.h:2226
RawSample::Ptr loadRawSampleWithoutImage(pbio::stl_wraps::WrapIStream &binary_stream, const RawImage image, const double space_translation_x=0, const double space_translation_y=0, const double space_scale=1) const
Загрузить объект RawSample, сохраненный с помощью метода RawSample::saveWithoutImage. В случае, если над изображением была выполнена трансформация, вы можете указать параметры преобразования пространства координат: (x, y) -> ( (x + space_translation_x) * space_scale, (y + space_translation_y) * space_scale ) которое будет применено к информации о позиции лица. Заметьте, что параметры одного и того же преобразования нужно передавать только один раз - либо при сериализации, либо при десериализации, иначе преобразование будет применено дважды, что неверно. Формат платформонезависимый. Потокобезопасный.
Definition: FacerecService.h:1769
QualityEstimator::Ptr createQualityEstimator(const std::string ini_file) const
Создать объект QualityEstimator. Потокобезопасный.
Definition: FacerecService.h:1490
FaceQualityEstimator - Интерфейсный объект для определения качества образца лица. ...
Статус лицензии.
Definition: FacerecService.h:97
LivenessEstimator::Ptr createLivenessEstimator() const
Создать объект LivenessEstimator. Потокобезопасный.
Definition: FacerecService.h:1527
LightSmartPtr< DepthLivenessEstimator >::tPtr Ptr
Псевдоним для типа умного указателя на DepthLivenessEstimator.
Definition: DepthLivenessEstimator.h:43