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.

126 lines
4.4 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. #include <cmath>
  7. namespace fsdk {
  8. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  9. DECLARE_SMARTPTR(IHeadPoseEstimator);
  10. #endif
  11. /**
  12. * @brief Head pose estimation output.
  13. * @details These values are produced by IHeadPoseEstimator object.
  14. * Each angle is measured in degrees and in [-180, 180] range.
  15. * */
  16. struct HeadPoseEstimation {
  17. float pitch; //!< Pitch angle estimation.
  18. float yaw; //!< Yaw angle estimation.
  19. float roll; //!< Roll angle estimation.
  20. enum FrontalFaceType {
  21. Non = 0, //!< Non-frontal face
  22. Good, //!< Good for recognition; Doesn't descrease recall and looks fine.
  23. ISO //!< GOST/ISO angles
  24. };
  25. /**
  26. * @brief Returns type of face frontality
  27. * */
  28. inline FrontalFaceType getFrontalFaceType() const;
  29. };
  30. /**
  31. * @brief Head pose angles estimator interface.
  32. * @note This estimator is designed to work with 68 facial landmarks or with raw image data;
  33. * @see IDetector for details.
  34. * @details Estimated angles are:
  35. * \li pitch;
  36. * \li yaw;
  37. * \li roll.
  38. * @see HeadPoseEstimation structure for details about how exactly the estimations are reported.
  39. * */
  40. struct IHeadPoseEstimator : IRefCounted {
  41. /**
  42. * @brief Estimate the angles.
  43. * @param [in] landmarks Landmarks68 structure.
  44. * @param [out] out output estimation.
  45. * @return Result with error code.
  46. * @see Landmarks, HeadPoseEstimation, Result and FSDKError for details.
  47. * */
  48. virtual Result<FSDKError>
  49. FSDK_DEPRECATED("HeadPoseEstimator is deprecated since v.5.0.1, use BestShotQualityEstimator instead")
  50. estimate(
  51. const Landmarks68 &landmarks,
  52. HeadPoseEstimation& out) const noexcept = 0;
  53. /**
  54. * @brief Estimate the angles.
  55. * @param [in] image source image.
  56. * @param [in] detection detection coordinates in image space.
  57. * @param [out] out output estimation.
  58. * @return Result with error code.
  59. * @see HeadPoseEstimation, Detection, Image, Result and FSDKError for details.
  60. * @note image format must be R8G8B8, @see Format.
  61. * */
  62. virtual Result<FSDKError>
  63. FSDK_DEPRECATED("HeadPoseEstimator is deprecated since v.5.0.1, use BestShotQualityEstimator instead")
  64. estimate(
  65. const Image& image,
  66. const Detection& detection,
  67. HeadPoseEstimation& out) const noexcept = 0;
  68. /**
  69. * @brief Estimate headpose angles of multiple frames in a single estimate function call.
  70. * @param [in] images span of source images.
  71. * @param [in] detections span of detection coordinates in corresponding source images space.
  72. * @param [out] out estimations array of corresponding images.
  73. * @return Result with error code.
  74. * @see Span, HeadPoseEstimation, Detection, Image, Result and FSDKError for details.
  75. * @note images format must be R8G8B8, @see Format.
  76. * @note all spans should be based on user owned continuous collections.
  77. * @note all spans should be equal size.
  78. * */
  79. virtual Result<FSDKError>
  80. FSDK_DEPRECATED("HeadPoseEstimator is deprecated since v.5.0.1, use BestShotQualityEstimator instead")
  81. estimate(
  82. Span<const Image> images,
  83. Span<const Detection> detections,
  84. Span<HeadPoseEstimation> out) const noexcept = 0;
  85. /**
  86. * @brief Validate input of multiple frames in a single function call.
  87. * @param [in] images span of source images.
  88. * @param [in] detections span of detection coordinates in corresponding source images space.
  89. * @param [out] errors output span of errors for each image.
  90. * @return Result with error code.
  91. * @see Span, Detection, Image, Result and FSDKError for details.
  92. * @note images format must be R8G8B8, @see Format.
  93. * @note all spans should be based on user owned continuous collections.
  94. * @note all spans should be equal size.
  95. * */
  96. virtual Result<FSDKError>
  97. FSDK_DEPRECATED("HeadPoseEstimator is deprecated since v.5.0.1, use BestShotQualityEstimator instead")
  98. validate(
  99. Span<const Image> images,
  100. Span<const Detection> detections,
  101. Span<Result<FSDKError>> errors) const noexcept = 0;
  102. };
  103. /*
  104. Implementation details.
  105. */
  106. HeadPoseEstimation::FrontalFaceType
  107. HeadPoseEstimation::getFrontalFaceType() const {
  108. if(std::abs(roll) <= 8 && std::abs(pitch) <= 5 && std::abs(yaw) <= 5)
  109. return HeadPoseEstimation::ISO;
  110. if(std::abs(roll) <= 30 && std::abs(pitch) <= 40 && std::abs(yaw) <= 40)
  111. return HeadPoseEstimation::Good;
  112. return HeadPoseEstimation::Non;
  113. }
  114. } // namespace fsdk