Face Engine SDK  5.17.0
A face detection, recognition and tracking engine.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
IDescriptor.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <fsdk/IObject.h>
11 #include <fsdk/IDetector.h>
12 #include <fsdk/FSDKError.h>
13 #include <fsdk/Types.h>
14 
15 #include <limits>
16 
17 namespace fsdk {
18 
19 #ifndef DOXYGEN_SHOULD_SKIP_THIS
20  DECLARE_SMARTPTR(IDescriptor);
21  DECLARE_SMARTPTR(IDescriptorBatch);
22  DECLARE_SMARTPTR(IDescriptorMatcher);
23  DECLARE_SMARTPTR(IDescriptorExtractor);
24 #endif
25 
35  struct MatchingResult {
36  float distance;
37  float similarity;
38 
42  MatchingResult(void) noexcept
43  : distance(std::numeric_limits<float>::infinity())
44  , similarity(0.f)
45  {}
46 
53  float distance,
54  float similarity) noexcept
57  {}
58  };
59 
67  };
68 
73  enum DescriptorVersion : uint32_t {
76  };
77 
82  enum HumanDescriptorVersion : uint32_t {
94  };
95 
105  virtual uint32_t getModelVersion() const noexcept = 0;
106 
112  virtual DescriptorType getDescriptorType() const noexcept = 0;
113 
119  virtual uint32_t getDescriptorLength() const noexcept = 0;
120 
128  virtual bool getDescriptor(uint8_t* buffer) const noexcept = 0;
129 
134  virtual void setDescriptor(const uint8_t* buffer) noexcept = 0;
135  };
136 
153  enum class Error : uint32_t {
154  Ok,
155  InvalidInput,
156  BatchFull,
157  Incompatible,
158  Internal,
159  IoError,
160  OutOfRange,
161  };
162 
170  virtual Result<Error> add(IDescriptor* descriptor) noexcept = 0;
171 
188  virtual Result<Error> add(IDescriptorBatch* batch, uint32_t offset = 0) noexcept = 0;
189 
205  virtual Result<Error> add(IDescriptorBatch* batch, uint32_t offset, uint32_t count) noexcept = 0;
206 
214  virtual Result<Error> removeFast(uint32_t index) noexcept = 0;
215 
223  virtual Result<Error> removeSlow(uint32_t index) noexcept = 0;
224 
233  virtual Result<MultiError<ISerializableObject::Error,Error>> loadAndAdd(IArchive* archive) = 0;
234 
239  virtual uint32_t getMaxCount() const noexcept = 0;
240 
245  virtual uint32_t getCount() const noexcept = 0;
246 
253  virtual uint32_t getModelVersion() const noexcept = 0;
254 
261  virtual DescriptorType getDescriptorType() const noexcept = 0;
262 
267  virtual uint32_t getDescriptorLength() const noexcept = 0;
268 
275  virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorSlow(uint32_t index) const noexcept = 0;
276 
284  virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorFast(uint32_t index) noexcept = 0;
285  };
286 
290  template<>
291  struct ErrorTraits<IDescriptorBatch::Error> {
292  static bool isOk(IDescriptorBatch::Error error) noexcept {
293  return error == IDescriptorBatch::Error::Ok;
294  }
295 
296  static const char* toString (IDescriptorBatch::Error error) noexcept {
297  switch(error) {
298  case IDescriptorBatch::Error::Ok: return "Ok";
299  case IDescriptorBatch::Error::IoError: return "Error during reading/writing";
300  case IDescriptorBatch::Error::Internal: return "Internal error";
301  case IDescriptorBatch::Error::BatchFull: return "Batch is full";
302  case IDescriptorBatch::Error::OutOfRange: return "Descriptor out of range";
303  case IDescriptorBatch::Error::Incompatible: return "Incompatible descriptor";
304  case IDescriptorBatch::Error::InvalidInput: return "Invalid input";
305  default: return "Unknown error";
306  }
307  }
308  };
309 
328  extractFromWarpedImage(
329  const Image& warp,
330  IDescriptor* descriptor) const noexcept = 0;
331 
350  extractFromWarpedImageBatch(
351  Span<const Image> warps,
352  IDescriptorBatch* descriptorBatch,
353  IDescriptor* aggregation,
354  Span<float> garbageScoreBatch) const noexcept = 0;
355 
371  virtual Result<FSDKError>
372  extractFromWarpedImageBatch(
373  Span<const Image> warps,
374  IDescriptorBatch* descriptorBatch,
375  Span<float> garbageScoreBatch) const noexcept = 0;
376 
387  virtual Result<FSDKError>
388  validate(
389  Span<const Image> warps,
390  Span<Result<FSDKError>> errors) const noexcept = 0;
391 
396  virtual uint32_t getModelVersion() const noexcept = 0;
397 
402  virtual DescriptorType getDescriptorType() const noexcept = 0;
403 
407  using FutureResult = vlc::future<float>;
408 
427  virtual FutureResult extractFromWarpedImageBatchAsync(
428  Span<const Image> warps,
429  IDescriptorBatch* descriptorBatch,
430  IDescriptor* aggregation,
431  Span<float> garbageScoreBatch) const = 0;
432  };
433 
455  virtual ResultValue<
456  FSDKError,
458  match(
459  const IDescriptor* first,
460  const IDescriptor* second) noexcept = 0;
461 
475  virtual Result<FSDKError>
476  match(
477  const IDescriptor* reference,
478  const IDescriptorBatch* candidates,
479  Span<MatchingResult> results) noexcept = 0;
480 
485  virtual uint32_t getModelVersion() const noexcept = 0;
486 
496  virtual Result<FSDKError> calcSimilarity(Span<MatchingResult> distances) const noexcept = 0;
497 
507  virtual Result<FSDKError> calcDistance(Span<MatchingResult> similarities) const noexcept = 0;
508  };
510 }
virtual uint32_t getModelVersion() const noexcept=0
Get algorithm model version this descriptor was created with.
DescriptorVersion
Minimum descriptor model version. Determines which minimum version of descriptor to use...
Definition: IDescriptor.h:73
virtual bool getDescriptor(uint8_t *buffer) const noexcept=0
Copy descriptor data to user provided buffer.
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:56
regular human descriptor.
Definition: IDescriptor.h:93
An internal processing error (Ex: memopry allocation or misalignment).
A structure that encapsulates an action result enumeration.
Definition: Result.h:27
Common data types and structures.
An error structure designed for functions which can return errors from different enum classes...
Definition: MultiError.h:14
Error
Descriptor batch error enumeration.
Definition: IDescriptor.h:153
virtual ResultValue< FSDKError, IDescriptorPtr > getDescriptorFast(uint32_t index) noexcept=0
Get descriptor from batch by index without copying.
precise human descriptor, heavy and slow.
Definition: IDescriptor.h:84
HumanDescriptorVersion
Human descriptor model versions. Determines which version of human descriptor to use.
Definition: IDescriptor.h:82
Descriptor batch interface.
Definition: IDescriptor.h:148
human descriptor for tracking of people, light and fast version.
Definition: IDescriptor.h:86
Object system types and interfaces.
virtual Result< MultiError< ISerializableObject::Error, Error > > loadAndAdd(IArchive *archive)=0
Load a descriptor/descriptors from archive and add it to the batch.
virtual uint32_t getDescriptorLength() const noexcept=0
return size of descriptor in bytes.
Common SDK error codes.
Serializable object interface.
Definition: IObject.h:71
virtual Result< Error > add(IDescriptor *descriptor) noexcept=0
Add a descriptor to the batch.
Definition: Result.h:8
Trying to add an incompatible descriptor.
human descriptor for tracking of people, light and fast version.
Definition: IDescriptor.h:83
Base strong reference counted object interface.
Definition: IRefCounted.h:37
virtual Result< Error > removeFast(uint32_t index) noexcept=0
Remove a descriptor from batch.
virtual uint32_t getMaxCount() const noexcept=0
Get maximum number of descriptors in this batch.
Descriptor matcher interface.
Definition: IDescriptor.h:447
virtual void setDescriptor(const uint8_t *buffer) noexcept=0
Copy descriptor from user providedbuffer.
human descriptor.
Definition: IDescriptor.h:66
virtual DescriptorType getDescriptorType() const noexcept=0
Get type of descriptor.
Error while accessing descriptor out of range.
float similarity
similarity (normalized in [0..1] range).
Definition: IDescriptor.h:37
virtual ResultValue< FSDKError, IDescriptorPtr > getDescriptorSlow(uint32_t index) const noexcept=0
Get descriptor from batch by index with copying.
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
Face detector interfaces.
virtual uint32_t getModelVersion() const noexcept=0
Get algorithm model version the descriptors in this batch were created with.
virtual uint32_t getDescriptorLength() const noexcept=0
Get length of one descriptor. Specified by version of descriptors in batch.
virtual uint32_t getCount() const noexcept=0
Get actual number of descriptors in this batch.
Descriptor extractor interface.
Definition: IDescriptor.h:314
MatchingResult(void) noexcept
Initializes result to default values.
Definition: IDescriptor.h:42
virtual Result< Error > removeSlow(uint32_t index) noexcept=0
Remove a descriptor from batch.
Image.
Definition: Image.h:38
precise human descriptor, heavy and slow.
Definition: IDescriptor.h:92
Result of descriptor matching.
Definition: IDescriptor.h:35
regular human descriptor.
Definition: IDescriptor.h:91
Descriptor interface.
Definition: IDescriptor.h:100
Data storage object interface helper.
Definition: IObject.h:167
face descriptor.
Definition: IDescriptor.h:74
regular human descriptor.
Definition: IDescriptor.h:85
Error while trying open/read/write file.
Archive interface.
Definition: IObject.h:38
precise human descriptor, heavy and slow.
Definition: IDescriptor.h:87
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
human descriptor.
Definition: IDescriptor.h:75
float distance
distance between descriptor vectors.
Definition: IDescriptor.h:36
DescriptorType
Descriptor type enum. Determines which type of descriptor to use.
Definition: IDescriptor.h:64
Invalid input (Ex: null pointer while a valid object is expected).
MatchingResult(float distance, float similarity) noexcept
Initializes result.
Definition: IDescriptor.h:52
vlc::future< float > FutureResult
Common aliases for BestShotQuality asynchronous interface.
Definition: IDescriptor.h:407
precise human descriptor, heavy and slow.
Definition: IDescriptor.h:90
Span. Not owning data view. It incapsulated pointer to the continuous array with one or more T objec...
Definition: Span.h:14
face descriptor.
Definition: IDescriptor.h:65
virtual DescriptorType getDescriptorType() const noexcept=0
Get type of descriptor.
human descriptor for tracking of people, light and fast version.
Definition: IDescriptor.h:89
regular human descriptor.
Definition: IDescriptor.h:88