# 通用印刷体识别

调试工具

接口应在服务器端调用,不可在前端(小程序、网页、APP等)直接调用,具体可参考接口调用指南

接口英文名:commOcr

本接口用于识别通用印刷体

# 1. 调用方式

# HTTPS 调用

POST https://api.weixin.qq.com/cv/ocr/comm?access_token=ACCESS_TOKEN&img_url=IMG_URL

# 云调用

  • 调用方法:ocr.printedText

  • 出入参和 HTTPS 调用相同,调用方式可查看 云调用 说明文档

# 第三方调用

  • 本接口支持第三方平台代商家调用。

  • 该接口所属的权限集 id 为:117

  • 服务商获得其中之一权限集授权后,可通过使用 authorizer_access_token 代商家进行调用,具体可查看 第三方调用 说明文档。

# 2. 请求参数

# 查询参数 Query String parameters

参数名类型必填示例说明
access_tokenstringACCESS_TOCKEN接口调用凭证,可使用 access_tokenauthorizer_access_token
img_urlstringENCODE_URL要检测的图片 url,传这个则不用传 img 参数。

# 请求体 Request Payload

参数名类型必填说明
imgformdataform-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用传 img_url。

# 3. 返回参数

# 返回体 Response Payload

参数名类型说明
errcodenumber错误码
errmsgstring错误描述
itemsobjarray识别结果
img_sizeobject图片大小

# Res.items(Array) Object Payload

识别结果

参数名类型说明
posobject位置信息

# Res.img_size Object Payload

图片大小

参数名类型说明
wnumber宽度
hnumber高度

# Res.items(Array).pos Object Payload

位置信息

参数名类型说明
left_topobject左上角位置
right_topobject右上角位置
right_bottomobject右下角位置
left_bottomobject左下角位置

# Res.items(Array).pos.left_top Object Payload

左上角位置

参数名类型说明
xnumberx坐标
ynumbery坐标

# Res.items(Array).pos.right_top Object Payload

右上角位置

参数名类型说明
xnumberx坐标
ynumbery坐标

# Res.items(Array).pos.right_bottom Object Payload

右下角位置

参数名类型说明
xnumberx坐标
ynumbery坐标

# Res.items(Array).pos.left_bottom Object Payload

左下角位置

参数名类型说明
xnumberx坐标
ynumbery坐标

# 4. 注意事项

本接口无特殊注意事项

# 5. 代码示例

# 5.1 上传文件请求

请求示例

curl -F 'img=@test.jpg' "https://api.weixin.qq.com/cv/ocr/comm?access_token=ACCESS_TOCKEN" 

返回示例

{
    "errcode": 0, 
    "errmsg": "ok", 
    "items": [ //识别结果
        {
            "text": "腾讯", 
            "pos": {
                "left_top": {
                    "x": 575, 
                    "y": 519
                }, 
                "right_top": {
                    "x": 744, 
                    "y": 519
                }, 
                "right_bottom": {
                    "x": 744, 
                    "y": 532
                }, 
                "left_bottom": {
                    "x": 573, 
                    "y": 532
                }
            }
        }, 
        {
            "text": "微信团队", 
            "pos": {
                "left_top": {
                    "x": 670, 
                    "y": 516
                }, 
                "right_top": {
                    "x": 762, 
                    "y": 517
                }, 
                "right_bottom": {
                    "x": 762, 
                    "y": 532
                }, 
                "left_bottom": {
                    "x": 670, 
                    "y": 531
                }
            }
        }
    ], 
    "img_size": { //图片大小
        "w": 1280, 
        "h": 720
    }
}

# 5.2 上传链接请求

请求示例

curl "https://api.weixin.qq.com/cv/ocr/comm?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN"

返回示例

{
    "errcode": 0, 
    "errmsg": "ok", 
    "items": [ //识别结果
        {
            "text": "腾讯", 
            "pos": {
                "left_top": {
                    "x": 575, 
                    "y": 519
                }, 
                "right_top": {
                    "x": 744, 
                    "y": 519
                }, 
                "right_bottom": {
                    "x": 744, 
                    "y": 532
                }, 
                "left_bottom": {
                    "x": 573, 
                    "y": 532
                }
            }
        }, 
        {
            "text": "微信团队", 
            "pos": {
                "left_top": {
                    "x": 670, 
                    "y": 516
                }, 
                "right_top": {
                    "x": 762, 
                    "y": 517
                }, 
                "right_bottom": {
                    "x": 762, 
                    "y": 532
                }, 
                "left_bottom": {
                    "x": 670, 
                    "y": 531
                }
            }
        }
    ], 
    "img_size": { //图片大小
        "w": 1280, 
        "h": 720
    }
}

# 6. 错误码

以下是本接口的错误码列表,其他错误码可参考 通用错误码

错误码错误描述解决方案
-1system error系统繁忙,此时请开发者稍候再试
40001invalid credential  access_token isinvalid or not latest获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口
101000invalid image url
101002decode image failed图片大小超过限制,resp_type = 0: 2MB,resp_type = 1: 10MB
101003not enough market quota

# 7. 适用范围

本接口在不同账号类型下的可调用情况:
小程序公众号服务号
仅认证 仅认证
  • ✔:该账号可调用此接口
  • 仅认证:表示仅允许企业主体已认证账号调用,未认证或不支持认证的账号无法调用
  • 其他未明确声明的账号类型,如无特殊说明,均不可调用此接口;