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.

135 lines
5.2 KiB

1 year ago
  1. #pragma once
  2. #include "IHeadPoseEstimator.h" // for HeadPoseEstimation
  3. #include <fsdk/IObject.h>
  4. #include <fsdk/FSDKError.h>
  5. #include <fsdk/Optional.h>
  6. #include <fsdk/Types.h>
  7. #include <fsdk/vlc/future.h>
  8. #include <vector>
  9. namespace fsdk {
  10. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  11. DECLARE_SMARTPTR(IBestShotQualityEstimator);
  12. #endif
  13. /**
  14. * @brief BestShotQuality estimator interface.
  15. * @note This estimator is designed to work with Image and detection;
  16. * */
  17. struct IBestShotQualityEstimator : IRefCounted {
  18. /**
  19. * @brief EstimationRequest lists all possible estimation attributes
  20. * that BestShotQuality estimator is able to estimate.
  21. * */
  22. enum EstimationRequest {
  23. estimateAGS = 1 << 0, //!< Estimate AGS
  24. estimateHeadPose = 1 << 1, //!< Estimate HeadPose
  25. estimateAll = 0xffff //!< Make full estimation (all attributes)
  26. };
  27. /**
  28. * @brief BestShotQualityEstimator output structure
  29. * */
  30. struct EstimationResult {
  31. Optional<HeadPoseEstimation> headPose; //!< HeadPose estimation if was requested, empty otherwise
  32. Optional<float> ags; //!< AGS estimation if was requested, empty otherwise
  33. };
  34. /**
  35. * @brief Estimate unified AGS and HeadPose attributes.
  36. * @param [in] image source image;
  37. * @param [in] detection detection coordinates in image space;
  38. * @param [in] request EstimationRequest structure;
  39. * @param [out] result output estimation.
  40. * @return Result with error code.
  41. * @see IBestShotQualityEstimator::EstimationRequest, IBestShotQualityEstimator::EstimationResult,
  42. * Detection, Image, Result and FSDKError for details.
  43. * @note image format must be R8G8B8, @see Format.
  44. * */
  45. virtual Result<FSDKError> estimate(
  46. const Image& image,
  47. const Detection& detection,
  48. const EstimationRequest request,
  49. EstimationResult& result) const noexcept = 0;
  50. /**
  51. * @brief Estimate unified AGS and HeadPose attributes of multiple frames in a single estimate function call.
  52. * @param [in] images span of source images.
  53. * @param [in] detections span of detection coordinates in corresponding source images space.
  54. * @param [in] request EstimationRequest structure.
  55. * @param [out] results span of estimations.
  56. * @return Result with error code.
  57. * @see IBestShotQualityEstimator::EstimationRequest, IBestShotQualityEstimator::EstimationResult,
  58. * Span, Detection, Image, Result and FSDKError for details.
  59. * @note images format must be R8G8B8, @see Format.
  60. * @note all spans should be based on user owned continuous collections.
  61. * @note all spans should be equal size.
  62. * */
  63. virtual Result<FSDKError> estimate(
  64. Span<const Image> images,
  65. Span<const Detection> detections,
  66. const EstimationRequest request,
  67. Span<EstimationResult> results) const noexcept = 0;
  68. /**
  69. * @brief Common aliases for BestShotQuality asynchronous interface.
  70. * */
  71. using EstimationBatch = std::vector<EstimationResult>;
  72. using EstimationBatchFuture = vlc::future<EstimationBatch>;
  73. /**
  74. * @brief Asynchronously estimate unified AGS and HeadPose attributes of multiple frames in a single estimate function call.
  75. * @param [in] images span of source images.
  76. * @param [in] detections span of detection coordinates in corresponding source images space.
  77. * @param [in] request EstimationRequest structure.
  78. * @return Future estimation result object.
  79. * @see IBestShotQualityEstimator::EstimationRequest, IBestShotQualityEstimator::EstimationResult,
  80. * Span, Detection, Image, Result, FSDKError and vlc::future for details.
  81. * @note images format must be R8G8B8, @see Format.
  82. * @note all spans should be based on user owned continuous collections.
  83. * @note all spans should be equal size.
  84. * @note this method is experimental and interface may be changed in the future.
  85. * @note this method is not marked as noexcept and may throw an exception.
  86. * */
  87. virtual EstimationBatchFuture estimateAsync(
  88. Span<const Image> images,
  89. Span<const Detection> detections,
  90. const EstimationRequest request) const = 0;
  91. /**
  92. * @brief Validate input of multiple frames in a single function call.
  93. * @param [in] images span of source images.
  94. * @param [in] detections span of detection coordinates in corresponding source images space.
  95. * @param [in] request EstimationRequest structure.
  96. * @param [out] errors output span of errors for each image.
  97. * @return Result with error code.
  98. * @see IBestShotQualityEstimator::EstimationRequest,
  99. * Span, Detection, Image, Result and FSDKError for details.
  100. * @note images format must be R8G8B8, @see Format.
  101. * @note all spans should be based on user owned continuous collections.
  102. * @note all spans should be equal size.
  103. * */
  104. virtual Result<FSDKError>
  105. validate(
  106. Span<const Image> images,
  107. Span<const Detection> detections,
  108. const EstimationRequest request,
  109. Span<Result<FSDKError>> errors) const noexcept = 0;
  110. };
  111. /*
  112. Implementation details.
  113. */
  114. inline IBestShotQualityEstimator::EstimationRequest
  115. operator|(
  116. IBestShotQualityEstimator::EstimationRequest first,
  117. IBestShotQualityEstimator::EstimationRequest second
  118. ) {
  119. return static_cast<IBestShotQualityEstimator::EstimationRequest>(
  120. static_cast<int>(first) | static_cast<int>(second)
  121. );
  122. }
  123. } // namespace fsdk