9 #ifndef __PBIO_API__PBIO__RECOGNIZER_H_
10 #define __PBIO_API__PBIO__RECOGNIZER_H_
17 #include "ComplexObject.h"
19 #include "RawSample.h"
23 #include "stl_wraps_impls/WrapIStreamBufferImpl.h"
24 #include "stl_wraps_impls/WrapIStreamImpl.h"
25 #include "stl_wraps_impls/WrapOStreamImpl.h"
46 typedef LightSmartPtr<Recognizer>::tPtr
Ptr;
370 const void*
const data,
371 const int size)
const;
448 const std::vector<pbio::Template::Ptr> &templates,
449 const int search_threads_count = 1,
450 const int reserve_queries_count = 0)
const;
454 const uint64_t templates_count,
455 const int search_threads_count = 1,
456 const int reserve_queries_count = 0)
const;
502 std::vector<SearchResult>
search(
554 std::vector<std::vector<SearchResult> >
search(
555 const std::vector<pbio::Template::Ptr> &queries_templates,
595 const size_t set_size,
596 const std::vector<pbio::Template::Ptr> &templates,
597 const std::vector<size_t> &inviolable_templates_indexes = std::vector<size_t>());
602 const DHPtr &dll_handle,
606 friend class object_with_ref_counter<
Recognizer>;
621 Recognizer::Recognizer(
622 const DHPtr &dll_handle,
624 ComplexObject(dll_handle, impl)
633 std::ostringstream name_stream;
634 pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
636 void* exception = NULL;
638 _dll_handle->Recognizer_getMethodName(
641 pbio::stl_wraps::WrapOStream::write_func,
644 checkException(exception, *_dll_handle);
646 return name_stream.str();
654 void* exception = NULL;
656 void*
const result_impl = _dll_handle->Recognizer_processing(
658 (
const pbio::facerec::RawSampleImpl*) sample._impl,
661 checkException(exception, *_dll_handle);
663 return Template::Ptr::make(_dll_handle, result_impl);
670 pbio::stl_wraps::WrapIStreamImpl binary_stream_wrap(binary_stream);
678 void* exception = NULL;
680 void*
const result_impl = _dll_handle->Recognizer_loadTemplate(
683 pbio::stl_wraps::WrapIStream::read_func,
686 checkException(exception, *_dll_handle);
688 return Template::Ptr::make(_dll_handle, result_impl);
694 const void*
const data,
695 const int size)
const
697 void* exception = NULL;
699 pbio::stl_wraps::WrapIStreamBufferImpl input_stream((
const char*) data, size);
701 void*
const result_impl = _dll_handle->Recognizer_loadTemplate(
704 pbio::stl_wraps::WrapIStream::read_func,
707 checkException(exception, *_dll_handle);
709 return Template::Ptr::make(_dll_handle, result_impl);
720 void* exception = NULL;
722 _dll_handle->Recognizer_verifyMatch_v2(
724 (
const pbio::facerec::TemplateImpl*) template1._impl,
725 (
const pbio::facerec::TemplateImpl*) template2._impl,
732 checkException(exception, *_dll_handle);
739 const std::vector<pbio::Template::Ptr> &templates,
740 const int search_threads_count,
741 const int reserve_queries_count)
const
743 std::vector<const pbio::facerec::TemplateImpl*> templates_impls(templates.size());
745 for(
size_t i = 0; i < templates.size(); ++i)
746 templates_impls[i] = (
const pbio::facerec::TemplateImpl*) templates[i]->_impl;
748 void* exception = NULL;
750 void*
const result_impl =
751 _dll_handle->Recognizer_createIndex(
755 search_threads_count,
758 checkException(exception, *_dll_handle);
762 result->reserveSearchMemory(reserve_queries_count);
769 const uint64_t templates_count,
770 const int search_threads_count,
771 const int reserve_queries_count)
const
773 void* exception = NULL;
775 void*
const result_impl =
776 _dll_handle->Recognizer_createResizableIndex(
779 search_threads_count,
782 checkException(exception, *_dll_handle);
786 result->reserveSearchMemory(reserve_queries_count);
799 std::vector<int64_t> result_i(k);
800 std::vector<float> result_distance(k);
801 std::vector<float> result_far(k);
802 std::vector<float> result_frr(k);
803 std::vector<float> result_score(k);
805 void* exception = NULL;
807 _dll_handle->Recognizer_search_v2(
811 (
const pbio::facerec::TemplateImpl*
const*) &query_template._impl,
812 (
const pbio::facerec::TemplatesIndexImpl*) templates_index._impl,
821 checkException(exception, *_dll_handle);
823 std::vector<SearchResult> result(k);
826 for(
size_t i = 0; i < k; ++i)
834 result[i].i = result_i[i];
835 result[i].match_result.distance = result_distance[i];
836 result[i].match_result.fa_r = result_far[i];
837 result[i].match_result.fr_r = result_frr[i];
838 result[i].match_result.score = result_score[i];
847 const std::vector<pbio::Template::Ptr> &queries_templates,
852 const size_t queries_count = queries_templates.size();
854 std::vector<const pbio::facerec::TemplateImpl*> queries_impls(queries_count);
856 for(
size_t i = 0; i < queries_count; ++i)
858 queries_impls[i] = (
const pbio::facerec::TemplateImpl*) queries_templates[i]->_impl;
861 std::vector<int64_t> result_i(k * queries_count);
862 std::vector<float> result_distance(k * queries_count);
863 std::vector<float> result_far(k * queries_count);
864 std::vector<float> result_frr(k * queries_count);
865 std::vector<float> result_score(k * queries_count);
867 void* exception = NULL;
869 _dll_handle->Recognizer_search_v2(
874 (
const pbio::facerec::TemplatesIndexImpl*) templates_index._impl,
883 checkException(exception, *_dll_handle);
885 std::vector<std::vector<SearchResult> > result(
887 std::vector<SearchResult>(k));
889 for(
size_t i = 0; i < queries_count; ++i)
891 for(
size_t j = 0; j < k; ++j)
893 const size_t h = i * k + j;
901 result[i][j].i = result_i[h];
902 result[i][j].match_result.distance = result_distance[h];
903 result[i][j].match_result.fa_r = result_far[h];
904 result[i][j].match_result.fr_r = result_frr[h];
905 result[i][j].match_result.score = result_score[h];
918 const double distance_threshold)
const
922 void* exception = NULL;
924 _dll_handle->Recognizer_getROCCurvePointByDistanceThreshold_v2(
933 checkException(exception, *_dll_handle);
940 const double desired_far)
const
944 void* exception = NULL;
946 _dll_handle->Recognizer_getROCCurvePointByFAR_v2(
955 checkException(exception, *_dll_handle);
962 const double desired_frr)
const
966 void* exception = NULL;
968 _dll_handle->Recognizer_getROCCurvePointByFRR_v2(
977 checkException(exception, *_dll_handle);
985 const double score_threshold)
const
989 void* exception = NULL;
991 _dll_handle->Recognizer_getROCCurvePointByScoreThreshold(
1000 checkException(exception, *_dll_handle);
1007 const size_t set_size,
1008 const std::vector<pbio::Template::Ptr> &templates,
1009 const std::vector<size_t> &inviolable_templates_indexes)
1011 std::vector<pbio::facerec::TemplateImpl const*> template_impls(templates.size());
1013 for(
size_t i = 0; i < templates.size(); ++i)
1014 template_impls[i] = (pbio::facerec::TemplateImpl
const*) templates[i]->_impl;
1016 std::vector<int8_t> inv_flags_8(templates.size(), 0);
1018 for(
size_t i = 0; i < inviolable_templates_indexes.size(); ++i)
1020 const size_t j = inviolable_templates_indexes[i];
1022 if(j >= templates.size())
1025 "Error: bad index in chooseRepresentativeTemplatesSet, error code: 0x63156958");
1030 std::vector<int32_t> result(set_size);
1032 void* exception = NULL;
1034 _dll_handle->Recognizer_chooseRepresentativeTemplatesSet(
1036 template_impls.empty() ? NULL : template_impls.data(),
1037 inv_flags_8.empty() ? NULL : inv_flags_8.data(),
1039 result.empty() ? NULL : result.data(),
1043 checkException(exception, *_dll_handle);
1045 return std::vector<size_t>(result.begin(), result.end());
1052 #endif // __PBIO_API__PBIO__RECOGNIZER_H_
MatchResult getROCCurvePointByScoreThreshold(const double score_threshold) const
Get a point on the ROC curve with a given similarity score threshold. Thread-safe.
Definition: Recognizer.h:984
Template::Ptr loadTemplate(std::istream &binary_stream) const
Load the template. The format is platform-independent. Only the templates that were created with the ...
Definition: Recognizer.h:668
Result of template matching.
Definition: Recognizer.h:15
Interface object for creating other interface objects.
Definition: FacerecService.h:64
TemplatesIndex::Ptr createIndex(const std::vector< pbio::Template::Ptr > &templates, const int search_threads_count=1, const int reserve_queries_count=0) const
Create the TemplatesIndex for quick search. The total size of all indexes is limited by the license...
Definition: Recognizer.h:738
MatchResult match_result
Result of matching the query Template with the i-th Template from the TemplatesIndex.
Definition: Recognizer.h:111
Interface object that stores a captured face sample.
Definition: RawSample.h:49
Interface object for saving the face template.
Definition: Template.h:37
double score
Score of templates similarity - real number from 0 to 1.
Definition: Recognizer.h:89
double distance
Distance between the templates.
Definition: Recognizer.h:60
Interface object for working with the template index.
Definition: TemplatesIndex.h:37
std::string getMethodName() const
Get a method name. Thread-safe.
Definition: Recognizer.h:631
Heuristically accelerated linear search. Heuristics reduces TAR (true acceptance rate) on the 1:N tes...
Definition: Recognizer.h:143
Interface object for creating and matching templates.
Definition: Recognizer.h:37
LightSmartPtr< Template >::tPtr Ptr
Alias for the type of a smart pointer to Template.
Definition: Template.h:46
LightSmartPtr< TemplatesIndex >::tPtr Ptr
Alias for the type of a smart pointer to TemplatesIndex.
Definition: TemplatesIndex.h:46
Template::Ptr processing(const RawSample &sample) const
Create a template.
Definition: Recognizer.h:651
Error - the class of exceptions thrown when errors occur.
SearchAccelerationType
Types of search acceleration.
Definition: Recognizer.h:119
Result of template matching.
Definition: Recognizer.h:53
std::vector< size_t > chooseRepresentativeTemplatesSet(const size_t set_size, const std::vector< pbio::Template::Ptr > &templates, const std::vector< size_t > &inviolable_templates_indexes=std::vector< size_t >())
Choose templates set that best represent original templates.
Definition: Recognizer.h:1006
Result of searching the Template query in the TemplatesIndex.
Definition: Recognizer.h:97
std::vector< SearchResult > search(const pbio::Template &query_template, const pbio::TemplatesIndex &templates_index, const size_t k, const SearchAccelerationType acceleration=SEARCH_ACCELERATION_1) const
Search for the k nearest Templates in the TemplatesIndex. The search time depends on k and the size o...
Definition: Recognizer.h:793
LightSmartPtr< Recognizer >::tPtr Ptr
Alias for the type of a smart pointer to Recognizer.
Definition: Recognizer.h:46
The class of exceptions thrown when errors occur.
Definition: Error.h:26
double fa_r
False acceptance rate corresponding to the distance value taken as a threshold at the extended LFW te...
Definition: Recognizer.h:71
MatchResult getROCCurvePointByFRR(const double desired_frr) const
Get a point on the ROC curve with a given false rejection rate (FRR). Thread-safe.
Definition: Recognizer.h:961
TemplatesIndex - Interface object for working with the template index.
MatchResult verifyMatch(const Template &template1, const Template &template2) const
Compare two templates. The order of templates does not matter. Only the templates that were created w...
Definition: Recognizer.h:714
size_t i
Index in the TemplatesIndex.
Definition: Recognizer.h:104
MatchResult getROCCurvePointByDistanceThreshold(const double distance_threshold) const
Get a point on the ROC curve with a given distance threshold. Thread-safe.
Definition: Recognizer.h:917
No acceleration, a standard line search. The result is identical to N calls of Recognizer::verifyMatc...
Definition: Recognizer.h:130
Definition: FacerecService.mm:79
MatchResult getROCCurvePointByFAR(const double desired_far) const
Get a point on the ROC curve with a given false acceptance rate (FAR). Thread-safe.
Definition: Recognizer.h:939
double fr_r
False rejection rate corresponding to the distance value taken as a threshold at the extended LFW tes...
Definition: Recognizer.h:82