How to perform a face search on many media assets
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
-
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); -
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); -
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.Statusin the response isSaveSuccess, the media asset was successfully added to the content library. -
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 } -
Search for media asset clips in the content library by face image (fine-grained search).
Call the SearchMediaClipByFace operation with the
MediaIdreturned 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.