更新记录
1.0.0(2025-09-13)
把所有的原生代码,改造为UTS插件。
平台兼容性
uni-app(3.6.9)
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
× |
× |
× |
× |
× |
- |
10.0 |
× |
× |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
× |
其他
zero-baiduocr-offline-sdk-text
开发文档
UTS 语法
UTS API插件
UTS uni-app兼容模式组件
UTS 标准模式组件
Hello UTS
使用文档
<template>
<view>
<view>
<button @tap="auth">鉴权:</button>
<button @tap="initClient">初始化客户端:</button>
<button @tap="runWithCamera">拍照文字识别</button>
<button @tap="runWithAlbum">选择相册文字识别</button>
</view>
<view>
<text class="btn-view">鉴权结果{{authResult}}</text>
<text class="btn-view">客户端结果{{ocrClient}}</text>
<text class="btn-view">从拍照或者相册中识别的结果</text>
<text>{{result}}</text>
</view>
</view>
</template>
<script>
import { OCRRunOptions, initLicenseOnlineMany, initOCRClient, ocrRun } from "@/uni_modules/zero-baiduocr-offline-sdk-text"
export default {
data() {
return {
authResult: false,
ocrClient: false,
result: [] as Array<string>
}
},
onLoad() {
},
methods: {
// 鉴权
auth() {
initLicenseOnlineMany("您在百度通用文字识别申请到的KEY", (result : boolean) => {
this.authResult = result
})
},
initClient() {
initOCRClient((clientResult : boolean) => {
this.ocrClient = clientResult
})
},
run(sourceType : "album" | "camera" = "album") {
uni.chooseMedia({
mediaType: ["image"],
sourceType: [sourceType],
count: 1,
success: (res) => this.startOCR(res)
})
},
runWithCamera() {
this.run("camera")
},
runWithAlbum() {
this.run("album")
},
startOCR(res : ChooseMediaSuccess) {
let tempFilePath = res.tempFiles[0].tempFilePath
let query : OCRRunOptions = {
imageFilePath: tempFilePath, // 图片文件
isSingleWord: true, // 是不是单字节,一般是的,也就是识别的时候一个字一个字的识别,
engGranularity: 0, // 英文识别粒度(按0字母 or 1按单词)0代表LETTER, 1代表WORD
directionCheck: true, // 是否让程序自动识别纸张的方向,默认是true为好
languageType: 0, // 语言类型 (0代表简体中文 + 繁体中文 + 英文, 1代表英语 + 欧洲 17 种语言,) 0代表CHN_ENG, 1代表EURO18
detectHand: true // 是否启用手写体识别,一般传true
}
ocrRun(query, OCRRunResult => {
this.result = OCRRunResult.lines
})
}
}
}
</script>
<style>
.btn-view {
font-size: 30px;
}
</style>