基于百度图像识别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));
    }
}

  

 

posted @ 2022-10-28 14:16  Lindseyyip  阅读(162)  评论(0编辑  收藏  举报