提交视频人像抠图任务

最近更新时间:2024-07-23 18:12:12

我的收藏

简介

本文档提供关于视频人像分割的相关 API 概览以及 SDK 示例代码。
API
操作描述
提交一个视频人像抠图任务

SDK API 参考

SDK 所有接口的具体参数与方法说明,请参考 SDK API

提交任务

功能说明

提交一个视频人像抠图任务。
注意:
COS Android SDK 版本需要大于等于 v5.9.32。

示例代码

// 存储桶名称,格式为 BucketName-APPID
String bucket = "examplebucket-1250000000";
PostSegmentVideoBodyRequest request = new PostSegmentVideoBodyRequest(bucket);
PostSegmentVideoBody postSegmentVideoBody = new PostSegmentVideoBody();// 提交任务请求体
request.setPostSegmentVideoBody(postSegmentVideoBody);// 设置请求
PostSegmentVideoBody.PostSegmentVideoBodyInput postSegmentVideoBodyInput = new PostSegmentVideoBody.PostSegmentVideoBodyInput();
postSegmentVideoBody.input = postSegmentVideoBodyInput;
// 设置文件路径;是否必传:是
postSegmentVideoBodyInput.object = "input/test.mp4";
PostSegmentVideoBody.PostSegmentVideoBodyOperation postSegmentVideoBodyOperation = new PostSegmentVideoBody.PostSegmentVideoBodyOperation();
postSegmentVideoBody.operation = postSegmentVideoBodyOperation;
PostSegmentVideoBody.PostSegmentVideoBodySegmentVideoBody postSegmentVideoBodySegmentVideoBody = new PostSegmentVideoBody.PostSegmentVideoBodySegmentVideoBody();
postSegmentVideoBodyOperation.segmentVideoBody = postSegmentVideoBodySegmentVideoBody;
// 设置抠图模式 Mask:输出alpha通道结果Foreground:输出前景视频Combination:输出抠图后的前景与自定义背景合成后的视频默认值:Mask;是否必传:否
postSegmentVideoBodySegmentVideoBody.mode = "Mask";
// 设置抠图类型HumanSeg:人像抠图GreenScreenSeg:绿幕抠图SolidColorSeg:纯色背景抠图默认值:HumanSeg;是否必传:否
postSegmentVideoBodySegmentVideoBody.segmentType = "HumanSeg";
// 设置mode为 Foreground 时参数生效,背景颜色为红色,取值范围 [0, 255], 默认值为 0;是否必传:否
postSegmentVideoBodySegmentVideoBody.backgroundRed = "0";
// 设置mode为 Foreground 时参数生效,背景颜色为绿色,取值范围 [0, 255],默认值为 0;是否必传:否
postSegmentVideoBodySegmentVideoBody.backgroundGreen = "0";
// 设置mode为 Foreground 时参数生效,背景颜色为蓝色,取值范围 [0, 255],默认值为 0;是否必传:否
postSegmentVideoBodySegmentVideoBody.backgroundBlue = "0";
// 设置调整抠图的边缘位置,取值范围为[0, 255],默认值为 0;是否必传:否
postSegmentVideoBodySegmentVideoBody.binaryThreshold = "0";
// 设置纯色背景抠图的背景色(红), 当 SegmentType 为 SolidColorSeg 生效,取值范围为 [0, 255],默认值为 0;是否必传:否
postSegmentVideoBodySegmentVideoBody.removeRed = "0";
// 设置纯色背景抠图的背景色(绿), 当 SegmentType 为 SolidColorSeg 生效,取值范围为 [0, 255],默认值为 0;是否必传:否
postSegmentVideoBodySegmentVideoBody.removeGreen = "0";
// 设置纯色背景抠图的背景色(蓝), 当 SegmentType 为 SolidColorSeg 生效,取���范围为 [0, 255],默认值为 0;是否必传:否
postSegmentVideoBodySegmentVideoBody.removeBlue = "0";
PostSegmentVideoBody.PostSegmentVideoBodyOutput postSegmentVideoBodyOutput = new PostSegmentVideoBody.PostSegmentVideoBodyOutput();
postSegmentVideoBodyOperation.output = postSegmentVideoBodyOutput;
// 设置存储桶的地域;是否必传:是
postSegmentVideoBodyOutput.region = "ap-chongqing";
// 设置存储结果的存储桶;是否必传:是
postSegmentVideoBodyOutput.bucket = "test-123456789";
// 设置结果文件名;是否必传:是
postSegmentVideoBodyOutput.object = "output/out.mp4";
// 设置透传用户信息,可打印的 ASCII 码,长度不超过1024;是否必传:否
postSegmentVideoBodyOperation.userData = "This is my data.";
// 设置任务优先级,级别限制:0 、1 、2。级别越大任务优先级越高,默认为0;是否必传:否
postSegmentVideoBodyOperation.jobLevel = "0";
// 设置任务回调格式,JSON 或 XML,默认 XML,优先级高于队列的回调格式;是否必传:否
postSegmentVideoBody.callBackFormat = "JSON";
// 设置任务回调类型,Url 或 TDMQ,默认 Url,优先级高于队列的回调类型;是否必传:否
postSegmentVideoBody.callBackType = "Url";
// 设置任务回调地址,优先级高于队列的回调地址。设置为 no 时,表示队列的回调地址不产生回调;是否必传:否
postSegmentVideoBody.callBack = "http://callback.demo.com";

ciService.postSegmentVideoBodyAsync(request, new CosXmlResultListener() {
@Override
public void onSuccess(CosXmlRequest request, CosXmlResult cosResult) {
// result 提交任务的结果
// 详细字段请查看api文档或者SDK源码
PostSegmentVideoBodyResult result = (PostSegmentVideoBodyResult) cosResult;

}
@Override
public void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {
if (clientException != null) {
clientException.printStackTrace();
} else {
serviceException.printStackTrace();
}
}
});

说明:
更多完整示例,请前往 GitHub 查看。