Face Engine SDK  5.25.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(float distance, float similarity) noexcept
00053             : distance(distance)
00054             , similarity(similarity) {
00055         }
00056     };
00057 
00062     enum DescriptorType {
00063         DT_FACE, 
00064         DT_HUMAN 
00065     };
00066 
00071     enum DescriptorVersion : uint32_t {
00072         DV_MIN_FACE_DESCRIPTOR_VERSION = 54,  
00073         DV_MIN_HUMAN_DESCRIPTOR_VERSION = 102 
00074     };
00075 
00080     enum HumanDescriptorVersion : uint32_t {
00081         HDV_TRACKER_HUMAN_DESCRIPTOR_VERSION = 102, 
00082         HDV_PRECISE_HUMAN_DESCRIPTOR_VERSION = 103, 
00083         HDV_REGULAR_HUMAN_DESCRIPTOR_VERSION = 104, 
00084         HDV_TRACKER_V2 = 105,                       
00085         HDV_PRECISE_V2 = 106,                       
00086         HDV_REGULAR_V2 = 107,                       
00087         HDV_TRACKER_V3 = 108,                       
00088         HDV_PRECISE_V3 = 109,                       
00089         HDV_REGULAR_V3 = 110,                       
00090         HDV_PRECISE_V4 = 112,                       
00091         HDV_REGULAR_V4 = 113,                       
00092         HDV_PRECISE_V5 = 115,                       
00093         HDV_REGULAR_V5 = 116                        
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 
00215         virtual Result<Error> removeFast(uint32_t index) noexcept = 0;
00216 
00225         virtual Result<Error> removeSlow(uint32_t index) noexcept = 0;
00226 
00235         virtual Result<MultiError<ISerializableObject::Error, Error>> loadAndAdd(IArchive* archive) = 0;
00236 
00241         virtual uint32_t getMaxCount() const noexcept = 0;
00242 
00247         virtual uint32_t getCount() const noexcept = 0;
00248 
00255         virtual uint32_t getModelVersion() const noexcept = 0;
00256 
00263         virtual DescriptorType getDescriptorType() const noexcept = 0;
00264 
00269         virtual uint32_t getDescriptorLength() const noexcept = 0;
00270 
00277         virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorSlow(uint32_t index) const noexcept = 0;
00278 
00286         virtual ResultValue<FSDKError, IDescriptorPtr> getDescriptorFast(uint32_t index) noexcept = 0;
00287     };
00288 
00292     template <>
00293     struct ErrorTraits<IDescriptorBatch::Error> {
00294         static bool isOk(IDescriptorBatch::Error error) noexcept {
00295             return error == IDescriptorBatch::Error::Ok;
00296         }
00297 
00298         static const char* toString(IDescriptorBatch::Error error) noexcept {
00299             switch(error) {
00300             case IDescriptorBatch::Error::Ok:
00301                 return "Ok";
00302             case IDescriptorBatch::Error::IoError:
00303                 return "Error during reading/writing";
00304             case IDescriptorBatch::Error::Internal:
00305                 return "Internal error";
00306             case IDescriptorBatch::Error::BatchFull:
00307                 return "Batch is full";
00308             case IDescriptorBatch::Error::OutOfRange:
00309                 return "Descriptor out of range";
00310             case IDescriptorBatch::Error::Incompatible:
00311                 return "Incompatible descriptor";
00312             case IDescriptorBatch::Error::InvalidInput:
00313                 return "Invalid input";
00314             default:
00315                 return "Unknown error";
00316             }
00317         }
00318     };
00319 
00324     struct IDescriptorExtractor : IRefCounted {
00337         virtual ResultValue<FSDKError, float>
00338         extractFromWarpedImage(const Image& warp, IDescriptor* descriptor) const noexcept = 0;
00339 
00357         virtual ResultValue<FSDKError, float> extractFromWarpedImageBatch(
00358             Span<const Image> warps,
00359             IDescriptorBatch* descriptorBatch,
00360             IDescriptor* aggregation,
00361             Span<float> garbageScoreBatch) const noexcept = 0;
00362 
00378         virtual Result<FSDKError> extractFromWarpedImageBatch(
00379             Span<const Image> warps,
00380             IDescriptorBatch* descriptorBatch,
00381             Span<float> garbageScoreBatch) const noexcept = 0;
00382 
00393         virtual Result<FSDKError>
00394         validate(Span<const Image> warps, Span<Result<FSDKError>> errors) const noexcept = 0;
00395 
00400         virtual uint32_t getModelVersion() const noexcept = 0;
00401 
00406         virtual DescriptorType getDescriptorType() const noexcept = 0;
00407 
00411         using FutureResult = vlc::future<float>;
00412 
00431         virtual FutureResult extractFromWarpedImageBatchAsync(
00432             Span<const Image> warps,
00433             IDescriptorBatch* descriptorBatch,
00434             IDescriptor* aggregation,
00435             Span<float> garbageScoreBatch) const = 0;
00436     };
00437 
00451     struct IDescriptorMatcher : IRefCounted {
00459         virtual ResultValue<FSDKError, MatchingResult>
00460         match(const IDescriptor* first, const IDescriptor* second) noexcept = 0;
00461 
00475         virtual Result<FSDKError> match(
00476             const IDescriptor* reference,
00477             const IDescriptorBatch* candidates,
00478             Span<MatchingResult> results) noexcept = 0;
00479 
00484         virtual uint32_t getModelVersion() const noexcept = 0;
00485 
00495         virtual Result<FSDKError> calcSimilarity(Span<MatchingResult> distances) const noexcept = 0;
00496 
00506         virtual Result<FSDKError> calcDistance(Span<MatchingResult> similarities) const noexcept = 0;
00507     };
00508 
00510 } // namespace fsdk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines