Face search
After you create a dataset and index images into it, you can use face search to find the N images in the dataset that are most similar to a specified image. This feature is useful for applications such as VIP customer identification.
Use cases
Intelligent security monitoring
Using facial recognition, you can monitor crowded places such as factories, schools, shopping malls, and restaurants. This allows you to automatically count, identify, and track people, flag potentially unsafe behaviors and areas, and issue alerts. This improves security management and reduces costs for manual supervision.
Factory production safety
This feature provides an integrated software and hardware solution for production safety monitoring. Using images captured by cameras in plants and workshops, the system can identify unauthorized individuals to reduce security risks.
Face-based gate access
Integrating facial recognition into turnstiles allows you to quickly enroll faces and build a secure face library. Users gain entry by scanning their faces, which helps prevent issues like forgotten or spoofed badges. This enables access control for enterprise, commercial, and residential scenarios.
Smart face attendance
This feature offers three types of attendance solutions: mobile attendance, camera-based contactless attendance, and all-in-one device attendance. The system finds a user's most similar face in under one second, ensuring accurate check-ins, preventing fraudulent activities like buddy punching, and enhancing corporate security management.
Prerequisites
-
You have indexed the images to be compared into a dataset. You can index images by binding a bucket (Create a binding task) or by actively indexing file metadata (IndexFileMeta or BatchIndexFileMeta).
-
The dataset must contain at least two high-definition face images of the same person that meet the following requirements:
-
The face size is greater than 75 × 75 pixels.
-
The absolute values of the three HeadPose components must all be less than 30°.
-
FaceQuality is greater than 0.8.
-
-
You have created an SMQ queue. For more information, see Manage queues.
NoteThis topic provides an example of using the Python SDK for Simple Message Queue (SMQ), formerly Message Service (MNS), to receive task notifications. For other ways to get task information, see Process asynchronous tasks.
Step 1: Upload a file
Use the Object Storage Service (OSS) console to upload the photos that you want to compare to the bound bucket.
On the upload page, click Scan Files and select the photos to upload.
Step 2: Add photos to dataset
-
Use the Intelligent Media Management (IMM) console to add photos from your OSS bucket to a dataset to build a face library. The procedure is as follows:
On the dataset details page, navigate to the Data Ingestion > Batch Add tab and click Add Files to Dataset. In the dialog box that appears, configure the Notification settings as needed. To add files, click Select Files, or enter a full path in the input box and click Add to List. Review the Object Path, Custom Tags, and Actions for each file, and then click OK.
The selected files are displayed in the file list with their oss:// paths.
-
You can also call the BatchIndexFileMeta operation to index information from face photos into the dataset in batches. This process runs as an asynchronous task. You can obtain task information by configuring the Notification parameter.
Step 3: Create face search task
You can call the CreateFacesSearchingTask operation to find the top N photos that are most similar to the largest face in a specified image. The following example shows how to search the test-dataset dataset for photos similar to the image at oss://test-bucket/test-object.jpg.
Sample request
-
The TopicName parameter specifies the name of the SMQ topic. This example uses tf-test-mns-topic.
-
The MaxResult parameter specifies the number of similar images to return. This parameter is optional. The default value is 5. Valid values: 0 to 100.
{
"ProjectName": "test-project",
"DatasetName": "test-dataset",
"Sources": [{"URI": "oss://test-bucket/test-object.jpg"}],
"Notification": {"MNS": {"TopicName": "tf-test-mns-topic"}},
"MaxResult": 100
}
Sample response
{
"TaskId": "CreateFacesSearchingTask-dedf1bd9-7edc-4d16-97f2-bbb2a4fc****",
"RequestId": "BB9C38A3-BB7A-53B7-A168-6DBC1CF6****",
"EventId": "0DA-1TAZO4ClNnKbn4Ungls8SOk****"
}
This response confirms that the face search task was created.
Sample code
Step 4: View face search results
After the face search task is successfully created, you can retrieve the task information from the SMQ service. The following example shows how to get task information by using the Python SDK. For more information, see Step 4: Receive and delete messages.
-
In the sample directory, run the following command.
python recvdelmessage.py tf-test-mns-queue -
The console returns the result in JSON format. The following code shows the formatted content of the Message field.
{ "ProjectName": "test-project", "DatasetName": "test-dataset", "RequestId": "BB9C38A3-BB7A-53B7-A168-6DBC1CF6****", "StartTime": "2023-01-04T05:08:28.582Z", "EndTime": "2023-01-04T05:08:28.785Z", "UserData": "", "TaskType": "FacesSearching", "TaskId": "CreateFacesSearchingTask-dedf1bd9-7edc-4d16-97f2-bbb2a4fc****", "Status": "Succeeded", "Code": "", // An empty Code field indicates that the operation was successful. "Message": "Success", "SimilarFaces": [ { "URI": "oss://test-bucket/test-object.jpg", "Boundary": { "Width": 109, "Height": 150, "Left": 69, "Top": 49 }, // A list of similar faces. "SimilarFaces": [ { "URI": "oss://test-bucket/test-object-1.jpg", "FigureId": "4cacbb71-52fd-4d3f-9d14-0840fecee0bf", "Similarity": 0.73321015 }, { "URI": "oss://test-bucket/test-object-2.jpg", "FigureId": "7a4cd08d-bcd0-4bc4-93f4-1291075819cf", "Similarity": 0.77035695 }, { "URI": "oss://test-bucket/test-object-3.jpg", "FigureId": "da920124-410a-4493-9fd3-1a3b366dca86", "Similarity": 0.9836307 } ] } ] }NoteThe message shows that the following three images in the
test-datasetdataset are similar to the face in the query image:-
Image 1: oss://test-bucket/test-object-1.jpg, with a similarity score of 0.73321015.
-
Image 2: oss://test-bucket/test-object-2.jpg, with a similarity score of 0.77035695.
-
Image 3: oss://test-bucket/test-object-3.jpg, with a similarity score of 0.9836307.
-