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

IIndex.h
1 #pragma once
2
3 #include "IIDMap.h"
4 #include <fsdk/IAsyncContext.h>
5 #include <fsdk/IDescriptor.h>
6
7 namespace fsdk {
8
9 #ifndef DOXYGEN_SHOULD_SKIP_THIS
10 DECLARE_SMARTPTR(IStaticDescriptorStorage);
11 DECLARE_SMARTPTR(IDynamicDescriptorStorage);
12 DECLARE_SMARTPTR(IIndex);
13 DECLARE_SMARTPTR(IDenseIndex);
14 DECLARE_SMARTPTR(IDynamicIndex);
15 DECLARE_SMARTPTR(IIndexBuilder);
16 DECLARE_SMARTPTR(IIDMap);
17 #endif
18
23 enum DynamicIndexState : uint8_t {
24 DIS_INVALID = 0,
25 DIS_VALID,
26 DIS_UNKNOWN,
27 DIS_COUNT
28 };
29
31 using DescriptorId = size_t;
32
36 struct SearchResult : MatchingResult {
38 DescriptorId index;
39
41 SearchResult() noexcept
42 : MatchingResult()
43 , index(std::numeric_limits<DescriptorId>::max()) {
44 }
45
52 SearchResult(float distance, float similarity, DescriptorId index) noexcept
53 : MatchingResult(distance, similarity)
54 , index(index) {
55 }
56 };
57
62 struct IStaticDescriptorStorage {
73 virtual Result<FSDKError>
74 descriptorByIndex(const DescriptorId index, IDescriptor* descriptor) const noexcept = 0;
75
80 virtual uint32_t getDescriptorVersion() const noexcept = 0;
81
86 virtual uint64_t size() const noexcept = 0;
87 };
88
93 struct IDynamicDescriptorStorage : IStaticDescriptorStorage {
105 virtual ResultValue<FSDKError, DescriptorId> appendDescriptor(const IDescriptor* descriptor) noexcept = 0;
106
119 virtual ResultValue<FSDKError, DescriptorId> appendBatch(const IDescriptorBatch* batch) noexcept = 0;
120
138 virtual Result<FSDKError> removeDescriptor(const DescriptorId index) noexcept = 0;
139 };
140
145 struct IIndex : IRefCounted {
156 virtual ResultValue<FSDKError, int>
157 search(const IDescriptor* reference, int maxResultsCount, SearchResult* results) const noexcept = 0;
158 };
159
163 struct IDenseIndex : IStaticDescriptorStorage, IIndex {};
164
168 struct IDynamicIndex : IDynamicDescriptorStorage, IIndex {
178 virtual Result<FSDKError> saveToDenseIndex(const char* path) const noexcept = 0;
179
190 virtual Result<FSDKError> saveToDynamicIndex(const char* path) const noexcept = 0;
191
205 virtual uint64_t countOfIndexedDescriptors() const noexcept = 0;
206
214 virtual ResultValue<FSDKError, IIDMapPtr> eraseRemovedDescriptors() noexcept = 0;
215
222 virtual ResultValue<FSDKError, DynamicIndexState> isValidForSearch() const noexcept = 0;
223
230 virtual ResultValue<FSDKError, float> evaluate() const noexcept = 0;
231 };
232
237 struct IProgressTracker {
242 virtual void progress(const float completion) const noexcept = 0;
243 };
244
248 struct IIndexBuilder : IDynamicDescriptorStorage, IRefCounted {
257 virtual ResultValue<FSDKError, IDynamicIndex*>
258 buildIndex(const IProgressTracker* const progressTracker = nullptr) noexcept = 0;
259
269 virtual ResultValue<FSDKError, Future<ResultValue<FSDKError, IDynamicIndex*>>> buildIndexAsync(
270 IAsyncContext* const asyncContext,
271 const IProgressTracker* const progressTracker = nullptr) noexcept = 0;
272 };
273
274
275 } // namespace fsdk
fsdk::DIS_VALID
DIS_VALID - index is valid for search.
Definition: IIndex.h:25
fsdk::IDynamicDescriptorStorage::appendDescriptor
virtual ResultValue< FSDKError, DescriptorId > appendDescriptor(const IDescriptor *descriptor) noexcept=0
Appends descriptor to internal storage. If used on.
DECLARE_SMARTPTR
#define DECLARE_SMARTPTR(X)
Smart ptr declaration helper macro.
Definition: Def.h:70
fsdk::IStaticDescriptorStorage::getDescriptorVersion
virtual uint32_t getDescriptorVersion() const noexcept=0
Return version of stored descriptors.
fsdk
SDK namespace.
Definition: IAGSEstimator.h:8
fsdk::IDynamicDescriptorStorage::removeDescriptor
virtual Result< FSDKError > removeDescriptor(const DescriptorId index) noexcept=0
Removes descriptor out of graph. If used on.
fsdk::IDynamicIndex::saveToDenseIndex
virtual Result< FSDKError > saveToDenseIndex(const char *path) const noexcept=0
Saves index as dense.
fsdk::Result
A structure that encapsulates an action result enumeration.
Definition: Result.h:27
fsdk::IIndex
Base index interface.
Definition: IIndex.h:145
fsdk::IProgressTracker
Progress tracker interface.
Definition: IIndex.h:237
fsdk::DIS_UNKNOWN
DIS_UNKNOWN - index state is unknown.
Definition: IIndex.h:26
fsdk::SearchResult
Result of index search.
Definition: IIndex.h:36
fsdk::IDescriptorBatch
Descriptor batch interface.
Definition: IDescriptor.h:148
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:37
fsdk::IAsyncContext
Interface for running tasks asynchronously.
Definition: IAsyncContext.h:24
fsdk::SearchResult::SearchResult
SearchResult() noexcept
Default constructor.
Definition: IIndex.h:41
fsdk::DynamicIndexState
DynamicIndexState
Index state. Tells whether index valid for search or not.
Definition: IIndex.h:23
fsdk::IDynamicIndex::isValidForSearch
virtual ResultValue< FSDKError, DynamicIndexState > isValidForSearch() const noexcept=0
Check if graph is valid for search or not.
fsdk::IStaticDescriptorStorage::descriptorByIndex
virtual Result< FSDKError > descriptorByIndex(const DescriptorId index, IDescriptor *descriptor) const noexcept=0
Requests descriptor data out of internal storage.
fsdk::IDynamicIndex::eraseRemovedDescriptors
virtual ResultValue< FSDKError, IIDMapPtr > eraseRemovedDescriptors() noexcept=0
Erases removed descriptors out of index fully.
IDescriptor.h
Descriptor extractor and matcher interfaces.
fsdk::MatchingResult::similarity
float similarity
similarity (normalized in [0..1] range).
Definition: IDescriptor.h:37
fsdk::DescriptorId
size_t DescriptorId
Intergral type used as identification of descriptor in internal storage.
Definition: IIDMap.h:17
fsdk::IDynamicIndex
Dynamic index interface.
Definition: IIndex.h:168
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::SearchResult::SearchResult
SearchResult(float distance, float similarity, DescriptorId index) noexcept
Construct structure with parameters.
Definition: IIndex.h:52
fsdk::IDenseIndex
Dense (read only) index interface.
Definition: IIndex.h:163
fsdk::MatchingResult
Result of descriptor matching.
Definition: IDescriptor.h:35
fsdk::SearchResult::index
DescriptorId index
Identificator of descriptor in some storage.
Definition: IIndex.h:38
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:100
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:93
fsdk::DIS_INVALID
DIS_INVALID - index is invalid for search.
Definition: IIndex.h:24
fsdk::IIndexBuilder
Index builder interface.
Definition: IIndex.h:248
fsdk::IDynamicDescriptorStorage::appendBatch
virtual ResultValue< FSDKError, DescriptorId > appendBatch(const IDescriptorBatch *batch) noexcept=0
Appends batch of descriptors to internal storage. If used on.
fsdk::IDynamicIndex::evaluate
virtual ResultValue< FSDKError, float > evaluate() const noexcept=0
Evaluate if graph is good enough for search or not.
fsdk::IStaticDescriptorStorage
Static descriptor storage interface.
Definition: IIndex.h:62
fsdk::IProgressTracker::progress
virtual void progress(const float completion) const noexcept=0
Function is called on some operation progress change.