首页 > 其他分享 >基于百度图像识别SDK开发动植物识别

基于百度图像识别SDK开发动植物识别

时间:2022-10-28 14:23:34浏览次数:80  
标签:AipImageClassify 图像识别 String client static KEY public 百度 SDK

1.登录百度智能云官网(没有要先注册账号)

2.在官网下载java sdk压缩工具包

3.将下载的aip-java-sdk-version.zip解压。

 

 4.在idea新建工程,并添加lib文件夹,把jar包导入。

 

5.申请免费图像识别借口,获得app_id,api_key,secret_key;

动物识别源码如下:

package Sample;
import java.util.*;
import org.json.JSONObject;
import com.baidu.aip.imageclassify.AipImageClassify;
public class Sample {

    public static final String APP_ID = "28103509";
    public static final String API_KEY = "XvzIGyHYhHQ2iaT0aVF6YlOp";
    public static final String SECRET_KEY = "0jpvYidH5lDHauM0fs9e91lI3GrrM2dR";
    public static void main(String[] args) {

        AipImageClassify client = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY);
        Sample.sample_plant(client);
    }
    public static void sample_plant(AipImageClassify client)
    {
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("baike_num", "5");
        options.put("top_num", "3");
        String image = "img/cat2.png";
        JSONObject res = client.advancedGeneral(image, options);
        System.out.println(res.toString(2));
    }
}

 植物识别源码如下:

package Sample;
import com.baidu.aip.imageclassify.AipImageClassify;
import org.json.JSONObject;
import java.util.HashMap;
public class Sample2{
    //设置APPID/AK/SK
    public static final String APP_ID = "28109906";
    public static final String API_KEY = "FnGCRjFUsK0Nr1n9iHbOrz2t";
    public static final String SECRET_KEY="iM1Lo13eNlDxXb75nNoRgOhOdKcGuv1Y";
    public static void main(String[] args) {
        // 初始化一个AipImageClassify
        AipImageClassify client = new AipImageClassify(APP_ID, API_KEY, SECRET_KEY);
        // 可选:设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("baike_num", "5");
        String image = "img/a.jpg";
        JSONObject res = client.plantDetect(image, options);
        System.out.println(res.toString(2));
    }
}

  

 

标签:AipImageClassify,图像识别,String,client,static,KEY,public,百度,SDK
From: https://www.cnblogs.com/lyf3701/p/16835915.html

相关文章