百度AI图片识别亲测成功详解
百度AI圖片識別親測成功詳解
1、瀏覽器輸入網址http://ai.baidu.com/或者百度一下搜索‘百度ai’點擊第一個。
2、點擊控制臺,有百度賬號的直接登錄,沒有的注冊后登錄。
3、點擊左側菜單“文字識別”—>點擊“應用列表”—>點擊“創建應用”—>填寫相關信息后—>點“立即創建”—>獲取“AppID、API Key、Secret Key”。
4、SDK下載,下載解壓后將相應jar包添加到項目中;
5、點擊“使用說明”查看幫助文檔https://ai.baidu.com/ai-doc/OCR/1k3h7y3db
6、直接上代碼,將如下代碼直接復制到項目中運行看效果(注意需將第三點中獲取的“AppID、API Key、Secret Key”填入代碼中),根據項目實際情況結合幫助文檔再進行調整即可。
?
import java.util.HashMap;
import org.json.JSONObject;
import org.springframework.stereotype.Component;
import com.baidu.aip.ocr.AipOcr;
@Component
public class Sample{
? ?// 設置APPID/AK/SK
? ?public static final String APP_ID = "第三點中獲取的AppID";
? ?public static final String API_KEY = "第三點中獲取的API Key";
? ?public static final String SECRET_KEY = "第三點中獲取的Secret Key";
? ?public static void main(String[] arg){
? ? ? ?JSONObject res = sample();
? ? ? ?System.out.println(res.toString(2));
? ?}
? ?// 初始化用戶對象
? ?public static AipOcr init() {
? ? ? ?// 初始化一個AipOcr
? ? ? ?AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
? ? ? ?// 可選:設置網絡連接參數
? ? ? ?client.setConnectionTimeoutInMillis(2000);
? ? ? ?client.setSocketTimeoutInMillis(60000);
? ? ? ?return client;
? ?}
? ?public static JSONObject sample() {
? ? ? ?// 傳入可選參數調用接口
? ? ? ?HashMap<String, String> options = new HashMap<String, String>();
? ? ? ?options.put("language_type", "CHN_ENG");
? ? ? ?options.put("detect_direction", "true");
? ? ? ?options.put("detect_language", "true");
? ? ? ?options.put("probability", "true");
? ? ? ?//初始化用戶對象
? ? ? ?AipOcr client = init();
? ? ? ?// 參數為本地圖片路徑
? ? ? ?String path = "F:\\揣搜網.png";
? ? ? ?JSONObject res = client.basicGeneral(path, options);
? ? ? ?// 參數為本地圖片二進制數組
? ? ? ?//String image = "F:\\揣搜網.png";
? ? ? ?//File file = new File(image);
? ? ? ?//byte[] fileByte = new byte[0];
? ? ? ?//try {
? ? ? ?// ? ?fileByte = Files.readAllBytes(file.toPath());
? ? ? ?//} catch (IOException e) {
? ? ? ?// ? ?e.printStackTrace();
? ? ? ?//}
? ? ? ?//JSONObject res = client.basicGeneral(fileByte, options);
? ? ? ?// 通用文字識別, 圖片參數為遠程url圖片
? ? ? ?//String url = "https://timgsa.baidu.com/timg?" +
// ? ? ? ?"image&quality=80&size=b9999_10000&sec=1600324362220&di=ffc9820b80235fcfa42c3c91b696ead4" +
// ? ? ? ?"&imgtype=0&src=http%3A%2F%2Fcdn.duitang.com%" +
// ? ? ? ?"2Fuploads%2Fitem%2F201512%2F29%2F20151229183756_SxVkw.jpeg";
? ? ? ?//JSONObject res = client.basicGeneralUrl(url, options);
? ? ? ?return res;
? ?}
}
?
7、識別效果。(注意免費是有次數限制的具體情況請查看“購買指南”)
?
轉載至:http://www.chuaisou.com/index.html#/app/itw?rt=1&pn=I160031022Q521738
?
總結
以上是生活随笔為你收集整理的百度AI图片识别亲测成功详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IOS唤起H5微信或支付宝收银台
- 下一篇: 关于英语作文AI批改的思考(含定向高分方