Face search¶
Face search is the process in which a probe template is searched against the reference templates of more than one subject. It returns a candidate list.
The FaceMatcher module provides a search method that performs a one-to-many search of a biometric probe against a previously initialized dictionary of biometric references. This method is generally used when the database size is relatively small (up to 1000 templates).
For large databases (over 1000 templates), the FaceIndexer module offers a more efficient way of performing a one-to-many search. From an index file created from a list of face templates, it uses modern indexing techniques for fast, lossless searching.
Constructing a face index¶
The example below demonstrates how to construct a face index:
# Maximum user number to size the indexer
count = 100
# create indexer
indexer = FaceIndexer.create(count, FaceTemplateFormat.V9A)
for user_index in range(10):
# load or create a FaceTemplate for the user
record = FaceTemplate.from_file(
"data/{}.bin".format(user_index)
)
# Add record to indexer with a chosen user identifier
indexer.add_template(record, "user_{}".format(user_index))
# save the index to a file
indexer.to_file("data/face_index.db")
Searching in the index¶
The example below demonstrates how to search for a face using the index:
# load database
indexer = FaceIndexer.from_file("data/face_index.db")
# load or create a FaceTemplate for the user
probe = FaceTemplate.from_file(
"data/user5.bin"
)
# Search user in indexer
candidate_list = indexer.search_template(probe, 1)
if candidate_list:
print("Found match with : " + candidate_list[0].id)