阿里视觉训练营Day5——垃圾分类

开通服务

首先在视觉智能开放平台https://vision.aliyun.com/开通垃圾分类服务

功能描述

可以对图片中的物品垃圾进行分类,并给出具体的物品名称。

示例代码

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.imagerecog.model.v20190930.*;

public class ClassifyingRubbish {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-shanghai", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        ClassifyingRubbishRequest request = new ClassifyingRubbishRequest();
        request.setRegionId("cn-shanghai");
        request.setImageURL("http://viapi-test.oss-cn-shanghai.aliyuncs.com/demo-center/imagerecog/ClassifyingRubbish2.jpg");

        try {
            ClassifyingRubbishResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }

    }
}

请求实例

http(s)://imagerecog.cn-shanghai.aliyuncs.com/?Action=ClassifyingRubbish
&ImageURL=https://viapi-test.oss-cn-shanghai.aliyuncs.com/test-team/rubbish.jpg
&<公共请求参数>

正常返回实例

<RequestId>UUID</RequestId>
<Data>
    <Sensitive>false</Sensitive>
    <Elements>
        <Category>可回收垃圾</Category>
        <CategoryScore>0.68</CategoryScore>
        <Rubbish>U盘</Rubbish>
        <RubbishScore>0.68</RubbishScore>
    </Elements>
</Data>

json格式

{
    "RequestId": "UUID",
    "Data": {
      "Sensitive": false,
      "Elements": [
        {
          "Category": "可回收垃圾",
          "CategoryScore": 0.68,
          "Rubbish": "U盘",
          "RubbishScore": 0.68
        }
      ]
    }
}
上一篇:Python数据分析与展示:Series类型简单操作-8


下一篇:Linux网桥端口的arp问题