微信小程序 OCRprintedText


当前第2页 返回上一页

图片支持使用img参数实时上传,也支持使用img_url参数传送图片地址,由微信后台下载图片进行识别。 通用印刷体OCR适用于屏幕截图、印刷体照片等场景

请求数据示例

示例1:

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

示例2:

curl -F ‘img=@test.jpg’“http://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
    }
}

云调用

云调用是小程序·云开发提供的在云函数中调用微信开放接口的能力,需要在云函数中通过 wx-server-sdk 使用。

接口方法

openapi.ocr.printedText
需在 config.json 中配置 ocr.printedText API 的权限,详情

请求参数

属性 类型 默认值 必填 说明
imgUrl string 要检测的图片 url,传这个则不用传 img 参数。
img FormData form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用传 img_url。

img 的结构

属性 类型 默认值 必填 说明
contentType string 数据类型,传入 MIME Type
value Buffer 文件 Buffer

返回值

Object

返回的 JSON 数据包

属性 类型 说明
errCode string 错误码
errMsg string 错误信息
items string 识别结果
imgSize string 图片大小

异常

Object

抛出的异常

属性 类型 说明
errCode string 错误码
errMsg string 错误信息

errCode 的合法值

说明 最低版本

使用说明

接口限制 内测期间已认证的订阅号、服务号、企业号、小程序可直接调用,次数限制为500次/天。

使用 Tips 此接口为后台接口,可基于自有业务承载情况,搭配小程序的拍照、相册选照等一起使用,即可完成身份证照片的采集、上传、识别、信息返回等流程,用于需要基于身份证、银行卡等实体卡或证,采集照片或文字信息等的业务场景。

图片说明 文件大小限制:小于2M

图片支持使用img参数实时上传,也支持使用img_url参数传送图片地址,由微信后台下载图片进行识别。 通用印刷体OCR适用于屏幕截图、印刷体照片等场景

请求数据示例

const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.ocr.printedText({
        type: 'photo',
        imgUrl: 'ENCODE_URL'
      })
    return result
  } catch (err) {
    return err
  }
}

// cloud = require('wx-server-sdk')
// ...
// 方法返回 Promise
cloud.openapi.ocr.printedText({
  type: 'photo',
  img: {
    contentType: 'image/png',
    value: Buffer
  }
})

返回数据示例

{
    "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
    }
}



标签:微信小程序

返回前面的内容

相关阅读 >>

微信小程序工具 下载地址

微信小程序api 微信支付

sdk数据库 aggregate联表查询

微信小程序api 关闭当前页面

微信小程序视图容器 cover-image

微信小程序api nfc-isodep标签

微信小程序 工具库类typescript支持

微信小程序api 背景音频-监听播放事件

微信小程序api mdns

微信小程序api-设备-加速度计

更多相关阅读请进入《微信小程序》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...