Enrollment 28.2.0
Loading...
Searching...
No Matches
IrisDetector.h
Go to the documentation of this file.
1
9
10#pragma once
11
13#include "enrollment/Export.h"
20#include <memory>
21#include <vector>
22
23namespace inno
24{
28 */
29 class IrisDetector
30 {
31 public:
35 */
36 class Config : public Serializable
37 {
38 public:
41 */
42 enum class Type : uint8_t
43 {
49 ACCURATE,
55 FAST,
56 };
60 */
61 void SetDetector(Type value)
62 {
63 type = value;
64 }
68 */
69 [[nodiscard]] Type GetDetector() const
70 {
71 return type;
72 }
79 */
80 void SetMaxDetectionSize(float value)
81 {
82 maxDetectionSize = value;
83 }
87 */
88 [[nodiscard]] float GetMaxDetectionSize() const
89 {
90 return maxDetectionSize;
91 }
98 */
99 void SetMinDetectionSize(float value)
100 {
101 minDetectionSize = value;
102 }
106 */
107 [[nodiscard]] float GetMinDetectionSize() const
108 {
109 return minDetectionSize;
110 }
111
115 */
116 void WriteTo(Writer& writer) const final
117 {
118 writer.Write("t", static_cast<unsigned int>(type));
119 writer.Write("i", minDetectionSize);
120 writer.Write("x", maxDetectionSize);
121 }
122
129 */
130 static Config Default()
131 {
132 static const Config Cfg;
133 return Cfg;
134 }
135
143 Config() = default;
144 Config(const Config& c) = default;
145 Config(Config&&) = default;
146 Config& operator=(const Config&) = default;
147 Config& operator=(Config&&) = default;
148 virtual ~Config() = default;
149
150 private:
151 Type type = Type::ACCURATE;
152 float minDetectionSize = DefaultMinDetectionSize;
153 float maxDetectionSize = DefaultMaxDetectionSize;
154 static constexpr float DefaultMinDetectionSize = 0.05F;
155 static constexpr float DefaultMaxDetectionSize = 0.95F;
156 };
157
169 */
170 [[nodiscard]] std::shared_ptr<IrisSegment> Detect(const std::shared_ptr<Image>& image,
171 const IrisPosition& position,
172 const IrisAttributes& ia = IrisAttributes()) const
173 {
174 log.LogInfo("Iris detection for %v with cfg %v ...", image, cfg);
175 auto bgr = image->AsRawBGR();
176
177 auto r = exec->Detect(log.GetLogger(),
178 bgr.height,
179 bgr.width,
180 static_cast<unsigned int>(bgr.dpi),
181 bgr.Data().data(),
182 cfg.GetMinDetectionSize(),
183 cfg.GetMaxDetectionSize(),
184 static_cast<unsigned int>(cfg.GetDetector()),
185 ThrowOnError{});
186
187 if (r.irises[0] == nullptr)
188 {
189 throw EnrollmentRuntimeException("No iris is detected");
190 }
191
192 if (r.irises[1] != nullptr)
193 {
194 // release all iris handlers, because more than one iris is found.
195 // The function has only one return value, so we have to release all iris handlers.
196 for (auto& iris : r.irises)
197 {
198 if (iris != nullptr)
199 {
200 exec->DestroyImpl()(iris);
201 }
202 }
203
204 throw EnrollmentRuntimeException("More than one iris is detected");
205 }
206 const auto& firstIrisBB = r.irisRoundingBoxes[0];
207 const Rectangle irisRect = { { firstIrisBB.topLeftX, firstIrisBB.topLeftY },
208 { firstIrisBB.topRightX, firstIrisBB.topLeftY },
209 { firstIrisBB.bottomRightX, firstIrisBB.bottomRightY },
210 { firstIrisBB.bottomLeftX, firstIrisBB.bottomLeftY } };
211
212 const auto& firstPupilBB = r.pupilRoundingBoxes[0];
213 const Rectangle pupilRect = { { firstPupilBB.topLeftX, firstPupilBB.topLeftY },
214 { firstPupilBB.topRightX, firstPupilBB.topLeftY },
215 { firstPupilBB.bottomRightX, firstPupilBB.bottomRightY },
216 { firstPupilBB.bottomLeftX, firstPupilBB.bottomLeftY } };
217
218 auto segment = IrisSegment::Create(Iris::Create(image,
219 r.confidences[0],
220 position,
221 std::shared_ptr<void>(r.irises[0], exec->DestroyImpl()),
222 irisRect,
223 pupilRect,
224 log.GetLogger(),
225 exec,
226 ia),
227 image->RectangleIntersection(irisRect) == Image::Intersection::INSIDE,
228 pupilRect,
229 irisRect);
230
231 log.LogInfo("Iris detection result %v", segment);
232 return segment;
233 }
234
239 */
241 : log(GlobalLogger::Get())
242 , exec(GlobalIrisExecutor::Get())
243 , cfg(Config::Default())
244 {
245 }
246
251 */
252 explicit IrisDetector(Config config)
253 : log(GlobalLogger::Get())
254 , exec(GlobalIrisExecutor::Get())
255 , cfg(std::move(config))
256 {
257 }
263 */
264 IrisDetector(Config config, std::shared_ptr<IrisExecutor> executor)
265 : log(GlobalLogger::Get())
266 , exec(std::move(executor))
267 , cfg(std::move(config))
268 {
269 if (exec == nullptr)
270 {
271 throw NullArgumentException("executor can not be null");
272 }
273 }
274
280 */
281 explicit IrisDetector(std::shared_ptr<IrisExecutor> executor)
282 : log(GlobalLogger::Get())
283 , exec(std::move(executor))
284 , cfg(Config::Default())
285 {
286 if (exec == nullptr)
287 {
288 throw NullArgumentException("executor can not be null");
289 }
290 }
291
292 IrisDetector(const IrisDetector&) = delete;
293 IrisDetector(IrisDetector&&) = delete;
294 IrisDetector& operator=(const IrisDetector&) = delete;
295 IrisDetector& operator=(IrisDetector&&) = delete;
296 virtual ~IrisDetector() = default;
297
298 private:
300 std::shared_ptr<IrisExecutor> exec;
301 Config cfg;
302 };
303} // namespace inno
Base exception for all enrollment-sdk runtime exceptions.
Definition EnrollmentException.h:84
It provides functions with format specifier to compose and log message via provided Logger.
Definition FormattingLogger.h:601
Holds instance of IrisExecutor.
Definition IrisExecutor.h:369
Holds instance of Logger.
Definition Logger.h:275
@ INSIDE
Object is fully in Image.
Definition Image.h:129
Iris attributes Holds the iris attributes.
Definition IrisAttributes.h:32
Iris detector configuration.
Definition IrisDetector.h:36
void WriteTo(Writer &writer) const final
Function serializes configuration via provided Writer.
Definition IrisDetector.h:115
Type GetDetector() const
Function gets detection type.
Definition IrisDetector.h:68
float GetMaxDetectionSize() const
Function gets max detection size.
Definition IrisDetector.h:87
Type
Type of neural network detector.
Definition IrisDetector.h:42
@ ACCURATE
Neural network iris detector with very high accuracy.
Definition IrisDetector.h:48
@ FAST
The fastest iris detector is used when fast mode is used.
Definition IrisDetector.h:54
static Config Default()
Provides default configuration.
Definition IrisDetector.h:129
Config()=default
Creates Default configuration.
void SetDetector(Type value)
Function sets type of detector.
Definition IrisDetector.h:60
float GetMinDetectionSize() const
Function gets min detection size.
Definition IrisDetector.h:106
void SetMaxDetectionSize(float value)
Function sets max detection size.
Definition IrisDetector.h:79
void SetMinDetectionSize(float value)
Function sets min detection size.
Definition IrisDetector.h:98
IrisDetector implements detection by means of Innovatrics IFace.
Definition IrisDetector.h:29
IrisDetector()
Construct a new IrisDetector object GlobalIrisExecutor is used for execution of iris functionality.
Definition IrisDetector.h:239
std::shared_ptr< IrisSegment > Detect(const std::shared_ptr< Image > &image, const IrisPosition &position, const IrisAttributes &ia=IrisAttributes()) const
Detect iris in given image.
Definition IrisDetector.h:169
IrisDetector(std::shared_ptr< IrisExecutor > executor)
Construct a new IrisDetector object Default Config is used.
Definition IrisDetector.h:280
IrisDetector(Config config, std::shared_ptr< IrisExecutor > executor)
Construct a new IrisDetector object.
Definition IrisDetector.h:263
IrisDetector(Config config)
Construct a new IrisDetector object GlobalIrisExecutor is used for execution of iris functionality.
Definition IrisDetector.h:251
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
IrisPosition
It is position of iris on face iso_19794-6_2011.
Definition IrisPosition.h:22