首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【手写文字识别】-JavaAPI示例代码

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

作者头像
小帅丶
发布2018-02-09 17:37:26
3.6K0
发布2018-02-09 17:37:26
举报
文章被收录于专栏:XAIXAI
手写文字识别-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 = "自己的access_token";
		byte[] imageData = FileUtil.readFileByBytes("C:/Users/Administrator/Desktop/xs.jpg");
		String img64 = Base64Util.encode(imageData);
		String param ="image="+URLEncoder.encode(img64,"UTF-8");
		System.out.println("请求的参数:"+param);
		String object = HttpUtil.post(url, accessToken, param);
		System.out.println(new String(object));
	}
}
  • 手写文字识别-返回的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%左右

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
文字识别
文字识别(Optical Character Recognition,OCR)基于腾讯优图实验室的深度学习技术,将图片上的文字内容,智能识别成为可编辑的文本。OCR 支持身份证、名片等卡证类和票据类的印刷体识别,也支持运单等手写体识别,支持提供定制化服务,可以有效地代替人工录入信息。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档