Face Engine SDK  5.17.0
A face detection, recognition and tracking engine.
include/fsdk/IDescriptor.h
Go to the documentation of this file.
00001 
00008 #pragma once
00009 
00010 #include <fsdk/IObject.h>
00011 #include <fsdk/IDetector.h>
00012 #include <fsdk/FSDKError.h>
00013 #include <fsdk/Types.h>
00014 
00015 #include <limits>
00016 
00017 namespace fsdk {
00018 
00019 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00020     DECLARE_SMARTPTR(IDescriptor);
00021     DECLARE_SMARTPTR(IDescriptorBatch);
00022     DECLARE_SMARTPTR(IDescriptorMatcher);
00023     DECLARE_SMARTPTR(IDescriptorExtractor);
00024 #endif
00025     
00035     struct MatchingResult {
00036         float distance;     
00037         float similarity;   
00038 
00042         MatchingResult(void) noexcept
00043             : distance(std::numeric_limits<float>::infinity())
00044             , similarity(0.f)
00045         {}
00046 
00052         MatchingResult(
00053             float distance,
00054             float similarity) noexcept
00055             : distance(distance)
00056             , similarity(similarity)
00057         {}
00058     };
00059     
00064     enum DescriptorType {
00065         DT_FACE,        
00066         DT_HUMAN        
00067     };
00068     
00073     enum DescriptorVersion : uint32_t {
00074         DV_MIN_FACE_DESCRIPTOR_VERSION  = 46,       
00075         DV_MIN_HUMAN_DESCRIPTOR_VERSION = 102       
00076     };
00077 
00082     enum HumanDescriptorVersion : uint32_t {
00083         HDV_TRACKER_HUMAN_DESCRIPTOR_VERSION = 102,     
00084         HDV_PRECISE_HUMAN_DESCRIPTOR_VERSION = 103,     
00085         HDV_REGULAR_HUMAN_DESCRIPTOR_VERSION = 104,     
00086         HDV_TRACKER_V2 = 105,                           
00087         HDV_PRECISE_V2 = 106,                           
00088         HDV_REGULAR_V2 = 107,                           
00089         HDV_TRACKER_V3 = 108,                           
00090         HDV_PRECISE_V3 = 109,                           
00091         HDV_REGULAR_V3 = 110,                           
00092         HDV_PRECISE_V4 = 112,                           
00093         HDV_REGULAR_V4 = 113                            
00094     };
00095     
00100     struct IDescriptor : IDataStorageObject {
00105         virtual uint32_t getModelVersion() const noexcept = 0;
00106         
00112         virtual DescriptorType getDescriptorType() const noexcept = 0;
00113 
00119         virtual uint32_t getDescriptorLength() const noexcept = 0;
00120 
00128         virtual bool getDescriptor(uint8_t* buffer) const noexcept = 0;
00129 
00134         virtual void setDescriptor(const uint8_t* buffer) noexcept = 0;
00135     };
00136 
00148     struct IDescriptorBatch : IDataStorageObject {
00153         enum class Error : uint32_t {
00154             Ok,             
00155             InvalidInput,   
00156             BatchFull,      
00157             Incompatible,   
00158             Internal,       
00159             IoError,        
00160             OutOfRange,     
00161         };
00162 
00170         virtual Result<Error> add(IDescriptor* descriptor) noexcept = 0;
00171 
00188         virtual Result<Error> add(IDescriptorBatch* batch, uint32_t offset = 0) noexcept = 0;
00189 
00205         virtual Result<Error> add(IDescriptorBatch* batch, uint32_t offset, uint32_t count) noexcept = 0;
00206 
00214         virtual Result<Error> removeFast(uint32_t index) noexcept = 0;
00215 
00223         virtual Result<Error> removeSlow(uint32_t index) noexcept = 0;
00224 
00233         virtual Result<MultiError<ISerializableObject::Error,Error>> loadAndAdd(IArchive* archive) = 0;
00234 
00239         virtual uint32_t getMaxCount() const noexcept = 0;
00240 
00245         virtual uint32_t getCount() const noexcept = 0;
00246 
00253         virtual uint32_t getModelVersion() const noexcept = 0;
00254         
00261         virtual DescriptorType getDescriptorType() const noexcept = 0;
00262 
00267         virtual uint32_t getDescriptorLength() const noexcept = 0;
00268 
00275         virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorSlow(uint32_t index) const noexcept = 0;
00276 
00284         virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorFast(uint32_t index) noexcept = 0;
00285     };
00286 
00290     template<>
00291     struct ErrorTraits<IDescriptorBatch::Error> {
00292         static bool isOk(IDescriptorBatch::Error error) noexcept {
00293             return error == IDescriptorBatch::Error::Ok;
00294         }
00295 
00296         static const char* toString (IDescriptorBatch::Error error) noexcept {
00297             switch(error) {
00298                 case IDescriptorBatch::Error::Ok: return "Ok";
00299                 case IDescriptorBatch::Error::IoError: return "Error during reading/writing";
00300                 case IDescriptorBatch::Error::Internal: return "Internal error";
00301                 case IDescriptorBatch::Error::BatchFull: return "Batch is full";
00302                 case IDescriptorBatch::Error::OutOfRange: return "Descriptor out of range";
00303                 case IDescriptorBatch::Error::Incompatible: return "Incompatible descriptor";
00304                 case IDescriptorBatch::Error::InvalidInput: return "Invalid input";
00305                 default: return "Unknown error";
00306             }
00307         }
00308     };
00309     
00314     struct IDescriptorExtractor : IRefCounted {
00327         virtual ResultValue<FSDKError, float>
00328         extractFromWarpedImage(
00329             const Image& warp,
00330             IDescriptor* descriptor) const noexcept = 0;
00331 
00349         virtual ResultValue<FSDKError, float>
00350         extractFromWarpedImageBatch(
00351             Span<const Image> warps,
00352             IDescriptorBatch* descriptorBatch,
00353             IDescriptor* aggregation,
00354             Span<float> garbageScoreBatch) const noexcept = 0;
00355 
00371         virtual Result<FSDKError>
00372         extractFromWarpedImageBatch(
00373             Span<const Image> warps,
00374             IDescriptorBatch* descriptorBatch,
00375             Span<float> garbageScoreBatch) const noexcept = 0;
00376 
00387         virtual Result<FSDKError>
00388         validate(
00389             Span<const Image> warps,
00390             Span<Result<FSDKError>> errors) const noexcept = 0;
00391 
00396         virtual uint32_t getModelVersion() const noexcept = 0;
00397         
00402         virtual DescriptorType getDescriptorType() const noexcept = 0;
00403 
00407          using FutureResult = vlc::future<float>;
00408 
00427         virtual FutureResult extractFromWarpedImageBatchAsync(
00428             Span<const Image> warps,
00429             IDescriptorBatch* descriptorBatch,
00430             IDescriptor* aggregation,
00431             Span<float> garbageScoreBatch) const = 0;
00432     };
00433 
00447     struct IDescriptorMatcher : IRefCounted {
00455         virtual ResultValue<
00456                 FSDKError,
00457                 MatchingResult>
00458         match(
00459             const IDescriptor* first,
00460             const IDescriptor* second) noexcept = 0;
00461 
00475         virtual Result<FSDKError>
00476         match(
00477             const IDescriptor* reference,
00478             const IDescriptorBatch* candidates,
00479             Span<MatchingResult> results) noexcept = 0;
00480 
00485         virtual uint32_t getModelVersion() const noexcept = 0;
00486 
00496         virtual Result<FSDKError> calcSimilarity(Span<MatchingResult> distances) const noexcept = 0;
00497 
00507         virtual Result<FSDKError> calcDistance(Span<MatchingResult> similarities) const noexcept = 0;
00508     };
00510 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines