Baidu OCR text recognition, card recognition, bill recognition native plug-ins

1. Plug-in recommendation

2. Preparations

1. Certificate preparation for Android and IOS

2. Baidu data preparation

  • Enter Baidu AI Open Platform

  • Click the console in the upper right corner to log in. If you don't have an account, please register an account first.

  • After logging in, if there is no real-name authentication, please real -name authentication first . It is recommended that the real-name authentication of the enterprise (more functions are available)

  • Select Text Recognition - "Create Application"

    Create an app

  • Get API Key, Secret Key and License file

    Get the license file

  • Baidu OCR interface charging details, there are free gift times, for development and debugging, please view it in Baidu Console - "Overview , or directly view the product pricing document

    Baidu OCR interface fee details

3. Get started quickly

  • Step1: Download this plugin example project, or download GitHub - silianpan/Seal-UniPlugin-Demo

  • Step2: Open manifest.json—"Basic Configuration—"Re-obtain DCloud AppID

  • Step3: Click to try

  • Step4:打开manifest.json—》App原生插件配置—》选择云端插件

  • Step5:在项目根目录创建nativeplugins/Seal-OCR/android/assets层层文件夹,IOS端创建nativeplugins/Seal-OCR/ios目录

  • Step6:将准备工作中下载的Android端的aip.license(若下载文件名不同,统一改成此文件名)文件放置到上面创建的assets目录,IOS端aip.license文件直接放置到ios目录

  • Step7:制作自定义调试基座:在HBuilderX菜单中点击运行—》运行到手机或模拟器—》制作自定义调试基座,填写步骤及注意事项如下图

    附:debug.keystore下载链接,仅仅用作测试

    Keystore name: “debug.keystore” Keystore password: “android” Key alias: “AndroidDebugKey” Key password: “android”

    md5:A5:61:77:2E:AA:63:15:18:47:D6:5B:EC:6A:FA:F4:0A

  • Step8:选择自定义调试基座:点击运行—》运行到手机或模拟器—》基座运行选择—》自定义调试基座

  • Step9:调试运行:点击运行—》运行到手机或模拟器—》运行到Android App基座

四、接口使用手册

  • 插件方法:ocr
  • ocr方法参数
参数 类型 默认值 是否必填 说明
ak string null 百度AI开放平台控制台应用Api Key,正式发布推荐采用License文件
sk string null 百度AI开放平台控制台应用Secret Key,正式发布推荐采用License文件
ocrType string null 识别类型,详细说明如下
resultType int 0 返回结果类型,0:只返回识别结果,1:只返回被识别图片,2:返回识别结果+被识别图片
scaleWidth double 0.2 拍照后显示的裁剪框宽度,取值范围0.05 ~ 0.2,值越小裁剪框越大,0.05为最大,宽度和高度可设不同,ocrType类型为 "身份证"、"银行卡" 和 "护照" 时无效,其他类型均有效
scaleHeight double 0.2 拍照后显示的裁剪框高度,取值范围0.05 ~ 0.2,值越小裁剪框越大,0.05为最大,宽度和高度可设不同,ocrType类型为 "身份证"、"银行卡" 和 "护照" 时无效,其他类型均有效
albumEnable bool true 是否启用相册选择,默认:true(是)
backgroundColor string #000000 识别页面背景颜色,默认:#000000(黑色)
hintTextEnable bool true 是否显示底部文字提示,默认:true(是)
hintText string null 自定义底部提示文字内容,不填则使用插件默认文字提示
hintTextColor string #FFFFFF 提示文字颜色,默认:#FFFFFF(白色)
hintTextBackgroundColor string #000000 提示文字背景颜色,默认:#000000(黑色)
hintTextSize int 14 提示文字大小,默认:14px
templateSign string null 自定义模板ID
  • ocrType详细说明

    字段值 说明
    general 通用文字识别(含位置信息版)
    general_basic 通用文字识别
    accurate_basic 通用文字识别(高精度版)
    accurate 通用文字识别(含位置信息高精度版)
    general_enhanced 通用文字识别(含生僻字版),改服务已经停止,改用高精度版
    general_webimage 网络图片识别
    bankcard 银行卡识别
    bankcard_scan 银行卡扫描采集
    vehicle_license 行驶证识别
    driving_license 驾驶证识别
    license_plate 车牌识别
    business_license 营业执照识别
    receipt 通用票据识别
    passport 护照识别
    numbers 数字识别
    qrcode 二维码识别
    businesscard 名片识别
    lottery 彩票识别
    vatinvoice 增值税发票识别
    taxireceipt 出租车票
    vincode VIN码
    trainticket 火车票
    trip_ticket 行程单
    car_sell_invoice 机动车销售发票
    vihicle_sertification 车辆合格证
    example_doc_reg 试卷分析和识别
    written_text 手写文字识别
    hukou_page 户口本识别
    normal_machine_invoice 普通机打发票识别
    weight_note 磅单识别
    medical_detail 医疗费用明细识别
    online_taxi_itinerary 网约车行程单识别
    idcard_front 身份证正面拍照识别
    idcard_back 身份证反面拍照识别
    idcard_front_scan 身份证正面扫描(嵌入式质量控制+云端识别)
    idcard_back_scan 身份证反面扫描(嵌入式质量控制+云端识别)
    custom 自定义模板
  • 代码示例

    sealOcrModule.ocr(
        {
            // ak: '',
            // sk: '',
            ocrType,
            scaleWidth: 0.1,
            scaleHeight: 0.1,
            albumEnable: false
        },
        res => {
            uni.showModal({
                content: '获取识别结果:' + JSON.stringify(res)
            })
        }
    )
    复制代码
  • 接口回调结果状态码说明

    状态码 说明
    200 识别成功
    301 获取Token失败,请检查百度云应用包名配置、ak、sk是否一致
    302 获取Token失败,请检查百度云应用包名配置、license文件是否一致
    303 本地质量控制初始化错误
    304 百度ocr错误信息,包含错误码,可对照百度官方文档查阅
    1001 开始初始化SDK
    1002 SDK初始化完成
    1003 开始提取结果
    1004 提取结果完成

五、后续计划

  • IOS端支持

Guess you like

Origin juejin.im/post/7079373795865133063