You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.9 KiB

1 year ago
  1. #pragma once
  2. #include "BestShotMobileDefs.h"
  3. #include <fsdk/FaceEngine.h>
  4. #include <tsdk/ITrackEngine.h>
  5. namespace mobile {
  6. /** @brief Supported liveness methods enum
  7. * @note LivenessType::Offline supported in the Complete edition only!
  8. */
  9. enum class LivenessType {
  10. None = 0, //!< No liveness check at all
  11. Online = 1, //!< Online liveness check. Liveness processing on the backend.
  12. Offline = 2, //!< Offline liveness check. Liveness processing on the device.
  13. Offline_OSL = 3 //!< Offline liveness check with OneShot Liveness.
  14. //!< Liveness processing on the device.
  15. };
  16. /** @brief Current liveness state.
  17. */
  18. enum class LivenessState {
  19. Alive, //!< Face was estimated as alive.
  20. Fake, //!< Face was estimated as not alive.
  21. None, //!< No liveness check at all.
  22. NotReady, //!< Liveness check not ready for now. Need more frames to handle.
  23. BadHeadPose, //!< Head angles bigger than thresholds.
  24. BadQuality, //!< Image quality is less than threshold.
  25. FaceNotFound, //!< Face was not found.
  26. FaceTooClose, //!< Face is too close to the camera.
  27. FaceCloseToBorder, //!< Face is too close to the frame border.
  28. FaceTooSmall, //!< Face is too small.
  29. TooManyFaces, //!< There are more than one face in the frame.
  30. Timeout, //!< Liveness timeout.
  31. CriticalError //!< Critical during liveness processing.
  32. };
  33. /** @brief Current best shot state.
  34. */
  35. enum class BestShotState {
  36. Ok, //!< Nice best shot. It can be used for the recognition
  37. BadQuality, //!< Quality is less than threshold.
  38. BadHeadPose, //!< Head angles bigger than thresholds.
  39. Error //!< Error during the best shot processing.
  40. };
  41. struct BestShotInfo {
  42. //! State of this frame
  43. BestShotState state;
  44. //! Source image
  45. fsdk::Image image;
  46. //! Detection with face
  47. fsdk::Detection detection;
  48. //! Face landmarks
  49. fsdk::Landmarks5 landmarks;
  50. //! Estimation of the head position.
  51. //! This parameter could help to show notification to the user in case of bad angles.
  52. fsdk::HeadPoseEstimation headPoseEstimation;
  53. //! AGS estimation result.
  54. //! This parameter could help to show notification to the user in case of bad quality.
  55. float agsEstimation;
  56. //! Index of the frame
  57. tsdk::FrameId frameIndex;
  58. //! Index of the track
  59. tsdk::TrackId trackId;
  60. };
  61. struct IBestShotMobileObserver {
  62. /**
  63. * @brief Bestshot notification.
  64. * @param bestShotInfo bestshot information, @see BestShotInfo.
  65. * @note If liveness check is not nedded (LivenessType::None), this callback
  66. * could be used to take a bestshot.
  67. */
  68. BESTSHOT_MOBILE_API virtual void bestShot(
  69. const BestShotInfo& bestShotInfo) = 0;
  70. /**
  71. * @brief Liveness check notification.
  72. * @param state liveness state for the bestshot. @see LivenessState.
  73. * @param bestShotInfo bestshot information, @see BestShotInfo.
  74. * @note For the liveness type LivenessType::None this callback will not be called!
  75. */
  76. BESTSHOT_MOBILE_API virtual void liveness(
  77. const LivenessState livenessState,
  78. const BestShotInfo& bestShotInfo) = 0;
  79. /**
  80. * @brief End of a track notification
  81. * @param trackId id of the track. @see tsdk::TrackId.
  82. */
  83. BESTSHOT_MOBILE_API virtual void trackEnd(
  84. const tsdk::TrackId& trackId) = 0;
  85. };
  86. /** @brief IBestShotMobile interface class.
  87. * @note This interface is not thread-safe!
  88. */
  89. struct IBestShotMobile {
  90. virtual ~IBestShotMobile() = default;
  91. /** @brief Pushes a single frame to the buffer.
  92. * @note You should pass consequent frames for reasonble results
  93. * (thing video frames).
  94. * Calls face detector and tracker, then triggers the callback for
  95. * processed faces.
  96. * @param frame input frame image. Format must be R8G8B8.
  97. * @param frameId unique identifier for frames sequence.
  98. * @param data is any additional data that a developer wants to receive
  99. * in callbacks-realization.
  100. * Do not use the delete-operator. The garbage collector is implemented
  101. * inside for this param.
  102. * @return true if frame was appended to the queue for processing,
  103. * false otherwise - frame was skipped because of full queue.
  104. */
  105. BESTSHOT_MOBILE_API virtual bool pushFrame(
  106. const fsdk::Image &frame,
  107. uint32_t frameId) = 0;
  108. /** @brief Sets a bestshot observer.
  109. * @param observer pointer to the observer object, @see IBestShotMobileObserver
  110. */
  111. BESTSHOT_MOBILE_API virtual void setBestShotMobileObserver(
  112. IBestShotMobileObserver* observer) = 0;
  113. /** @brief Blocks current thread until all frames in this Stream will be handled
  114. * and all callbacks will be executed.
  115. * @note Stream could not be used after join.
  116. * @see setBestShotObserver, setVisualObserver, setDebugObserver and
  117. * setBestShotPredicate
  118. */
  119. BESTSHOT_MOBILE_API virtual void join() = 0;
  120. /** @brief Returns current liveness type.
  121. * @see LivenessType for details.
  122. * return current liveness type.
  123. */
  124. BESTSHOT_MOBILE_API virtual LivenessType getLivenessType() = 0;
  125. };
  126. /** @brief Creates an IBesthoMobile object.
  127. * @param faceEngine faceEngine object.
  128. * @param trackEngine trackEngine object.
  129. * @param settings settings.
  130. * @return IBestShotMobile object if succeeded, nullptr if failed.
  131. */
  132. IBestShotMobile* createBestShotMobile(
  133. fsdk::FaceEngineType* faceEngine,
  134. tsdk::ITrackEngine* trackEngine,
  135. fsdk::ISettingsProvider* settings
  136. );
  137. /** @brief Creates an IBesthoMobile object.
  138. * @param faceEngine faceEngine object.
  139. * @param trackEngine trackEngine object.
  140. * @param configPath path to the configuration file bestshotmobile.conf.
  141. * @return IBestShotMobile object if succeeded, nullptr if failed.
  142. */
  143. IBestShotMobile* createBestShotMobile(
  144. fsdk::FaceEngineType* faceEngine,
  145. tsdk::ITrackEngine* trackEngine,
  146. const char * configPath
  147. );
  148. } // namespace mobile