| Face Engine SDK 4.9.0 A face detection, recognition and tracking engine.

IIndex.h
1 #pragma once
2
3 #include "IAsyncContext.h"
4 #include "IDescriptor.h"
5
6 namespace fsdk {
7
8 #ifndef DOXYGEN_SHOULD_SKIP_THIS
9 DECLARE_SMARTPTR(IStaticDescriptorStorage);
10 DECLARE_SMARTPTR(IDynamicDescriptorStorage);
11 DECLARE_SMARTPTR(IIndex);
12 DECLARE_SMARTPTR(IDenseIndex);
13 DECLARE_SMARTPTR(IDynamicIndex);
14 DECLARE_SMARTPTR(IIndexBuilder);
15 #endif
16
18 using DescriptorId = size_t;
19
23 struct SearchResult : MatchingResult {
25 DescriptorId index;
26
28 SearchResult() noexcept
29 : MatchingResult()
30 , index(std::numeric_limits<DescriptorId>::max())
31 {}
32
39 SearchResult(
40 float distance,
41 float similarity,
42 DescriptorId index) noexcept
43 : MatchingResult(distance, similarity)
44 , index(index)
45 {}
46 };
47
52 struct IStaticDescriptorStorage {
62 virtual Result<FSDKError> descriptorByIndex(
63 const DescriptorId index,
64 IDescriptor* descriptor) const noexcept = 0;
65
70 virtual uint64_t size() const noexcept = 0;
71 };
72
77 struct IDynamicDescriptorStorage
78 : IStaticDescriptorStorage {
89 virtual ResultValue<FSDKError, DescriptorId> appendDescriptor(
90 const IDescriptor* desciptor) noexcept = 0;
91
103 virtual ResultValue<FSDKError, DescriptorId> appendBatch(
104 const IDescriptorBatch* batch) noexcept = 0;
105
120 virtual Result<FSDKError> removeDescriptor(const DescriptorId index) noexcept = 0;
121 };
122
127 struct IIndex
128 : IRefCounted {
139 virtual ResultValue<FSDKError, int> search(
140 const IDescriptor* reference,
141 int maxResultsCount,
142 SearchResult* results) const noexcept = 0;
143 };
144
148 struct IDenseIndex
149 : IStaticDescriptorStorage
150 , IIndex {
151
152 };
153
157 struct IDynamicIndex
158 : IDynamicDescriptorStorage
159 , IIndex {
168 virtual Result<FSDKError> saveToDenseIndex(const char* path) const noexcept = 0;
169
178 virtual Result<FSDKError> saveToDynamicIndex(const char* path) const noexcept = 0;
179
193 virtual uint64_t countOfIndexedDescriptors() const noexcept = 0;
194 };
195
200 struct IProgressTracker {
205 virtual void progress(const float completion) const noexcept = 0;
206 };
207
211 struct IIndexBuilder
212 : IDynamicDescriptorStorage
213 , IRefCounted {
222 virtual ResultValue<FSDKError, IDynamicIndex*> buildIndex(
223 const IProgressTracker* const progressTracker = nullptr) noexcept = 0;
224
234 virtual ResultValue<FSDKError, Future<ResultValue<FSDKError, IDynamicIndex*>>>
235 buildIndexAsync(
236 IAsyncContext* const asyncContext,
237 const IProgressTracker* const progressTracker = nullptr) noexcept = 0;
238 };
239
240
241 }
242
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:59
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::IDynamicDescriptorStorage::removeDescriptor
virtual Result< FSDKError > removeDescriptor(const DescriptorId index) noexcept=0
Removes descriptor out of internal storage. If used on.
fsdk::IDynamicIndex::saveToDenseIndex
virtual Result< FSDKError > saveToDenseIndex(const char *path) const noexcept=0
Saves index as dense.
fsdk::Result< FSDKError >
fsdk::IIndex
Base index interface.
Definition: IIndex.h:127
fsdk::IProgressTracker
Progress tracker interface.
Definition: IIndex.h:200
fsdk::SearchResult
Result of index search.
Definition: IIndex.h:23
fsdk::IDescriptorBatch
Descriptor batch interface.
Definition: IDescriptor.h:130
fsdk::IIndexBuilder::buildIndexAsync
virtual ResultValue< FSDKError, Future< ResultValue< FSDKError, IDynamicIndex * > > > buildIndexAsync(IAsyncContext *const asyncContext, const IProgressTracker *const progressTracker=nullptr) noexcept=0
Builds index with every descriptor appended. Non blocking operation.
fsdk::IStaticDescriptorStorage::size
virtual uint64_t size() const noexcept=0
Return size of internal storage.
fsdk::IDynamicIndex::countOfIndexedDescriptors
virtual uint64_t countOfIndexedDescriptors() const noexcept=0
Returns count of indexed descriptors.
fsdk::IRefCounted
Base strong reference counted object interface.
Definition: IRefCounted.h:36
fsdk::IAsyncContext
Interface for running tasks asynchronously.
Definition: IAsyncContext.h:24
fsdk::SearchResult::SearchResult
SearchResult() noexcept
Default constructor.
Definition: IIndex.h:28
fsdk::IStaticDescriptorStorage::descriptorByIndex
virtual Result< FSDKError > descriptorByIndex(const DescriptorId index, IDescriptor *descriptor) const noexcept=0
Requests descriptor data out of internal storage.
IDescriptor.h
Descriptor extractor and matcher interfaces.
fsdk::MatchingResult::similarity
float similarity
similarity (normalized in [0..1] range).
Definition: IDescriptor.h:37
fsdk::IDynamicIndex
Dynamic index interface.
Definition: IIndex.h:157
fsdk::DescriptorId
size_t DescriptorId
Intergral type used as identification of descriptor in internal storage.
Definition: IIndex.h:18
fsdk::IDynamicIndex::saveToDynamicIndex
virtual Result< FSDKError > saveToDynamicIndex(const char *path) const noexcept=0
Saves index as dynamic.
fsdk::ResultValue
Addon for Result to output some value aside the result. Specialization for copiable types...
Definition: ResultValue.h:21
fsdk::MatchingResult::MatchingResult
MatchingResult(void) noexcept
Initializes result to default values.
Definition: IDescriptor.h:42
IAsyncContext.h
Async context interface.
fsdk::IDynamicDescriptorStorage::appendDescriptor
virtual ResultValue< FSDKError, DescriptorId > appendDescriptor(const IDescriptor *desciptor) noexcept=0
Appends descriptor to internal storage. If used on.
fsdk::SearchResult::SearchResult
SearchResult(float distance, float similarity, DescriptorId index) noexcept
Construct structure with parameters.
Definition: IIndex.h:39
fsdk::IDenseIndex
Dense (read only) index interface.
Definition: IIndex.h:148
fsdk::MatchingResult
Result of descriptor matching.
Definition: IDescriptor.h:34
fsdk::SearchResult::index
DescriptorId index
Identificator of descriptor in some storage.
Definition: IIndex.h:25
fsdk::IIndex::search
virtual ResultValue< FSDKError, int > search(const IDescriptor *reference, int maxResultsCount, SearchResult *results) const noexcept=0
Search for descriptors with the shorter distance to passed descriptor.
fsdk::IDescriptor
Descriptor interface.
Definition: IDescriptor.h:82
fsdk::MatchingResult::distance
float distance
distance between descriptor vectors.
Definition: IDescriptor.h:36
fsdk::IIndexBuilder::buildIndex
virtual ResultValue< FSDKError, IDynamicIndex * > buildIndex(const IProgressTracker *const progressTracker=nullptr) noexcept=0
Builds index with every descriptor appended. Blocks until completed.
fsdk::IDynamicDescriptorStorage
Dynamic descriptor storage interface.
Definition: IIndex.h:77
fsdk::IIndexBuilder
Index builder interface.
Definition: IIndex.h:211
fsdk::IDynamicDescriptorStorage::appendBatch
virtual ResultValue< FSDKError, DescriptorId > appendBatch(const IDescriptorBatch *batch) noexcept=0
Appends batch of descriptors to internal storage. If used on.
fsdk::IStaticDescriptorStorage
Static descriptor storage interface.
Definition: IIndex.h:52
fsdk::IProgressTracker::progress
virtual void progress(const float completion) const noexcept=0
Function is called on some operation progress change.