Baidu AI vehicle image recognition JavaSDK is so easy to use?

Baidu AI vehicle image recognition SDK is easy to use

1. First I enter the official Baidu AI open platform: http://ai.baidu.com/?track=cp:aipinzhuan|pf:pc|pp:AIpingtai|pu:title|ci:|kw:10005792

2. Find the vehicle type recognition
Insert picture description here
3. Click on the technical document

Insert picture description here
4. Java SDK document
Insert picture description here
5. Create a maven project in idea and import dependencies

<dependency>
    <groupId>com.baidu.aip</groupId>
    <artifactId>java-sdk</artifactId>
    <version>4.15.3</version>
</dependency>

6. Create a test class

import org.json.JSONObject;
import org.junit.Test;

import com.baidu.aip.imageclassify.AipImageClassify;

import java.util.HashMap;

public class PhotoAITest {
    
    

    //设置APPID/AK/SK
    public static final String APP_ID = "XXX";
    public static final String API_KEY = "XXX";
    public static final String SECRET_KEY = "XXX";

    @Test
    public void sample() {
    
    
        // 初始化一个AipImageClassifyClient
        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("top_num", "3");
        options.put("baike_num", "5");

        // 参数为本地路径
        String image = "C:\\Users\\LENOVO\\Desktop\\汽车img\\奥迪.png";
        JSONObject res = client.carDetect(image, options);
        System.out.println(res.toString(2));

        // 参数为二进制数组
//        byte[] file = readFile("test.jpg");
//        res = client.carDetect(file, options);
//        System.out.println(res.toString(2));
    }

}

7. Get APP_ID, API_KEY, SCRET_KEY (register the account if you don’t have a Baidu account).
Insert picture description here
Insert picture description here
Fill in the application name at will, select individual below
Insert picture description here
Insert picture description here
8. Run the test case

{
    
    
  "result": [
    {
    
    
      "score": 0.9914040565490723,
      "year": "无年份信息",
      "name": "奥迪_Q3",
      "baike_info": {
    
    }
    },
    {
    
    
      "score": 5.118460976518691E-4,
      "year": "无年份信息",
      "name": "奥迪_Q5",
      "baike_info": {
    
    }
    },
    {
    
    
      "score": 4.889683914370835E-4,
      "year": "无年份信息",
      "name": "奥迪_Q7",
      "baike_info": {
    
    }
    }
  ],
  "color_result": "白色",
  "log_id": 1362230471873789952,
  "location_result": {
    
    
    "top": 9,
    "left": 16,
    "width": 331,
    "height": 220
  }
}

9. The free version of this API can only be called 500 times a day
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_41237676/article/details/113842997