Face Engine SDK  5.14.0
A face detection, recognition and tracking engine.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
IAttributeEstimator.h
1 #pragma once
2 
3 #include <fsdk/IObject.h>
4 #include <fsdk/FSDKError.h>
5 #include <fsdk/Optional.h>
6 #include <fsdk/Types.h>
7 
8 #include <algorithm>
9 
10 namespace fsdk {
11 
12 #ifndef DOXYGEN_SHOULD_SKIP_THIS
13  DECLARE_SMARTPTR(IAttributeEstimator);
14 
24  struct EthnicityEstimation {
25  float africanAmerican;
26  float indian;
27  float asian;
28  float caucasian;
29 
30  enum Ethnicities {
31  AfricanAmerican = 0,
32  Indian,
33  Asian,
34  Caucasian,
35  Count
36  };
37 
42  inline Ethnicities getPredominantEthnicity() const;
43 
49  inline float getEthnicityScore(Ethnicities ethnicity) const;
50  };
51 
64  struct IAttributeEstimator : IRefCounted {
69  enum EstimationRequest {
70  estimateAge = 1 << 0,
71  estimateGender = 1 << 1,
72  estimateEthnicity = 1 << 2,
73  estimateAll = 0xffff
74  };
75 
79  struct EstimationResult {
81  Optional<float> age;
83  Optional<float> gender;
85  Optional<float> genderScore;
87  Optional<EthnicityEstimation> ethnicity;
88  };
89 
100  virtual Result<FSDKError> estimate(
101  const Image& warp,
102  const EstimationRequest request,
103  EstimationResult& out) const noexcept = 0;
104 
117  virtual ResultValue<FSDKError, EstimationResult> estimate(
118  Span<const Image> warps,
119  const EstimationRequest request,
120  Span<EstimationResult> results) const noexcept = 0;
121 
134  virtual Result<FSDKError>
135  validate(
136  Span<const Image> warps,
137  const EstimationRequest request,
138  Span<Result<FSDKError>> errors) const noexcept = 0;
139  };
140 
144  using EstimationRequest = IAttributeEstimator::EstimationRequest;
145  using AttributeEstimationResult = IAttributeEstimator::EstimationResult;
146 
147  /*
148  Implementation details.
149  */
150  EthnicityEstimation::Ethnicities
151  EthnicityEstimation::getPredominantEthnicity() const {
152  const float* arr = &this->africanAmerican;
153  return static_cast<EthnicityEstimation::Ethnicities>(
154  std::distance(arr, std::max_element(arr, arr+EthnicityEstimation::Count))
155  );
156  }
157 
158  /*
159  Implementation details.
160  */
161  float
162  EthnicityEstimation::getEthnicityScore(
163  EthnicityEstimation::Ethnicities ethnicity
164  ) const {
165  return *(&this->africanAmerican + static_cast<uint32_t>(ethnicity));
166  }
167 
168  /*
169  Implementation details.
170  */
171  inline IAttributeEstimator::EstimationRequest
172  operator|(
173  IAttributeEstimator::EstimationRequest first,
174  IAttributeEstimator::EstimationRequest second
175  ) {
176  return static_cast<IAttributeEstimator::EstimationRequest>(
177  static_cast<int>(first) | static_cast<int>(second)
178  );
179  }
180 
181 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
182 
183 } // namespace sdk
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:59
Common data types and structures.
Object system types and interfaces.
Common SDK error codes.