手写文字识别-JavaAPI示例代码

不知不觉手写文字识别百度已经开始邀测了。需要的小伙伴去申请了哦。申请方式加入文字识别群找PM。或者工单提交申请。都要说明自己的APPID哦。

接口地址:https://aip.baidubce.com/rest/2.0/ocr/v1/handwriting

-----------------------------------------------------下面开始代码-----------------------------------------------------

手写文字识别-示例代码

import java.net.URLEncoder;

import com.baidu.aip.util.Base64Util;

import com.xiaoshuai.baidu.util.FileUtil;

import com.xiaoshuai.baidu.util.HttpUtil;

/**

* @author 小帅丶

* @类名称 HandWriteTest

* @remark 手写文字接口示例代码 只返回中英文及部分符合正则的内容

* @date 2018-1-26

*/

public class HandWriteTest {

public static void main(String[] args) throws Exception {

String url = "https://aip.baidubce.com/rest/2.0/ocr/v1/handwriting";

String accessToken = "自己的accestoken";

byte[] imageData = FileUtil.readFileByBytes("C:/Users/Administrator/Desktop/xs2.jpg");

String img64 = Base64Util.encode(imageData);

String param ="image="+URLEncoder.encode(img64,"UTF-8");

String object = HttpUtil.post(url, accessToken, param);

HandWriteBean bean = JSONObject.parseObject(object, HandWriteBean.class);

String regex = "^[..,,。!a-zA-Z0-9_\u4e00-\u9fa5]*$";

Pattern pattern = Pattern.compile(regex);

Matcher matcher = null;

String text ="";

List list = bean.getWords_result();

for (int i = 0; i < list.size(); i++) {

matcher = pattern.matcher(list.get(i).getWords());

while (matcher.find()) {

text +=matcher.group();

}

}

System.out.println("识别的内容是:"+text);

}

}

手写文字识别-所需要的Java对象

package com.xiaoshuai.baidu.ocr;

import java.util.List;

/**

* @author 小帅丶

* @类名称 HandWriteBean

* @remark

* @date 2018-1-27

*/

public class HandWriteBean {

private long log_id;

private int words_result_num;

private List words_result;

/**

* @return the log_id

*/

public long getLog_id() {

return log_id;

}

/**

* @param log_id

* log_id

*/

public void setLog_id(long log_id) {

this.log_id = log_id;

}

/**

* @return the words_result_num

*/

public int getWords_result_num() {

return words_result_num;

}

/**

* @param words_result_num

* words_result_num

*/

public void setWords_result_num(int words_result_num) {

this.words_result_num = words_result_num;

}

/**

* @return the words_result

*/

public List getWords_result() {

return words_result;

}

/**

* @param words_result

* words_result

*/

public void setWords_result(List words_result) {

this.words_result = words_result;

}

public static class Words_result{

private Location location;

private String words;

/**

* @return the location

*/

public Location getLocation() {

return location;

}

/**

* @param location

* location

*/

public void setLocation(Location location) {

this.location = location;

}

/**

* @return the words

*/

public String getWords() {

return words;

}

/**

* @param words

* words

*/

public void setWords(String words) {

this.words = words;

}

}

public static class Location{

private int width;

private int top;

private int left;

private int height;

/**

* @return the width

*/

public int getWidth() {

return width;

}

/**

* @param width

* width

*/

public void setWidth(int width) {

this.width = width;

}

/**

* @return the top

*/

public int getTop() {

return top;

}

/**

* @param top

* top

*/

public void setTop(int top) {

this.top = top;

}

/**

* @return the left

*/

public int getLeft() {

return left;

}

/**

* @param left

* left

*/

public void setLeft(int left) {

this.left = left;

}

/**

* @return the height

*/

public int getHeight() {

return height;

}

/**

* @param height

* height

*/

public void setHeight(int height) {

this.height = height;

}

}

}

手写文字识别-返回的JSON字符串(全部内容)

因为文档还没有。不太确定参数是什么。默认只传递到了image参数。会对图片上的横线也做了识别。

{"log_id": 8502255431261249697, "words_result_num": 11, "words_result": [{"location": {"width": 323, "top": 20, "left": 5, "height": 18}, "words": "………………….…………………………………………"}, {"location": {"width": 1041, "top": 25, "left": 347, "height": 41}, "words": "……………………………………………………………………………………………………………………………………………………………………………………………………"}, {"location": {"width": 944, "top": 159, "left": 2, "height": 39}, "words": "………………………"}, {"location": {"width": 438, "top": 176, "left": 981, "height": 25}, "words": "…………………………………:*"}, {"location": {"width": 243, "top": 298, "left": 2, "height": 23}, "words": "…………………………………………………………."}, {"location": {"width": 436, "top": 309, "left": 266, "height": 20}, "words": "……………………………………"}, {"location": {"width": 729, "top": 314, "left": 698, "height": 23}, "words": "………………………………………………"}, {"location": {"width": 233, "top": 588, "left": 5, "height": 22}, "words": "…………"}, {"location": {"width": 692, "top": 454, "left": 366, "height": 198}, "words": "开发者小帅"}, {"location": {"width": 398, "top": 732, "left": 423, "height": 15}, "words": "………………,………………………………………………………………………………"}, {"location": {"width": 596, "top": 862, "left": 840, "height": 19}, "words": "……………………………………"}]}

手写文字识别-返回的JSON字符串(图片文字内容)

{

"log_id": 8502255431261250000,

"words_result_num": 11,

"words_result": [

{

"location": {

"width": 692,

"top": 454,

"left": 366,

"height": 198

},

"words": "开发者小帅"

}

]

}

手写文字识别-测试图片

是不是发现识别还是蛮不错的。相当准确。当然前提是作者写的字不错了。哈哈。

过于潦草的也进行了测试。准确率在75%左右

这周我的小程序也争取更新加入手写文字识别功能,敬请期待。

java文字手写识别_【手写文字识别】-JavaAPI示例代码相关推荐

  1. java人体识别_【人体分析-人像分割】JavaAPI示例代码

    接口能力: 对于输入的一张图片(可正常解码,且长宽比适宜),识别人体的轮廓范围,与背景进行分离,适用于拍照背景替换.照片合成.身体特效等场景.输入正常人像图片,返回分割后的二值结果图和分割类型(目前仅 ...

  2. Java EasyExcel在Web网站中读写Excel的方法及示例代码

    使用EasyExcel可以更容易简单在Web网站中读写Excel,本文主要介绍在Java Web网站中读写Excel方法及示例代码. 原文地址:Java EasyExcel在Web网站中读写Excel ...

  3. vue 手写签名_手写Promise/Promise.all/Promise.race(手写系列一)

    背景 几个月没写文章了,愧对关注本专栏的小伙伴.最近有同学提议我出一个手写系列的文章对常见对前端工具.框架.设计模式做一个覆盖.同时有个要求:代码要尽量短小易懂,并且体现原理,让学习者学习过后能在未来 ...

  4. python查找文字在图片中的位置_图片中的文字竟然能如此快速提取?OCR文字识别功能简直太强大了...

    想一想你之前如何将线下收集的材料信息采录到线上系统的? 比如作为财务人员,员工凭发票报销费用,但是收集到发票录入信息是需要将发票种类名称.发票代码.纳税人识别号等各种信息录入到系统.你是不是还在一个字 ...

  5. ocr语种识别_利用OCR图文识别,快速帮你提取文字信息

    我们在浏览网页.读书的时候,经常找到我们感兴趣的资料,有时候一些纸质文字或图片是无法复制保存的,那么为了方便这类信息的提取.编辑保存,中安未来特研发了OCR图文识别技术: 中安未来OCR图文识别技术是 ...

  6. ocr 超时小票识别_【FreeOCR(文字扫描识别软件)和小票打印机测试工具哪个好用】FreeOCR(文字扫描识别软件)和小票打印机测试工具对比-ZOL下载...

    蒙泰5.0应该是国内用得最多的一个喷绘软件吧,蒙泰适合各种类型的文字排版,如报纸.书刊杂志.中英文字典.古文.儿童拼音读物.卡通画册等.有卓越的文字处理功能,强大的图形处理能力,能彻底的解决输出难题, ...

  7. 什么叫侧面指纹识别_哪种指纹识别方式好?侧边指纹识别可能会成为主流

    我以前没有用过背面的指纹.从手机到现在,前置解屏都是一个被认为是理所当然的,甚至升级也应该是屏幕下的指纹.然而,有了小米8,突然觉得指纹解锁实际上不是一个非常重要的问题.首先,如果是前置指纹解屏的话, ...

  8. 用python做一个车牌识别_如何用 Python 识别车牌

    车牌识别在高速公路中有着广泛的应用,比如我们常见的电子收费(ETC)系统和交通违章车辆的检测,除此之外像小区或地下车库门禁也会用到,基本上凡是需要对车辆进行身份检测的地方都会用到. 简介 车牌识别系统 ...

  9. 韩语识别_韩语文字识别_韩语图片识别 - 云+社区 - 腾讯云

    广告关闭 腾讯云双11爆品提前享,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高满返5000元! 购买预付费包更加优惠 识别 小时语音不到 元 每月赠送免费额度最大程度降低客户成本 ...

最新文章

  1. Linux服务器搭建常用环境(一)
  2. hdu3037 Saving Beans
  3. STL中的栈结构和队列结构
  4. selenium2与python自动化2-元素定位
  5. [PHP] 项目实践中的自动加载实现
  6. C# winform bin文件夹、obj文件夹、Properties文件夹下分别存放什么文件?
  7. Permission denied (publickey) 解决方案
  8. 《Node Web开发》((美)David Herron)【摘要 书评 试读】- 京东图书
  9. vbs整人代码蓝屏_求大量VBS整人代码.
  10. vue图片懒加载 以及 页面刷新加载不显示大括号{{}}
  11. Xcode打包证书,ipa安装启动闪退的相关问题
  12. 计算机网络学习笔记3-ARP+广播风暴
  13. uniapp 跳转公众号获其他小程序
  14. 模拟动态登录,获取cookie和图片验证码登录(AcFun和豆瓣)
  15. 2007年IT产业回顾:划时代的一年 一个变革的时代
  16. 搭建用户增长体系,这5个方法告诉你怎么做
  17. 图解原型链及其继承优缺点
  18. 网络超时检测、心跳检测的方法
  19. 值得细细品读的URL资源
  20. [计算机通信网络]以太网的帧格式详解

热门文章

  1. 技术解析:一文看懂 Anolis OS 国密生态
  2. 前端实现模糊查询不区分大小写
  3. 缓存穿透、击穿、雪崩
  4. C51单片机播放音乐《起风了》
  5. element级联选择器城市3级联动三级联动json数据
  6. html涟漪动画效果,CSS 在按钮上做个涟漪效果(Ripple Animation)
  7. 武魂优化游戏引擎 视觉效果全新进化
  8. 青少年编程 中国电子学会scratch等级考试二级历年真题解析【持续更新 已更新至2023年3月】
  9. 同步练习(Java SE(十二))
  10. CountDownLatch 用法和源码解析