阿里云智能视觉生产图像处理人像分割Java SDK使用说明

下载安装

 <dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-ivpd</artifactId>
    <version>1.0.2</version>
</dependency>
<dependency>
    <groupId>com.aliyun</groupId>
    <artifactId>aliyun-java-sdk-core</artifactId>
    <version>4.4.9</version>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.60</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.3</version>
</dependency>

代码示例

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.aliyuncs.*;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.ivpd.model.v20190625.*;
import com.aliyuncs.profile.DefaultProfile;
import org.apache.http.util.Asserts;
import java.util.*;

public class ZhiNengShiJueShengChan {
    static IAcsClient client = null;
    static String regionId = "cn-beijing";
    public static void main(String[] args) throws Exception {
        DefaultProfile profile = DefaultProfile.getProfile(regionId, "accessKeyId", "accessKey secret");
        profile.getHttpClientConfig().setMaxRequests(100);
        profile.getHttpClientConfig().setMaxRequestsPerHost(50);
        client = new DefaultAcsClient(profile);
        testSegmentBody();//人像分割
    }
    public static SegmentBodyResponse testSegmentBody() throws Exception {
        SegmentBodyRequest req = new SegmentBodyRequest();
        System.out.print("--------  人像分割 -----");
        req.setImageUrl(formatDemoUrl("SegmentBody/mayun.jpeg"));
        SegmentBodyResponse resp = getAcsResponse(req);
        printResponse(req.getSysActionName(), resp.getRequestId(), resp.getCode(), resp.getMessage(), resp.getData());
        return resp;
    }
public static void printResponse(String action, String requestId, String code, String message, Object data) {
        System.out.print("  " + action + " ======================================\n");
        System.out.println("requestId:  " + requestId);
        System.out.println("code:  " + code);
        System.out.println(" msg:  " + message);
        System.out.println("body.class:  " + data == null ? null : data.getClass());
        System.out.println("body:  " + JSON.toJSONString(data, SerializerFeature.PrettyFormat));
        Asserts.check("0".equals(code), "assert code == 0 req:");
        Asserts.check(null != data, "assert data != null");
        System.out.println("\n");
    }
    private static <R extends RpcAcsRequest<T>, T extends AcsResponse> T getAcsResponse(R req) throws Exception {
        req.setSysProtocol(ProtocolType.HTTPS);
        return client.getAcsResponse(req);
    }
    private static String formatDemoUrl(String file) {
        return String.format("http://ivpd-%s.oss-%s.aliyuncs.com/ivpd-demo/images/%s", regionId, regionId, file);
    }
}

参考链接

SegmentBody人像分割

上一篇:kubeadm添加主从节点


下一篇:设计模式6大原则