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.

144 lines
4.9 KiB

1 year ago
  1. #pragma once
  2. #include <fsdk/IObject.h>
  3. #include <fsdk/FSDKError.h>
  4. #include <fsdk/Optional.h>
  5. #include <fsdk/Types.h>
  6. namespace fsdk {
  7. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  8. DECLARE_SMARTPTR(IEyeEstimator);
  9. #endif
  10. /**
  11. * @brief Eyes estimation output.
  12. * @details These values are produced by IEyeEstimator object.
  13. * */
  14. struct EyesEstimation {
  15. /**
  16. * @brief Eyes attribute structure.
  17. * */
  18. struct EyeAttributes {
  19. /**
  20. * @brief Enumeration of possible eye states.
  21. * */
  22. enum class State : uint8_t {
  23. Closed, //!< Eye is closed.
  24. Open, //!< Eye is open.
  25. Occluded //!< Eye is blocked by something not transparent, or landmark passed to estimator doesn't point to an eye.
  26. };
  27. static constexpr uint64_t irisLandmarksCount = 32; //!< Iris landmarks amount.
  28. static constexpr uint64_t eyelidLandmarksCount = 6; //!< Eyelid landmarks amount.
  29. /// @brief alias for @see Landmarks template structure with irisLandmarksCount as param.
  30. using IrisLandmarks = Landmarks<irisLandmarksCount>;
  31. /// @brief alias for @see Landmarks template structure with eyelidLandmarksCount as param
  32. using EyelidLandmarks = Landmarks<eyelidLandmarksCount>;
  33. State state; //!< State of an eye.
  34. IrisLandmarks iris; //!< Iris landmarks.
  35. EyelidLandmarks eyelid; //!< Eyelid landmarks
  36. };
  37. EyeAttributes leftEye; //!< Left eye attributes
  38. EyeAttributes rightEye; //!< Right eye attributes
  39. };
  40. /**
  41. * @brief EyeCropper is a helper structure for IEyeEstimator interface
  42. * Methods of this structure crop an input warped image and returns rectangle coordinates of each eye
  43. * */
  44. struct FSDK_API EyeCropper {
  45. struct EyesRects {
  46. Rect leftEyeRect;
  47. Rect rightEyeRect;
  48. };
  49. EyesRects
  50. cropByLandmarks5(
  51. const Image& warp,
  52. const Landmarks5& landmarks5
  53. );
  54. EyeCropper::EyesRects
  55. cropByLandmarks68(
  56. const Image& warp,
  57. const Landmarks68& landmarks68
  58. );
  59. };
  60. /**
  61. * @brief Eye estimator interface.
  62. * @note This estimator is designed to work with a person face image; you should pass a warped face detection image.
  63. * @see IWarper for details.
  64. * Eye estimator detects:
  65. * \li eyes state;
  66. * \li landmarks describing iris.
  67. * @see EyesEstimation for output details
  68. * */
  69. struct IEyeEstimator : IRefCounted {
  70. /**
  71. * @brief Estimate the attributes.
  72. * @param [in] warp image with warped face.
  73. * @param [in] eyeRects EyeCropper::EyesRects structure with valid rectangle coordinates of each eye.
  74. * @param [out] eyesEstimation Estimation of both eyes.
  75. * Iris and Eyelid output landmarks are in warpedImage coordinates.
  76. * If you want them in source of warpedImage image coordinates, use IWarper::unwarp
  77. * @see IWarper::unwarp.
  78. * @return Result with error code.
  79. * @see EyesEstimation, EyeCropper::EyesRects, Image, Result and FSDKError for details.
  80. * @note warp format must be R8G8B8, @see Format.
  81. * @note all spans should be based on user owned continuous collections.
  82. * @note all spans should be equal size.
  83. * */
  84. virtual Result<FSDKError>
  85. estimate(
  86. const Image& warp,
  87. const EyeCropper::EyesRects& eyeRects,
  88. EyesEstimation& eyesEstimation) const noexcept = 0;
  89. /**
  90. * @brief Estimate the attributes of multiple warped images in a single estimate function call
  91. * @param [in] warps span of images with warped faces.
  92. * @param [in] eyeRects span of EyesRects structure of corresponding warped image with valid rectangle coordinates of each eye.
  93. * @param [out] eyesEstimations span of EyesEstimation of corresponding warped images.
  94. * Iris and Eyelid output landmarks are in warpedImage coordinates.
  95. * If you want them in source of warpedImage image coordinates, use IWarper::unwarp
  96. * @see IWarper::unwarp.
  97. * @return Result with error code.
  98. * @see Span, EyesEstimation, EyeCropper::EyesRects, Image, Result and FSDKError for details.
  99. * @note warps format must be R8G8B8, @see Format.
  100. * @note all spans should be based on user owned continuous collections.
  101. * @note all spans should be equal size.
  102. * */
  103. virtual Result<FSDKError>
  104. estimate(
  105. Span<const Image> warps,
  106. Span<const EyeCropper::EyesRects> eyeRects,
  107. Span<EyesEstimation> eyesEstimations) const noexcept = 0;
  108. /**
  109. * @brief Validate input of multiple frames in a single function call.
  110. * @param [in] warps span of images with warped faces.
  111. * @param [in] eyeRects span of EyesRects structure of corresponding warped image with valid rectangle coordinates of each eye.
  112. * @param [out] errors output span of errors for each image.
  113. * @return Result with error code.
  114. * @see Span, EyeCropper::EyesRects, Image, Result and FSDKError for details.
  115. * @note warps format must be R8G8B8, @see Format.
  116. * @note all spans should be based on user owned continuous collections.
  117. * @note all spans should be equal size.
  118. * */
  119. virtual Result<FSDKError>
  120. validate(
  121. Span<const Image> warps,
  122. Span<const EyeCropper::EyesRects> eyeRects,
  123. Span<Result<FSDKError>> errors) const noexcept = 0;
  124. };
  125. } // namespace fsdk