阿里云智能视觉生产图像分析色板分析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);
        testRecognizeImageColor();//色板识别
    }
    public static void testRecognizeImageColor() throws Exception {
        RecognizeImageColorRequest req = new RecognizeImageColorRequest();
        System.out.print("--------  色板识别 ----");
        req.setUrl(formatDemoUrl("RecognizeImageColor/RecognizeImageColor.png"));
        RecognizeImageColorResponse resp = getAcsResponse(req);
        printResponse(req.getSysActionName(), resp.getRequestId(), resp.getCode(), resp.getMessage(), resp.getData());
    }
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);
    }
}

参考链接

RecognizeImageColor色板分析

上一篇:CentOS 第三方源实现yum安装(找了好久才找到的)


下一篇:“冬季实战营第一期”之从零到一上手玩转云服务器——学习报告