通用文字识别API如何通过Java进行调用?(一)

一、什么是通用文字识别?

通用文字识别又叫通用文字OCR识别,文字识别,文字图片识别,通用文字识别是一种算法识别技术,它能够将图像中的文字转换为可编辑的文本格式,可支持多种类型图片类型。

二、通用文字识别适用哪些场景?

例如:

1.办公领域:可快速将纸质文档转换为电子文档,便于编辑、存储和搜索。例如,扫描合同、文件等,提高工作效率。

2.教育领域:用于识别教材、笔记中的文字,方便学生整理学习资料。

3.互联网应用:在社交媒体中自动识别图片中的文字,以便进行搜索和分类;在电商平台中,识别商品图片上的文字信息。

三、如何用Java进行通用文字识别接口调用?

下面我们以阿里云为例,通过Java实现调用:

	public static void main(String[] args) {
	    String host = "https://kzwordocr.market.alicloudapi.com";
	    String path = "/api-mall/api/general/ocr";
	    String method = "POST";
	    String appcode = "你自己的AppCode";
	    Map<String, String> headers = new HashMap<String, String>();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + appcode);
	    //根据API的要求,定义相对应的Content-Type
	    headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	    Map<String, String> querys = new HashMap<String, String>();
	    Map<String, String> bodys = new HashMap<String, String>();
	    bodys.put("image", "image");
	    bodys.put("url", "url");


	    try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
	    	System.out.println(response.toString());
	    	//获取response的body
	    	//System.out.println(EntityUtils.toString(response.getEntity()));
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	}

正确返回示例如下:

{
    "msg": "成功",
    "success": true,
    "code": 200,
    "data": {
        "orderNo": "202407102026336827870",
        "info": [
            {
                "line_no": 0, //文本行编号,按从左至右、从上至下顺序依次排列
                "confidence": 0.96655273, //行文本识别置信度 0-1 
                "line_content": "姓名", //识别出的文本行内容
                "line_position": {
                    "x": 53,
                    "width": 53,
                    "y": 66,
                    "line_direction": 0,
                    "height": 22
                }
            },
            {
                "line_no": 1,
                "confidence": 0.98909503,
                "line_content": "陈海江",
                "line_position": {
                    "x": 102,
                    "width": 63,
                    "y": 63,
                    "line_direction": 0,
                    "height": 23
                }
            }
        ]
    }
}


line_no		文本行编号,按从左至右、从上至下顺序依次排列
line_content	识别出的文本行内容
confidence	行文本识别置信度
line_position	文本行位置信息,表示为坐标和旋转角度(左上角X,左上角Y,宽Width,高Height,旋转角度Line Position)+x左上角顶点横坐标X +y	左上角顶点纵坐标Y
width	        矩形框的宽
height		矩形框的高
line_direction	文本行的旋转角度
words		文本行内单字符的内容数组,数组元素为一个Json结构,包含character和confidence
character	候选字符character
confidence	单字符的识别置信度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值