| Face Engine SDK 4.7.0 A face detection, recognition and tracking engine.

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
19 struct EthnicityEstimation {
20 float africanAmerican;
21 float indian;
22 float asian;
23 float caucasian;
24
25 enum Ethnicities {
26 AfricanAmerican = 0,
27 Indian,
28 Asian,
29 Caucasian,
30 Count
31 };
32
36 inline Ethnicities getPredominantEthnicity() const;
37
42 inline float getEthnicityScore(Ethnicities ethnicity) const;
43 };
44
55 struct IAttributeEstimator : IRefCounted {
56
61 enum EstimationRequest {
62 estimateAge = 1 << 0,
63 estimateGender = 1 << 1,
64 estimateEthnicity = 1 << 2,
65 estimateAll = 0xffff
66 };
67
71 struct EstimationResult {
73 Optional<float> age;
75 Optional<float> gender;
77 Optional<float> genderScore;
79 Optional<EthnicityEstimation> ethnicity;
80 };
81
89 virtual Result<FSDKError> estimate(
90 const Image& warp,
91 const IAttributeEstimator::EstimationRequest request,
92 IAttributeEstimator::EstimationResult& out) const noexcept = 0;
93
104 virtual ResultValue<FSDKError, IAttributeEstimator::EstimationResult> estimate(
105 const Span<const Image> warps,
106 const IAttributeEstimator::EstimationRequest request,
107 Span<IAttributeEstimator::EstimationResult> results) const noexcept = 0;
108 };
109
113 using EstimationRequest = IAttributeEstimator::EstimationRequest;
114 using AttributeEstimationResult = IAttributeEstimator::EstimationResult;
115
116 /*
117 Implementation details.
118 */
119 EthnicityEstimation::Ethnicities
120 EthnicityEstimation::getPredominantEthnicity() const {
121 const float* arr = &this->africanAmerican;
122 return static_cast<EthnicityEstimation::Ethnicities>(
123 std::distance(arr, std::max_element(arr, arr+EthnicityEstimation::Count))
124 );
125 }
126
127 /*
128 Implementation details.
129 */
130 float
131 EthnicityEstimation::getEthnicityScore(
132 EthnicityEstimation::Ethnicities ethnicity
133 ) const {
134 return *(&this->africanAmerican + static_cast<uint32_t>(ethnicity));
135 }
136
137 /*
138 Implementation details.
139 */
140 inline IAttributeEstimator::EstimationRequest
141 operator|(
142 IAttributeEstimator::EstimationRequest first,
143 IAttributeEstimator::EstimationRequest second
144 ) {
145 return static_cast<IAttributeEstimator::EstimationRequest>(
146 static_cast<int>(first) | static_cast<int>(second)
147 );
148 }
149
150 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
151
152 } // namespace sdk
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:59
Types.h
Common data types and structures.
IObject.h
Object system types and interfaces.
FSDKError.h
Common SDK error codes.