用RestTemplate调用百度文字识别接口
来源:互联网 发布:淘宝企业店铺过户 编辑:程序博客网 时间:2024/06/18 06:49
1. 将RestTemplate加载到bean工厂
@Configurationpublic class RestTemplateConfig { private Logger logger = LogManager.getLogger(getClass()); @Bean public RestTemplate restTemplate(ClientHttpRequestFactory factory){logger.debug("-----------加载RestTemplate模板----------"); return new RestTemplate(factory); } @Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setReadTimeout(5000); factory.setConnectTimeout(15000); return factory; }}
2.调用接口,获取单位名称,和统一社会信用代码
//营业执照识别 @Test public void businessLicenseTest() { String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/business_license?access_token="+access_token; String image = getImage("g://picture//c2.png"); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/x-www-form-urlencoded"); MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<String, String>(); postParameters.add("image", image); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( postParameters, headers); String result = template.postForObject(url,requestEntity,String.class); try { result = new String (result.getBytes("iso-8859-1"),"utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } System.out.println("--------"+result); printResult(result,"社会信用代码"); }
public void printResult(String result , String item){ JSONObject jsonObject = new JSONObject(result); JSONObject words_result = (JSONObject)jsonObject.get("words_result"); JSONObject name = (JSONObject)words_result.get(item); String name1 = (String)name.get("words"); System.err.println(item + "--" + name1); } public String getImage(String url){ InputStream in = null; byte[] data = null; //读取图片字节数组 try { in = new FileInputStream(url); data = new byte[in.available()]; in.read(data); in.close(); } catch (IOException e) { e.printStackTrace(); } String image = Base64.encode(data); return image; }
图片
阅读全文
0 0
- 用RestTemplate调用百度文字识别接口
- RestTemplate远程接口调用
- 使用restTemplate调用外部接口
- 调用百度API实现简单的文字识别
- 调用百度api文字识别,并将结果存入txt
- 百度文字识别
- RestTemplate使用gzip压缩调用接口
- java RestTemplate调用远程服务接口
- Winfrom调用百度接口做的图片识别,带发音
- 调用百度大脑智能里的文字识别实现图片识别
- RestTemplate 调用
- 用百度AI的OCR文字识别结合PHP实现了图片的文字识别功能
- 百度OCR文字识别-身份证识别
- springboot中用RestTemplate调用百度ip定位服务
- 利用百度OCR的node.js的接口实现文字识别的功能
- Spring中使用RestTemplate调用第三方接口API
- 手写板 (调用百度接口)
- 手写板 (调用百度接口)
- 识别物体的滑窗是怎么快速建立的?
- 用GPU加速深度学习: Windows安装CUDA+TensorFlow教程
- 快速排序&冒泡排序
- Vue实战--v-bind动态绑定Class和style
- 视频录制不清楚、模糊解决办法
- 用RestTemplate调用百度文字识别接口
- 关于队列的操作理解
- Journey
- CentOS 7
- 右键新建excel文档无法打开,提示“文件格式或扩展名无效”
- 《java基础入门》课后习题答案_传智播客版
- 查找tomcat程序中某个进程占用CPU高的方法
- maven学习笔记1--简介
- 2017.11.29 python学习笔记