媒资管理服务支持对入库媒资进行人脸搜索功能,您可以根据实际需求对指定人物定位搜索或过滤敏感人物。通过阅读本文,您可以了解调用OpenAPI进行人脸搜索的流程。
前提条件
您已经安装IMS服务端SDK。具体操作,请参见安装SDK。
操作步骤
设置智能内容分析配置。
调用接口CreateSearchIndex,设置媒资注册完成后自动发起智能内容分析,同时设置入库类型为人脸。
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);
注册内容库资源。
调用接口RegisterMediaInfo,将待搜索的素材入库,支持对图片和视频进行人脸搜索。
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);
获取媒资内容信息。
调用接口GetMediaInfo,确认视频素材入库成功。
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);
如果返回的
AiRoughData.Status
值为SaveSuccess
,表示入库成功。根据人脸图片搜索入库媒资(粗搜)。
调用接口SearchMediaByFace,同时设置人脸图片URL,搜索人脸所在媒资的相关信息。
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);
返回示例:
{ "RequestId": "F0FBE61A-66FF-55C0-8900-EE816FA20B8D", "MediaInfoList": [ { "MediaId": "92796460cd4571ed91c6e7e7c45b****" }, { "MediaId": "b5a003f0cd3f71ed919fe7e7c45b****" } ], "Total": 2, "Code": "200", "Success": true }
根据人脸图片搜索入库媒资片段(精搜)。
调用接口SearchMediaClipByFace,同时输入步骤 4中返回的
MediaId
,搜索人脸所在该媒资的片段信息。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参考
联系我们
更多产品咨询问题或使用支持,欢迎通过钉钉搜索群号48335001108,加入智能媒体服务产品群联系我们。