更新记录
1.0.0(2023-09-26)
1、百度通用场景识别、网络图片识别、银行卡、身份证、行驶证、驾驶证、车牌、营业执照、菜单识别 2、仅支持Android,百度OCR Android SDK 2.0.1
平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:7.0 - 12.0 | armeabi-v7a:支持,arm64-v8a:支持,x86:支持 | × |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
接入前准备
1、Android证书,可以使用云端证书,参考文档 https://ask.dcloud.net.cn/article/35985#server
2、百度智能云账号(个人或企业),登录到控制台。
3、创建应用:勾选文字识别接口,文字识别HTTP SDK选择Android,填写应用包名和签名MD5
4、创建后点击应用管理,下载License文件,将下载的license文件放在应用目录nativePlugins/aibe-ocr-module/android/assets文件夹下
百度文字识别服务个人认证可领取1000次/月接口调用资源,企业认证可领取2000次/月接口调用资源,具体请查看官方文档说明:通用场景文字识别 - 文字识别OCR (baidu.com)
调用方法
引入插件
const aibeOcr = uni.requireNativePlugin('aibe-ocr-module')
初始化
aibeOcr.initAuth({}, res => {
uni.showToast({
title: '初始化成功'
})
})
识别调用
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
success: (res) => {
let path = plus.io.convertLocalFileSystemURL(res.tempFilePaths[0]);
let param = {
file: path,//图片路径
scene: this.scene,//识别场景
type: this.type,//识别类型
idCardSide: this.idCardSide,//身份证识别,front-人像面,back-国徽面
}
uni.showLoading({
title:'识别中...'
})
aibeOcr.identify(param, res2 => {
this.result = JSON.stringify(res2)
uni.hideLoading()
})
}
});
识别参数说明
参数名 | 是否必传 | 参数说明 |
---|---|---|
file | 是 | 图片路径,可以拍照或选择相册照片 |
scene | 是 | 识别场景,参数支持:通用场景(general),卡证识别(card),票证识别(receipt),菜单识别(menu) |
type | 否,卡证识别必传 | 识别类型,通用场景:标准版不传,高精度版(accurate),含位置版(position),高精度含位置(accuratePosition),网络图片(webimage); 卡证识别:银行卡(bankCard),身份证(idcard),行驶证(vehicle),驾驶证(driving),车牌(licensePlate),营业执照(businessLicense); 票证识别:不传; 菜单识别:不传 |
idCardSide | 否,身份证识别必传 | 身份证人像面(front),身份证国徽面(back) |
//示例代码
<template>
<view class="content">
<view style="margin-bottom: 10rpx;">识别场景:</view>
<view>
<radio-group @change="scenesChange">
<label v-for="(item, index) in scenes" :key="item.value">
<text style="margin-right: 30rpx;">
<radio :value="item.value" :checked="index === current" style="transform:scale(0.7)"/>{{item.name}}
</text>
</label>
</radio-group>
</view>
<view style="margin: 20rpx 0 10rpx 0;border-top: 1px solid #f1f1f1;padding-top: 20rpx;">识别类型:</view>
<view>
<radio-group @change="typeChange">
<label v-for="(item, index) in scenes[current].types" :key="item.value">
<text style="margin-right: 30rpx;">
<radio :value="item.value" :checked="index === typecur" style="transform:scale(0.7)"/>{{item.name}}
</text>
</label>
</radio-group>
</view>
<button type="primary" @click="identify" style="margin-top: 50rpx;">选择图片</button>
<view style="margin-top: 50rpx;width: 100%;word-wrap: break-word;word-break: normal;">{{result}}</view>
</view>
</template>
<script>
const aibeOcr = uni.requireNativePlugin('aibe-ocr-module')
export default {
data() {
return {
result:'',
scene:'general',//识别场景
type:'',//识别类型
idCardSide:'',
scenes:[
{name:'通用场景',value:'general',types:[
{name:'高精度版',value:'accurate'},
{name:'含位置版',value:'position'},
{name:'高精度含位置',value:'accuratePosition'},
{name:'网络图片',value:'webimage'}
]},
{name:'卡证识别',value:'card',types:[
{name:'银行卡',value:'bankCard'},
{name:'身份证-人像',value:'idcard-front'},
{name:'身份证-国徽',value:'idcard-back'},
{name:'行驶证',value:'vehicle'},
{name:'驾驶证',value:'driving'},
{name:'车牌',value:'licensePlate'},
{name:'营业执照',value:'businessLicense'}
]},
{name:'票证识别',value:'receipt'},
{name:'菜单识别',value:'menu'}
],
current: 0,
typecur: ''
}
},
onLoad() {
aibeOcr.initAuth({}, res => {
uni.showToast({
title: '初始化成功'
})
})
},
methods: {
identify(){
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
success: (res) => {
let path = plus.io.convertLocalFileSystemURL(res.tempFilePaths[0]);
let param = {
file: path,
scene: this.scene,
type: this.type,
idCardSide: this.idCardSide
}
uni.showLoading({
title:'识别中...'
})
aibeOcr.identify(param, res2 => {
this.result = JSON.stringify(res2)
uni.hideLoading()
})
}
});
},
//场景改变
scenesChange(e){
let index = this.scenes.findIndex(item => item.value == e.detail.value)
this.current = index
this.scene = e.detail.value
},
//类型改变
typeChange(e){
if(e.detail.value.indexOf('idcard') != -1){
let arr = e.detail.value.split('-')
this.type = arr[0]
this.idCardSide = arr[1]
}else{
this.type = e.detail.value
this.idCardSide = ''
}
}
}
}
</script>
<style scoped lang="scss">
.content{
padding: 20rpx;
}
</style>