Face Engine SDK  5.11.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 "IObject.h"
11 #include "IDetector.h"
12 #include "FSDKError.h"
13 #include "Types.h"
14 #include <limits>
15 
16 namespace fsdk {
17 
18 #ifndef DOXYGEN_SHOULD_SKIP_THIS
19  DECLARE_SMARTPTR(IDescriptor);
20  DECLARE_SMARTPTR(IDescriptorBatch);
21  DECLARE_SMARTPTR(IDescriptorMatcher);
22  DECLARE_SMARTPTR(IDescriptorExtractor);
23 #endif
24 
34  struct MatchingResult {
35  float distance;
36  float similarity;
37 
41  MatchingResult(void) noexcept
42  : distance(std::numeric_limits<float>::infinity())
43  , similarity(0.f)
44  {}
45 
52  float distance,
53  float similarity) noexcept
56  {}
57  };
58 
66  };
67 
72  enum DescriptorVersion : uint32_t {
75  };
76 
81  enum HumanDescriptorVersion : uint32_t {
88  };
89 
99  virtual uint32_t getModelVersion() const noexcept = 0;
100 
106  virtual DescriptorType getDescriptorType() const noexcept = 0;
107 
113  virtual uint32_t getDescriptorLength() const noexcept = 0;
114 
122  virtual bool getDescriptor(uint8_t* buffer) const noexcept = 0;
123 
128  virtual void setDescriptor(const uint8_t* buffer) noexcept = 0;
129  };
130 
147  enum class Error : uint32_t {
148  Ok,
149  InvalidInput,
150  BatchFull,
151  Incompatible,
152  Internal,
153  IoError,
154  OutOfRange,
155  };
156 
164  virtual Result<Error> add(IDescriptor* descriptor) noexcept = 0;
165 
182  virtual Result<Error> add(IDescriptorBatch* batch, uint32_t offset = 0) noexcept = 0;
183 
199  virtual Result<Error> add(IDescriptorBatch* batch, uint32_t offset, uint32_t count) noexcept = 0;
200 
208  virtual Result<Error> removeFast(uint32_t index) noexcept = 0;
209 
217  virtual Result<Error> removeSlow(uint32_t index) noexcept = 0;
218 
227  virtual Result<MultiError<ISerializableObject::Error,Error>> loadAndAdd(IArchive* archive) = 0;
228 
233  virtual uint32_t getMaxCount() const noexcept = 0;
234 
239  virtual uint32_t getCount() const noexcept = 0;
240 
247  virtual uint32_t getModelVersion() const noexcept = 0;
248 
255  virtual DescriptorType getDescriptorType() const noexcept = 0;
256 
261  virtual uint32_t getDescriptorLength() const noexcept = 0;
262 
269  virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorSlow(uint32_t index) const noexcept = 0;
270 
278  virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorFast(uint32_t index) noexcept = 0;
279  };
280 
284  template<>
285  struct ErrorTraits<IDescriptorBatch::Error> {
286  static bool isOk(IDescriptorBatch::Error error) noexcept {
287  return error == IDescriptorBatch::Error::Ok;
288  }
289 
290  static const char* toString (IDescriptorBatch::Error error) noexcept {
291  switch(error) {
292  case IDescriptorBatch::Error::Ok: return "Ok";
293  case IDescriptorBatch::Error::IoError: return "Error during reading/writing";
294  case IDescriptorBatch::Error::Internal: return "Internal error";
295  case IDescriptorBatch::Error::BatchFull: return "Batch is full";
296  case IDescriptorBatch::Error::OutOfRange: return "Descriptor out of range";
297  case IDescriptorBatch::Error::Incompatible: return "Incompatible descriptor";
298  case IDescriptorBatch::Error::InvalidInput: return "Invalid input";
299  default: return "Unknown error";
300  }
301  }
302  };
303 
322  extractFromWarpedImage(
323  const Image& warp,
324  IDescriptor* descriptor) const noexcept = 0;
325 
344  extractFromWarpedImageBatch(
345  Span<const Image> warps,
346  IDescriptorBatch* descriptorBatch,
347  IDescriptor* aggregation,
348  Span<float> garbageScoreBatch) const noexcept = 0;
349 
365  virtual Result<FSDKError>
366  extractFromWarpedImageBatch(
367  Span<const Image> warps,
368  IDescriptorBatch* descriptorBatch,
369  Span<float> garbageScoreBatch) const noexcept = 0;
370 
381  virtual Result<FSDKError>
382  validate(
383  Span<const Image> warps,
384  Span<Result<FSDKError>> errors) const noexcept = 0;
385 
390  virtual uint32_t getModelVersion() const noexcept = 0;
391 
396  virtual DescriptorType getDescriptorType() const noexcept = 0;
397 
401  using FutureResult = vlc::future<float>;
402 
421  virtual FutureResult extractFromWarpedImageBatchAsync(
422  Span<const Image> warps,
423  IDescriptorBatch* descriptorBatch,
424  IDescriptor* aggregation,
425  Span<float> garbageScoreBatch) const = 0;
426  };
427 
449  virtual ResultValue<
450  FSDKError,
452  match(
453  const IDescriptor* first,
454  const IDescriptor* second) noexcept = 0;
455 
469  virtual Result<FSDKError>
470  match(
471  const IDescriptor* reference,
472  const IDescriptorBatch* candidates,
473  Span<MatchingResult> results) noexcept = 0;
474 
479  virtual uint32_t getModelVersion() const noexcept = 0;
480 
490  virtual Result<FSDKError> calcSimilarity(Span<MatchingResult> distances) const noexcept = 0;
491 
501  virtual Result<FSDKError> calcDistance(Span<MatchingResult> similarities) const noexcept = 0;
502  };
504 }
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:72
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:59
An internal processing error (Ex: memopry allocation or misalignment).
A structure that encapsulates an action result enumeration.
Definition: Result.h:29
Common data types and structures.
An error structure designed for functions which can return errors from different enum classes...
Definition: MultiError.h:17
Error
Descriptor batch error enumeration.
Definition: IDescriptor.h:147
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:83
HumanDescriptorVersion
Human descriptor model versions. Determines which version of human descriptor to use.
Definition: IDescriptor.h:81
Descriptor batch interface.
Definition: IDescriptor.h:142
human descriptor for tracking of people, light and fast version.
Definition: IDescriptor.h:85
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:68
virtual Result< Error > add(IDescriptor *descriptor) noexcept=0
Add a descriptor to the batch.
Definition: Result.h:9
Trying to add an incompatible descriptor.
human descriptor for tracking of people, light and fast version.
Definition: IDescriptor.h:82
Base strong reference counted object interface.
Definition: IRefCounted.h:36
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:441
virtual void setDescriptor(const uint8_t *buffer) noexcept=0
Copy descriptor from user providedbuffer.
human descriptor.
Definition: IDescriptor.h:65
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:36
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:25
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:308
MatchingResult(void) noexcept
Initializes result to default values.
Definition: IDescriptor.h:41
virtual Result< Error > removeSlow(uint32_t index) noexcept=0
Remove a descriptor from batch.
Image.
Definition: Image.h:38
Result of descriptor matching.
Definition: IDescriptor.h:34
Descriptor interface.
Definition: IDescriptor.h:94
Data storage object interface helper.
Definition: IObject.h:157
face descriptor.
Definition: IDescriptor.h:73
regular human descriptor.
Definition: IDescriptor.h:84
Error while trying open/read/write file.
Archive interface.
Definition: IObject.h:37
precise human descriptor, heavy and slow.
Definition: IDescriptor.h:86
FSDKError
Common SDK error codes.
Definition: FSDKError.h:17
human descriptor.
Definition: IDescriptor.h:74
float distance
distance between descriptor vectors.
Definition: IDescriptor.h:35
DescriptorType
Descriptor type enum. Determines which type of descriptor to use.
Definition: IDescriptor.h:63
Invalid input (Ex: null pointer while a valid object is expected).
MatchingResult(float distance, float similarity) noexcept
Initializes result.
Definition: IDescriptor.h:51
vlc::future< float > FutureResult
Common aliases for BestShotQuality asynchronous interface.
Definition: IDescriptor.h:401
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:64
virtual DescriptorType getDescriptorType() const noexcept=0
Get type of descriptor.
regular human descriptor.
Definition: IDescriptor.h:87