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;
496 std::vector<SearchResult>
search(
548 std::vector<std::vector<SearchResult> >
search(
549 const std::vector<pbio::Template::Ptr> &queries_templates,
589 const size_t set_size,
590 const std::vector<pbio::Template::Ptr> &templates,
591 const std::vector<size_t> &inviolable_templates_indexes = std::vector<size_t>());
596 const DHPtr &dll_handle,
600 friend class object_with_ref_counter<
Recognizer>;
615 Recognizer::Recognizer(
616 const DHPtr &dll_handle,
618 ComplexObject(dll_handle, impl)
627 std::ostringstream name_stream;
628 pbio::stl_wraps::WrapOStreamImpl name_stream_wrap(name_stream);
630 void* exception = NULL;
632 _dll_handle->Recognizer_getMethodName(
635 pbio::stl_wraps::WrapOStream::write_func,
638 checkException(exception, *_dll_handle);
640 return name_stream.str();
648 void* exception = NULL;
650 void*
const result_impl = _dll_handle->Recognizer_processing(
652 (
const pbio::facerec::RawSampleImpl*) sample._impl,
655 checkException(exception, *_dll_handle);
657 return Template::Ptr::make(_dll_handle, result_impl);
664 pbio::stl_wraps::WrapIStreamImpl binary_stream_wrap(binary_stream);
672 void* exception = NULL;
674 void*
const result_impl = _dll_handle->Recognizer_loadTemplate(
677 pbio::stl_wraps::WrapIStream::read_func,
680 checkException(exception, *_dll_handle);
682 return Template::Ptr::make(_dll_handle, result_impl);
688 const void*
const data,
689 const int size)
const
691 void* exception = NULL;
693 pbio::stl_wraps::WrapIStreamBufferImpl input_stream((
const char*) data, size);
695 void*
const result_impl = _dll_handle->Recognizer_loadTemplate(
698 pbio::stl_wraps::WrapIStream::read_func,
701 checkException(exception, *_dll_handle);
703 return Template::Ptr::make(_dll_handle, result_impl);
714 void* exception = NULL;
716 _dll_handle->Recognizer_verifyMatch_v2(
718 (
const pbio::facerec::TemplateImpl*) template1._impl,
719 (
const pbio::facerec::TemplateImpl*) template2._impl,
726 checkException(exception, *_dll_handle);
733 const std::vector<pbio::Template::Ptr> &templates,
734 const int search_threads_count,
735 const int reserve_queries_count)
const
737 std::vector<const pbio::facerec::TemplateImpl*> templates_impls(templates.size());
739 for(
size_t i = 0; i < templates.size(); ++i)
740 templates_impls[i] = (
const pbio::facerec::TemplateImpl*) templates[i]->_impl;
742 void* exception = NULL;
744 void*
const result_impl =
745 _dll_handle->Recognizer_createIndex(
749 search_threads_count,
752 checkException(exception, *_dll_handle);
756 result->reserveSearchMemory(reserve_queries_count);
769 std::vector<int64_t> result_i(k);
770 std::vector<float> result_distance(k);
771 std::vector<float> result_far(k);
772 std::vector<float> result_frr(k);
773 std::vector<float> result_score(k);
775 void* exception = NULL;
777 _dll_handle->Recognizer_search_v2(
781 (
const pbio::facerec::TemplateImpl*
const*) &query_template._impl,
782 (
const pbio::facerec::TemplatesIndexImpl*) templates_index._impl,
791 checkException(exception, *_dll_handle);
793 std::vector<SearchResult> result(k);
796 for(
size_t i = 0; i < k; ++i)
804 result[i].i = result_i[i];
805 result[i].match_result.distance = result_distance[i];
806 result[i].match_result.fa_r = result_far[i];
807 result[i].match_result.fr_r = result_frr[i];
808 result[i].match_result.score = result_score[i];
817 const std::vector<pbio::Template::Ptr> &queries_templates,
822 const size_t queries_count = queries_templates.size();
824 std::vector<const pbio::facerec::TemplateImpl*> queries_impls(queries_count);
826 for(
size_t i = 0; i < queries_count; ++i)
828 queries_impls[i] = (
const pbio::facerec::TemplateImpl*) queries_templates[i]->_impl;
831 std::vector<int64_t> result_i(k * queries_count);
832 std::vector<float> result_distance(k * queries_count);
833 std::vector<float> result_far(k * queries_count);
834 std::vector<float> result_frr(k * queries_count);
835 std::vector<float> result_score(k * queries_count);
837 void* exception = NULL;
839 _dll_handle->Recognizer_search_v2(
844 (
const pbio::facerec::TemplatesIndexImpl*) templates_index._impl,
853 checkException(exception, *_dll_handle);
855 std::vector<std::vector<SearchResult> > result(
857 std::vector<SearchResult>(k));
859 for(
size_t i = 0; i < queries_count; ++i)
861 for(
size_t j = 0; j < k; ++j)
863 const size_t h = i * k + j;
871 result[i][j].i = result_i[h];
872 result[i][j].match_result.distance = result_distance[h];
873 result[i][j].match_result.fa_r = result_far[h];
874 result[i][j].match_result.fr_r = result_frr[h];
875 result[i][j].match_result.score = result_score[h];
888 const double distance_threshold)
const
892 void* exception = NULL;
894 _dll_handle->Recognizer_getROCCurvePointByDistanceThreshold_v2(
903 checkException(exception, *_dll_handle);
910 const double desired_far)
const
914 void* exception = NULL;
916 _dll_handle->Recognizer_getROCCurvePointByFAR_v2(
925 checkException(exception, *_dll_handle);
932 const double desired_frr)
const
936 void* exception = NULL;
938 _dll_handle->Recognizer_getROCCurvePointByFRR_v2(
947 checkException(exception, *_dll_handle);
955 const double score_threshold)
const
959 void* exception = NULL;
961 _dll_handle->Recognizer_getROCCurvePointByScoreThreshold(
970 checkException(exception, *_dll_handle);
977 const size_t set_size,
978 const std::vector<pbio::Template::Ptr> &templates,
979 const std::vector<size_t> &inviolable_templates_indexes)
981 std::vector<pbio::facerec::TemplateImpl const*> template_impls(templates.size());
983 for(
size_t i = 0; i < templates.size(); ++i)
984 template_impls[i] = (pbio::facerec::TemplateImpl
const*) templates[i]->_impl;
986 std::vector<int8_t> inv_flags_8(templates.size(), 0);
988 for(
size_t i = 0; i < inviolable_templates_indexes.size(); ++i)
990 const size_t j = inviolable_templates_indexes[i];
992 if(j >= templates.size())
995 "Error: bad index in chooseRepresentativeTemplatesSet, error code: 0x63156958");
1000 std::vector<int32_t> result(set_size);
1002 void* exception = NULL;
1004 _dll_handle->Recognizer_chooseRepresentativeTemplatesSet(
1006 template_impls.empty() ? NULL : template_impls.data(),
1007 inv_flags_8.empty() ? NULL : inv_flags_8.data(),
1009 result.empty() ? NULL : result.data(),
1013 checkException(exception, *_dll_handle);
1015 return std::vector<size_t>(result.begin(), result.end());
1022 #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:954
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:662
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:732
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:35
std::string getMethodName() const
Get a method name. Thread-safe.
Definition: Recognizer.h:625
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:44
Template::Ptr processing(const RawSample &sample) const
Create a template.
Definition: Recognizer.h:645
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:976
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:763
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:931
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:708
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:887
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:909
double fr_r
False rejection rate corresponding to the distance value taken as a threshold at the extended LFW tes...
Definition: Recognizer.h:82