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.

165 lines
5.8 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(IQualityEstimator);
  9. #endif
  10. /**
  11. * @brief Quality estimation structure
  12. * Each estimation is given in normalized [0, 1] range. Parameter meanings:
  13. * \li \c light: image overlighting degree. 1 - ok, 0 - overlighted;
  14. * \li \c dark: image darkness degree. 1 - ok, 0 - too dark;
  15. * \li \c gray: image grayness degree 1 - ok, 0 - too gray;
  16. * \li \c blur: image blur degree. 1 - ok, 0 - too blured.
  17. * */
  18. struct Quality {
  19. float light;
  20. float dark;
  21. float gray;
  22. float blur;
  23. /**
  24. * @return complex estimation of quality (minimin of flor estimations). 0 - low quality, 1 - high quality.
  25. * */
  26. inline float getQuality() const noexcept;
  27. };
  28. /**
  29. * @brief Subjective Quality estimation structure
  30. * Each estimation is given in normalized [0, 1] range. Parameter meanings:
  31. * \li \c blur: image blur degree. 1 - ok, 0 - too blured.
  32. * \li \c light: image brightness degree. 1 - ok, 0 - too bright;
  33. * \li \c darkness: image darkness degree. 1 - ok, 0 - too dark;
  34. * \li \c illumination: image illumination uniformity degree. 1 - ok, 0 - is too illuminated;
  35. * \li \c specularity: image specularity degree. 1 - ok, 0 - is not specular;
  36. * \li \c isBlurred image is blurred flag;
  37. * \li \c isHighlighted image is overlighted flag;
  38. * \li \c isDark image image is too dark flag;
  39. * \li \c isIlluminated image is too illuminated flag;
  40. * \li \c isNotSpecular image is not specular flag;
  41. * */
  42. struct SubjectiveQuality {
  43. float blur;
  44. float light;
  45. float darkness;
  46. float illumination;
  47. float specularity;
  48. bool isBlurred;
  49. bool isHighlighted;
  50. bool isDark;
  51. bool isIlluminated;
  52. bool isNotSpecular;
  53. /**
  54. * @return if all boolean flags are false returns true - high quality, else false - low quality.
  55. * */
  56. inline bool isGood() const noexcept;
  57. };
  58. /**
  59. * @brief Image quality estimator interface.
  60. * @note This estimator is designed to work with a person face image; you should pass a warped face detection image.
  61. * @see IWarper for details.
  62. * Quality estimator detects the same attributes as all the other estimators:
  63. * \li over/under exposure;
  64. * \li blurriness;
  65. * \li natural/unnatural colors;
  66. * It is different in the sense that it computes all the estimations at once and returns the results merged somehow
  67. * into a single value instead of several separate values. This way one can obtain a single scalar quality metric of
  68. * a person face image. The estimated value is a probability that the image is good for both recognition and viewing
  69. * purposes.
  70. * */
  71. struct IQualityEstimator : IRefCounted {
  72. /**
  73. * @brief Estimate the quality.
  74. * @param [in] warp image with warped face.
  75. * @param [out] quality output structure with quality params. Complex quality estimation available by method getQuality.
  76. * @return Result with error code.
  77. * @see Quality, Image, Result and FSDKError for details.
  78. * @note warp format must be R8G8B8, @see Format.
  79. * */
  80. virtual Result<FSDKError>
  81. estimate(const Image& warp, Quality& quality) const noexcept = 0;
  82. /**
  83. * @brief Estimate the quality of multiple warped images in a single estimate function call
  84. * @param [in] warps span of images with warped faces.
  85. * @param [out] quality output quality span.
  86. * @return Result with error code.
  87. * @see Span, Quality, Image, Result and FSDKError for details.
  88. * @note warps format must be R8G8B8, @see Format.
  89. * @note all spans should be based on user owned continuous collections.
  90. * @note all spans should be equal size.
  91. * */
  92. virtual Result<FSDKError>
  93. estimate(
  94. Span<const Image> warps,
  95. Span<Quality> quality) const noexcept = 0;
  96. /**
  97. * @brief Estimate the quality.
  98. * @param [in] warp image with warped face.
  99. * @param [out] quality output structure with subjective quality params.
  100. * @return Result with error code.
  101. * @see SubjectiveQuality, Image, Result and FSDKError for details.
  102. * @note warp format must be R8G8B8, @see Format.
  103. * */
  104. virtual Result<FSDKError> estimate(
  105. const Image& warp,
  106. SubjectiveQuality& quality) const noexcept = 0;
  107. /**
  108. * @brief Estimate the subjective quality of multiple warped images in a single estimate function call
  109. * @param [in] warps span of images with warped faces.
  110. * @param [out] quality output SubjectiveQuality span.
  111. * @return Result with error code.
  112. * @see Span, SubjectiveQuality, Image, Result and FSDKError for details.
  113. * @note warps format must be R8G8B8, @see Format.
  114. * @note all spans should be based on user owned continuous collections.
  115. * @note all spans should be equal size.
  116. * */
  117. virtual Result<FSDKError>
  118. estimate(
  119. Span<const Image> warps,
  120. Span<SubjectiveQuality> quality) const noexcept = 0;
  121. /**
  122. * @brief Validate input of multiple frames in a single function call.
  123. * @param [in] warps span of images with warped faces.
  124. * @param [out] errors output span of errors for each image.
  125. * @return Result with error code.
  126. * @see Span, Image, Result and FSDKError for details.
  127. * @note warps format must be R8G8B8, @see Format.
  128. * @note all spans should be based on user owned continuous collections.
  129. * @note all spans should be equal size.
  130. * */
  131. virtual Result<FSDKError>
  132. validate(
  133. Span<const Image> warps,
  134. Span<Result<FSDKError>> errors) const noexcept = 0;
  135. };
  136. /*
  137. Implementation details.
  138. */
  139. float Quality::getQuality() const noexcept {
  140. float min1 = std::min(dark, light);
  141. float min2 = std::min(gray, blur);
  142. return std::min(min1, min2);
  143. }
  144. /*
  145. Implementation details.
  146. */
  147. bool SubjectiveQuality::isGood() const noexcept {
  148. if (!isBlurred && !isHighlighted && !isDark && !isIlluminated && !isNotSpecular)
  149. return true;
  150. return false;
  151. }
  152. } // namespace fsdk