百度云文字识别 (AIPOcr)
接下来写点关于百度云 文字识别的 笔记吧.
在这里我根据返回参数 写了几个对应的实体类来接收,
写的一个java类继承文档提供的关于文字识别操作类
public class AIPOcrJava extends AipOcr {//设置APPID/AK/SK public static final String APP_ID = "*********"; public static final String API_KEY = "*******************"; public static final String SECRET_KEY = "************************"; public AIPOcrJava(){super(APP_ID, API_KEY, SECRET_KEY); this.setConnectionTimeoutInMillis(60000); this.setSocketTimeoutInMillis(20000); System.setProperty("aip.log4j.conf", "classpath/log4j.properties"); }public AIPOcrJava(String aipId, String aipKey, String secretKey) {super(aipId,aipKey,secretKey); this.setConnectionTimeoutInMillis(60000); this.setSocketTimeoutInMillis(60000); System.setProperty("aip.log4j.conf", "classpath/log4j.properties")
1,通用文字识别
public class AipOcrTest {//通用文字识别 public static String basicGeneral (String file){HashMap<String,String> options = new HashMap<>(4); options.put("language_type", "CHN_ENG"); options.put("detect_direction", "true"); // 检测图片朝上 options.put("detect_language", "true"); // 检测语言,默认是不检查 options.put("probability", "true"); //是否返回识别结果中每一行的置信度 AIPOcrJava aipOcrJava = new AIPOcrJava(); org.json.JSONObject jsonObject = aipOcrJava.basicGeneral(file, options); return jsonObject.toString(); }
// String result = basicGeneral("D:\\BaiDuYun\\webImageTest.jpg"); //{"log_id":4384474417080234428,"wordsResult":[ // {"probability":{"average":0.968971,"min":0.955538,"variance":1.8E-4},"words":"甜蜜"}, // {"probability":{"average":0.871825,"min":0.744326,"variance":0.016256},"words":"酿造"}], // "words_result_num":2,"language":-1,"direction":0}
2,通用文字识别高精度版
public static JSONObject basicAccurateGeneral (String file) {HashMap<String,String> options = new HashMap<>(4); options.put("language_type", "CHN_ENG"); options.put("detect_direction", "true"); // 检测图片朝上 options.put("detect_language", "true"); // 检测语言,默认是不检查 options.put("probability", "true"); //是否返回识别结果中每一行的置信度 AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = FileCopyUtils.copyToByteArray(new FileInputStream(file)); } catch (IOException e) {e.printStackTrace(); }return aipOcrJava.basicAccurateGeneral(bytes, options); }
//高精度版 // JSONObject result = basicAccurateGeneral("D:\\BaiDuYun\\imageTest2.jpeg"); // String s = /result.toString(); // {"log_id":4759662113465573053,"wordsResult":[ // {"probability":{"average":0.985876,"min":0.940408,"variance":4.62E-4},"words":"当我爱一个人"}, // {"probability":{"average":0.999704,"min":0.99927,"variance":0},"words":"会很热烈又会很淡漠"}, // {"probability":{"average":0.996163,"min":0.964984,"variance":7.3E-5},"words":"会好好的爱也会口无遮拦的去说违心的话"}, // {"probability":{"average":0.993361,"min":0.960509,"variance":1.84E-4},"words":"如果我会毁了爱也会被爱毁掉"}, // {"probability":{"average":0.989808,"min":0.951065,"variance":3.72E-4},"words":"但是我一定很爱那个人"}, // {"probability":{"average":0.985335,"min":0.878724,"variance":0.001031},"words":"爱情对我来说是爱到他人看不穿"}], // "words_result_num":6,"language":-1,"direction":0}
3,
//通用文字识别(含位置信息版) public static JSONObject general (String file) {HashMap<String,String> options = new HashMap<>(); options.put("language_type", "CHN_ENG"); options.put("detect_direction", "true"); // 检测图片朝上 options.put("vertexes_location", "true"); options.put("recognize_granularity", "big"); options.put("detect_language", "true"); // 检测语言,默认是不检查 options.put("probability", "true"); //是否返回识别结果中每一行的置信度 AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = FileCopyUtils.copyToByteArray(new FileInputStream(file)); } catch (IOException e) {e.printStackTrace(); }return aipOcrJava.general(bytes, options); }
//JSONObject jsonObject = general("D:\\BaiDuYun\\wordTest.jpg"); // {"log_id":6464113204717508848,"words_result":[ // {"probability":{"average":0.955421,"min":0.81863,"variance":0.004858},"words":"想拉你一把"}, // {"probability":{"average":0.887704,"min":0.364053,"variance":0.054941},"words":"你的手在里"}, // {"probability":{"average":0.722126,"min":0.599519,"variance":0.015032},"words":"33"}, // {"probability":{"average":0.764071,"min":0.764071,"variance":0},"words":"i"}],"words_result_num":4,"language":-1,"direction":0} //String str = jsonObject.toString(); // ResultBean resultBean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(str),ResultBean.class);
4
// 含位置信息的 高精度版本 // 通用文字识别(含生僻字版) 繁体字 public static JSONObject enhancedGeneral (String file) {HashMap<String,String> options = new HashMap<>(6); options.put("language_type", "CHN_ENG"); options.put("detect_direction", "true"); options.put("detect_language", "true"); options.put("probability", "true"); AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.enhancedGeneral(bytes, options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject;
//生僻字 // JSONObject result = enhancedGeneral("D:\\BaiDuYun\\fantizi.jpg");
// 身份证识别 public static JSONObject idCard (String file,String side) {HashMap<String,String> options = new HashMap<>(6); options.put("detect_direction", "true"); options.put("detect_risk", "true");//是否开启身份证风险类型(身份证复印件、临时身份证、身份证翻拍、修改过的身份证)功能,默认不开启,即:false。可选值:true-开启;false-不开启 AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.idcard(bytes, side,options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject; }
//身份证 正面 有一个 image-status
normal-识别正常reversed_side-未摆正身份证non_idcard-上传的图片中不包含身份证blurred-身份证模糊over_exposure-身份证关键字段反光或过曝unknown-未知状态
// JSONObject front = idCard("D:\\BaiDuYun\\idCrdFront.jpg", "front"); // System.out.println(front.toString()); //{"log_id":3309234557215895357,"words_result": // {"姓名":{"words":"***","location":{"top":444,"left":138,"width":172,"height":63}}, // "民族":{"words":"汉","location":{"top":574,"left":419,"width":36,"height":44}}, // "住址":{"words":"****************","location":{"top":788,"left":125,"width":568,"height":130}}, // "公民身份号码":{"words":"************00122","location":{"top":1045,"left":361,"width":707,"height":76}}, // "出生":{"words":"******8","location":{"top":0,"left":0,"width":0,"height":0}}, // "性别":{"words":"男","location":{"top":0,"left":0,"width":0,"height":0}}},"words_result_num":6,"image_status":"normal","direction":0}
//身份 背面 传的参数 "back" //JSONObject back = idCard("D:\\BaiDuYun\\idCrdBack.jpg","back"); // System.out.println(back.toString()); //{"log_id":1473111127994119341,"words_result": // {"失效日期":{"words":"20220502","location":{"top":1029,"left":732,"width":190,"height":42}}, // "签发机关":{"words":"***县公安局","location":{"top":945,"left":504,"width":236,"height":45}}, // "签发日期":{"words":"20120502","location":{"top":1037,"left":508,"width":198,"height":42}}}, // "words_result_num":3,"image_status":"normal","direction":0}
// 银行卡识别 public static JSONObject bankCard (String file) {HashMap<String,String> options = new HashMap<>(6); AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.bankcard(bytes,options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject; }
//银行卡识别 // JSONObject result = bankCard("D:\\BaiDuYun\\bankCard.jpg"); // System.out.println(result.toString()); //+bank_card_type number 是 银行卡类型,0:不能识别; 1: 借记卡; 2: 信用卡 //{"result":{"bank_card_number":"621**********13","bank_card_type":1,"bank_name":"邮储银行"},"log_id":3218655891356708921}
//驾驶证识别 public static JSONObject drivingLicense (String file) {HashMap<String,String> options = new HashMap<>(6); options.put("detect_direction", "false"); //不检查朝上 AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.drivingLicense(bytes,options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject; }
//驾照识别 // JSONObject result = drivingLicense("D:\\BaiDuYun\\drivingLicense.jpg"); // System.out.println(result.toString()); //{"log_id":2986902282992381075,"words_result": // {"姓名":{"words":"***"},"至":{"words":"20211124"}, // "证号":{"words":"5********"}, // "出生日期":{"words":"19921004"}, // "住址":{"words":"**********号"}, // "国籍":{"words":"中国"}, // "初次领证日期":{"words":"20151124"}, // "准驾车型":{"words":"C1"}, // "有效期限":{"words":"20151124"}, // "性别":{"words":"女"}},"words_result_num":10,"direction":-1}
//行驶证 识别 public static JSONObject vehicleLicense (String file) {HashMap<String,String> options = new HashMap<>(6); options.put("detect_direction", "false"); //不检查朝上 options.put("accuracy", "normal"); // normal 使用快速服务,1200ms左右时延;缺省或其它值使用高精度服务,1600ms左右时延 AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.vehicleLicense(bytes,options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject; }
//没得车,所以没得行驶证............,未测试.....
//车牌 识别 public static JSONObject plateLicense (String file) {HashMap<String,String> options = new HashMap<>(6); options.put("multi_detect", "true"); //是否检测多张车牌,默认为false,当置为true的时候可以对一张图片内的多张车牌进行识别 AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.plateLicense(bytes,options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject; }
// 营业执照识别 businessLicense public static JSONObject businessLicense (String file) {HashMap<String,String> options = new HashMap<>(6); AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.businessLicense(bytes,options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject; }
//车牌识别 // JSONObject result = plateLicense("D:\\BaiDuYun\\plateLicense.jpg"); //System.out.println(result.toString()); //{"log_id":5545684252572090954,"words_result":[ // {"number":"粤A69L59"," // vertexes_location":[{"x":44,"y":106},{"x":243,"y":107},{"x":243,"y":172},{"x":44,"y":170}], // "color":"blue", // "probability":[1,0.9999933242797852,0.9999986886978149,0.9999988079071045,0.9999998807907104,0.9999427795410156,0.9997766613960266]}]}
//执照识别 businessLicense JSONObject result = plateLicense("D:\\BaiDuYun\\businessLicense.jpg"); System.out.println(result.toString());
//自定义模版文字识别 // 自定义模版文字识别,是针对百度官方没有推出相应的模版,但是当用户需要对某一类卡证/票据(如房产证、军官证、火车票等)进行结构化的提取内容时 // ,可以使用该产品快速制作模版,进行识别。 public static JSONObject custom (String file) {HashMap<String,String> options = new HashMap<>(6); String templateSign = "Nsdax2424asaAS791823112"; //通用模板的 编号 AIPOcrJava aipOcrJava = new AIPOcrJava(); // JSONObject jsonObject = aipOcrJava.basicAccurateGeneral(file, options); 或者是传url byte[] bytes = new byte[0]; try {bytes = Util.readFileByBytes(file); } catch (IOException e) {e.printStackTrace(); }JSONObject jsonObject = aipOcrJava.custom(bytes,templateSign,options); // ResultBean bean = com.alibaba.fastjson.JSONObject.toJavaObject(com.alibaba.fastjson.JSONObject.parseObject(jsonObject.toString()), ResultBean.class); return jsonObject; }
百度的语音其实都跟这些差不多,可以自己试试了.
百度云文字识别 (AIPOcr)相关推荐
- java做百度语言识别_java实现百度云文字识别接口代码
java实现百度云文字识别接口代码 发布时间:2020-09-16 13:35:23 来源:脚本之家 阅读:52 作者:syy363250763 本文实例为大家分享了java实现百度云文字识别的接口具 ...
- 百度云 文字识别API在线调用测试
1.0:百度云文字识别应用创建 1.1:找到文字识别产品 1.2:点击使用文字识别 1.3:点击创建应用 1.4:点击 查看应用 ,并输入基本信息,点击立即创建 2.0:token 获取 2.1:找 ...
- python 百度云文字识别 proxy_python使用百度文字识别功能方法详解
介绍python使用百度智能去的文字识别功能,可以识别截图中的文,登陆路验证码等等., 登陆百度智能云,选择产品服务. 选择"人工智能"---文字识别. 点击创建应用. 如图下面有 ...
- 百度云 文字识别 身份证识别
身份识别 package ai1;import java.util.HashMap;import org.json.JSONObject;import com.baidu.aip.ocr.AipOcr ...
- python 百度云文字识别 proxy_Python基于百度AI的文字识别的示例
Python基于百度AI的文字识别的示例 发布时间:2020-10-03 14:52:27 来源:脚本之家 阅读:66 使用百度AI的文字识别库,做出的调用示例,其中filePath是图片的路径,可以 ...
- 用Python实现最简单的文字识别:基于百度云文字识别API
Python版本:3.6.5 百度云提供的文字识别技术,准确率还是非常高的,而且每天还有5w次免费的调用量,对于用来学习或者偶尔拿来用用,已经完全足够了.文章提供一个模板,稍加修改就可以直接套用.注释 ...
- JavaWeb使用百度云文字识别上传图片内容
今天有童鞋问我,android端实现了拍照识别图片内容,那JavaWeb的话,是不是也可以上传图片进行识别呢? 答案是一定的. 效果图走一波 选择文件点击确认上传 识别后返回识别结果 整体来说还是比较 ...
- 使用Python+百度云文字识别达到pdf扫描版转文字的学习过程
2021/3/18 新买了kindle想看pdf的书,但是只有扫描版,在kindle上看了个寂寞.于是将查了教程,将pdf转成合适的大小,放入kindle,是乱码的,因为扫描版是图片,转成mobi就会 ...
- JAVA基于百度云文字(车牌、身份证、图片)识别提取
基于百度云文字(车牌.身份证.图片)识别提取 由于自己想写一个停车场项目,所以去查询了百度API文档,可以实现所有图片中文字的提取,此贴为傻瓜式教程,希望所有像我一样的初学者都可以看懂,有所收获,话不 ...
- 百度 图片文字识别 Python版本
百度图片文字识别文档:https://cloud.baidu.com/doc/OCR/s/Sk3h7xyad 1. 创建应用 登录百度智能云,在产品服务/文字识别-概览下创建应用 2. 查看应用列表, ...
最新文章
- MarkDown入门及技巧
- 【职场攻略】是什么决定了我们的工资
- 用java编写五子棋游戏_java编写一个五子棋游戏,拜托了
- 为何有些程序员总是想要“干掉”产品经理?
- “中国式”盗版该何去何从?
- GeneDock协助诊断基层地区的听力障碍儿童 #科技有温度#
- Linux服务器运行环境搭建(四)——Tomcat安装
- cocos2d 浅析
- ubuntu安装tim
- 交换机、路由器 以及 路由器工作模式:桥接模式、路由模式、中继模式
- aspose-cad dwg转pdf dwg转png dwg转svg
- sudo 授权需谨慎,否则亲人两行泪!6 个超实用使用技巧
- lvs realserver 配置VIP
- 汽车软件行业工程师详细介绍?(中)
- opencv 双目标定操作完整版
- (无技术)我的网站开发之路及部分服务器商优缺点
- 一般人我不告诉的bug
- matlab读取txt文件大全
- HDOJ3594-仙人掌图的判断
- 微信小程序基础库版本与微信版本对应关系