Enrollment 28.2.0
Loading...
Searching...
No Matches
FaceDetector.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "enrollment/Export.h"
21#include <ciso646>
22#include <memory>
23#include <vector>
24
25namespace inno
26{
30 */
31 class FaceDetector : public FaceCaptureSegmentation
32 {
33 public:
37 */
38 class Config : public Serializable
39 {
40 public:
43 */
44 enum class Type : uint8_t
45 {
51 ACCURATE,
57 BALANCED,
65 FAST,
76 ACCURATE_SERVER
77 };
81 */
82 void SetDetector(Type value)
83 {
84 type = value;
85 }
89 */
90 [[nodiscard]] Type GetDetector() const
91 {
92 return type;
93 }
100 */
101 void SetMaxDetectionSize(float value)
102 {
103 maxDetectionSize = value;
104 }
108 */
109 [[nodiscard]] float GetMaxDetectionSize() const
110 {
111 return maxDetectionSize;
112 }
119 */
120 void SetMinDetectionSize(float value)
121 {
122 minDetectionSize = value;
123 }
127 */
128 [[nodiscard]] float GetMinDetectionSize() const
129 {
130 return minDetectionSize;
131 }
132
136 */
137 void WriteTo(Writer& writer) const final
138 {
139 writer.Write("t", static_cast<unsigned int>(type));
140 writer.Write("i", minDetectionSize);
141 writer.Write("x", maxDetectionSize);
142 }
143
150 */
151 static Config Default()
152 {
153 static const Config Cfg;
154 return Cfg;
155 }
156
164 Config() = default;
165 Config(const Config&) = default;
166 Config(Config&&) = default;
167 Config& operator=(const Config&) = default;
168 Config& operator=(Config&&) = delete;
169 virtual ~Config() = default;
170
171 private:
172 Type type = Type::BALANCED;
173 float minDetectionSize = DefaultMinDetectionSize;
174 float maxDetectionSize = DefaultMaxDetectionSize;
175 static constexpr float DefaultMinDetectionSize = 0.05F;
176 static constexpr float DefaultMaxDetectionSize = 0.95F;
177 };
178
186 */
187 std::vector<std::shared_ptr<Face>> Detect(std::shared_ptr<FaceCapture> capture) final
188 {
189 log.LogInfo("Face detection for %v with cfg %v ...", capture->image, cfg);
190
191 auto bgr = capture->image->AsRawBGR();
192 auto r = exec->Detect(log.GetLogger(),
193 bgr.height,
194 bgr.width,
195 static_cast<unsigned int>(bgr.dpi),
196 bgr.Data().data(),
197 bgr.Data().size(),
198 cfg.GetMinDetectionSize(),
199 cfg.GetMaxDetectionSize(),
200 static_cast<unsigned int>(cfg.GetDetector()),
201 ThrowOnError{});
202
203 // We want to hide specific implementation of segmentation with all its details like types of 3rd-party
204 // libraries and its headers (Do not want to include it here and expose details). And we want to use the
205 // function in DLL where we cannot pass stl vector. Therefore the function will copy data.
206 std::vector<std::shared_ptr<Face>> res;
207 for (auto& face : r.faces)
208 {
209 if (face.item != nullptr)
210 {
211 const Rectangle boundingBox = { { face.roundingBox.topLeftX, face.roundingBox.topLeftY },
212 { face.roundingBox.topRightX, face.roundingBox.topRightY },
213 { face.roundingBox.bottomRightX, face.roundingBox.bottomRightY },
214 { face.roundingBox.bottomLeftX, face.roundingBox.bottomLeftY } };
215 res.emplace_back(Face::Create(capture,
216 std::shared_ptr<void>(face.item, exec->DestroyImpl()),
217 boundingBox,
218 face.confidence,
219 exec));
220 }
221 }
222
223 log.LogInfo("Face detection result %v", res);
224 return res;
225 }
226
231 */
233 : log(GlobalLogger::Get())
234 , cfg(Config::Default())
235 , exec(GlobalFaceExecutor::Get())
236 {
237 }
238
243 */
244 explicit FaceDetector(Config config)
245 : log(GlobalLogger::Get())
246 , cfg(std::move(config))
247 , exec(GlobalFaceExecutor::Get())
248 {
249 }
250
256 */
257 FaceDetector(Config config, std::shared_ptr<FaceExecutor> executor)
258 : log(GlobalLogger::Get())
259 , cfg(std::move(config))
260 , exec(std::move(executor))
261 {
262 if (exec == nullptr)
263 {
264 throw NullArgumentException("executor can not be null");
265 }
266 }
267
273 */
274 explicit FaceDetector(std::shared_ptr<FaceExecutor> executor)
275 : log(GlobalLogger::Get())
276 , cfg(Config::Default())
277 , exec(std::move(executor))
278 {
279 if (exec == nullptr)
280 {
281 throw NullArgumentException("executor can not be null");
282 }
283 }
284 FaceDetector(const FaceDetector&) = delete;
285 FaceDetector(FaceDetector&&) = delete;
286 FaceDetector& operator=(const FaceDetector&) = delete;
287 FaceDetector& operator=(FaceDetector&&) = delete;
288 virtual ~FaceDetector() = default;
289
290 private:
292 Config cfg;
293 std::shared_ptr<FaceExecutor> exec;
294 };
295} // namespace inno
Face detector configuration.
Definition FaceDetector.h:38
void WriteTo(Writer &writer) const final
Function serializes configuration via provided Writer.
Definition FaceDetector.h:136
Type GetDetector() const
Function gets detection type.
Definition FaceDetector.h:89
float GetMaxDetectionSize() const
Function gets max detection size.
Definition FaceDetector.h:108
Type
Type of neural network detector.
Definition FaceDetector.h:44
@ BALANCED
Neural network face detector and facial features detector with good accuracy.
Definition FaceDetector.h:56
@ ACCURATE
Neural network face detector and facial features detector with very high accuracy.
Definition FaceDetector.h:50
@ FAST
The fastest face detector in combination with the fastest face validators and facial features detecto...
Definition FaceDetector.h:64
@ ACCURATE_SERVER
Definition FaceDetector.h:75
static Config Default()
Provides default Config.
Definition FaceDetector.h:150
Config()=default
Creates Default configuration.
void SetDetector(Type value)
Function sets type of detector.
Definition FaceDetector.h:81
float GetMinDetectionSize() const
Function gets min detection size.
Definition FaceDetector.h:127
void SetMaxDetectionSize(float value)
Function sets max detection size.
Definition FaceDetector.h:100
void SetMinDetectionSize(float value)
Function sets min detection size.
Definition FaceDetector.h:119
FaceDetector implements detection by means of Innovatrics IFace.
Definition FaceDetector.h:31
FaceDetector(std::shared_ptr< FaceExecutor > executor)
Construct a new FaceDetector object Default config is used for detection.
Definition FaceDetector.h:273
FaceDetector(Config config, std::shared_ptr< FaceExecutor > executor)
Construct a new FaceDetector object.
Definition FaceDetector.h:256
FaceDetector(Config config)
Construct a new FaceDetector object GlobalFaceExecutor is used for execution of face functionality.
Definition FaceDetector.h:243
FaceDetector()
Construct a new FaceDetector object GlobalFaceExecutor is used for execution of face functionality.
Definition FaceDetector.h:231
std::vector< std::shared_ptr< Face > > Detect(std::shared_ptr< FaceCapture > capture) final
Detect faces in given image.
Definition FaceDetector.h:186
It provides functions with format specifier to compose and log message via provided Logger.
Definition FormattingLogger.h:601
Holds instance of FaceExecutor.
Definition FaceExecutor.h:1355
Holds instance of Logger.
Definition Logger.h:275
Null argument is not allowed.
Definition EnrollmentException.h:156
It holds rectangle vertexes, width, height.
Definition ImageAttribute.h:357
Provides interface for serialization of all classes.
Definition Writer.h:164