package blog.open1111.crawler;
import java.util.HashMap;
import org.json.JSONObject;
import com.baidu.aip.ocr.AipOcr;
public class Sample {
//设置APPID/AK/SK
public static final String APP_ID = "";//"你的 App ID";
public static final String API_KEY = "";//"你的 Api Key";
public static final String SECRET_KEY = "";//"你的 Secret Key";
public void generalRecognition(AipOcr client) {
// // 参数为本地图片路径
// String imagePath = "general.jpg";
// JSONObject response1 = client.basicGeneral(imagePath, new HashMap<String, String>());
// System.out.println(response1.toString());
//
// // 参数为本地图片文件二进制数组
// byte[] file = readImageFile(imagePath);
// JSONObject response2 = client.basicGeneral(file, new HashMap<String, String>());
// System.out.println(response2.toString());
//
// // 参数为图片url
// String url = "http://some.com/a.jpg";
// JSONObject response3 = client.basicGeneralUrl(url, new HashMap<String, String>());
// System.out.println(response3.toString());
}
public void webImageOCR(AipOcr client) {
// 参数为本地图片路径
// String imagePath = "webimage.jpg";
// JSONObject response = client.webImage(imagePath);
// System.out.println(response.toString());
//
// // 参数为本地图片文件二进制数组
// byte[] file = readImageFile(imagePath);
// JSONObject response = client.webImage(file);
// System.out.println(response.toString());
}
public static void main(String[] args) {
// 初始化一个OcrClient
AipOcr client = new AipOcr(APP_ID, API_KEY, SECRET_KEY);
// 可选:设置网络连接参数
client.setConnectionTimeoutInMillis(2000);
client.setSocketTimeoutInMillis(60000);
// 调用身份证识别接口
// String idFilePath = "test.jpg";
// JSONObject idcardRes = client.idcard(idFilePath, true);
// System.out.println(idcardRes.toString(2));
//
// // 调用银行卡识别接口
// String bankFilePath = "test_bank.jpg";
// JSONObject bankRes = client.bankcard(bankFilePath);
// System.out.println(bankRes.toString(2));
// 调用通用识别接口
String genFilePath = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509077954725&di=2f37a190f51486deef50c193cfcde232&imgtype=0&src=http%3A%2F%2Fwww.cngr.cn%2Fup%2F2015-4%2F201543172418.jpg";
genFilePath = "F:/zbf/weixin.png";
//genFilePath = "https://www.baidu.com/img/bd_logo1.png";
//genFilePath = "F:/zbf/20171027-2.bmp";
//genFilePath = "http://www.kuaicha.info/showImg.action?picPath=4adcf163a4cdf707d3086313c94fb3055d504f798cfb7d39c868193cf55ef787be15c528fdb92d4ebbfe80ba3f6344a96235c3c8130c28b1f48b778117715847&thumbnailFalg=false";
JSONObject genRes = client.basicGeneral(genFilePath, new HashMap<String, String>());
System.out.println(genRes.toString(2));
// 调用通用识别(含位置信息)接口
// String genFilePath = "test_general.jpg";
// JSONObject genRes2 = client.general(genFilePath, new HashMap<String, String>());
// System.out.println(genRes2.toString(2));
// }
// 参数为图片url
// String url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509085123327&di=154e6805ba22967639c8718bbf9806a6&imgtype=0&src=http%3A%2F%2Fimg.xgo-img.com.cn%2Fpics%2F2373%2F630%2F572%2F2372094.jpg";
// //url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509077954725&di=2f37a190f51486deef50c193cfcde232&imgtype=0&src=http%3A%2F%2Fwww.cngr.cn%2Fup%2F2015-4%2F201543172418.jpg";
// //url = "http://www.kuaicha.info/showImg.action?picPath=4adcf163a4cdf707d3086313c94fb3055d504f798cfb7d39c868193cf55ef787be15c528fdb92d4ebbfe80ba3f6344a96235c3c8130c28b1f48b778117715847&thumbnailFalg=false";
// JSONObject response3 = client.basicGeneralUrl(url, new HashMap<String, String>());
// System.out.println(response3.toString());
}
}