How to perform a face search on many media assets

Updated at:
Copy as MD

Intelligent Media Services (IMS) supports face searches on media assets in a content library, allowing you to locate specific individuals or filter out sensitive ones by calling OpenAPI operations.

Prerequisites

The Intelligent Media Services (IMS) server-side software development kit (SDK) is installed. For more information, see Install the SDK.

Procedure

  1. Set the intelligent content analysis configuration.

    Call the CreateSearchIndex operation to enable automatic intelligent content analysis upon media asset registration and set the index type to face.

    com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret"); 
    com.aliyun.ice20201109.models.CreateSearchIndexRequest createSearchIndexRequest = new com.aliyun.ice20201109.models.CreateSearchIndexRequest() 
           .setIndexType("face"); 
    com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions(); 
    client.createSearchIndexWithOptions(createSearchIndexRequest, runtime);
  2. Register a content library resource.

    Call the RegisterMediaInfo operation to add a media asset to the content library. Face search is supported for images and videos.

    com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
    com.aliyun.ice20201109.models.RegisterMediaInfoRequest registerMediaInfoRequest = new com.aliyun.ice20201109.models.RegisterMediaInfoRequest()
            .setMediaType("video")
            .setTitle("face-test12")
            .setInputURL("oss://example-bucket/example.mp4");
    com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
    client.registerMediaInfoWithOptions(registerMediaInfoRequest, runtime);
  3. Retrieve media asset information.

    Call the GetMediaInfo operation to confirm that the media asset was successfully added to the content library.

    com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
    com.aliyun.ice20201109.models.GetMediaInfoRequest getMediaInfoRequest = new com.aliyun.ice20201109.models.GetMediaInfoRequest()
            .setInputURL("oss://example-bucket/example.mp4");
    com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
    client.getMediaInfoWithOptions(getMediaInfoRequest, runtime);

    If the value of AiRoughData.Status in the response is SaveSuccess, the media asset was successfully added to the content library.

  4. Search for media assets in the content library by face image (rough search).

    Call the SearchMediaByFace operation with a face image URL to find media assets that contain the matching face.

    com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
    com.aliyun.ice20201109.models.SearchMediaByFaceRequest searchMediaByFaceRequest = new com.aliyun.ice20201109.models.SearchMediaByFaceRequest()
            .setFaceSearchToken("test001")
            .setPersonImageUrl("https://****.oss-cn-shanghai.aliyuncs.com/test/testFacePic.png");
    com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
    client.searchMediaByFaceWithOptions(searchMediaByFaceRequest, runtime);

    Sample response:

    {
      "RequestId": "F0FBE61A-66FF-55C0-8900-EE816FA20B8D",
      "MediaInfoList": [
        {
          "MediaId": "92796460cd4571ed91c6e7e7c45b****"
        },
        {
          "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****"
        }
      ],
      "Total": 2,
      "Code": "200",
      "Success": true
    }
  5. Search for media asset clips in the content library by face image (fine-grained search).

    Call the SearchMediaClipByFace operation with the MediaId returned in Step 4 to retrieve specific clips containing the matched face.

    com.aliyun.ice20201109.Client client = Sample.createClient("accessKeyId", "accessKeySecret");
    com.aliyun.ice20201109.models.SearchMediaClipByFaceRequest searchMediaClipByFaceRequest = new com.aliyun.ice20201109.models.SearchMediaClipByFaceRequest()
            .setFaceSearchToken("test001")
            .setMediaId("92796460cd4571ed91c6e7e7c45b****");
    com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
    client.searchMediaClipByFaceWithOptions(searchMediaClipByFaceRequest, runtime);

API reference

Contact us

If you have questions or want to obtain technical support, join the DingTalk group for IMS (ID: 84650000851) to contact us.