更新记录
0.0.1(2025-03-13)
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 4.54,Android:支持,iOS:支持,HarmonyNext:不确定 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
lime-ocr
提供文字识别功能,支持多语言识别和结构化结果返回
文档
ocr
安装
插件市场导入,在页面上引入,然后自定义基座
使用
import { recognizeImage, type OCRRecognizeOptions } from '@/uni_modules/lime-ocr'
const onClick = () => {
recognizeImage({
// language: 'zh',
url: '/static/ocr/QQ20250312-231846.png', // 支持临时地址,缓存地址。如果是网络地址请先下载。
success(res) {
console.log('res', res.text)
// console.log('textBlocks', res.textBlocks)
},
fail(err) {
console.log('err', err)
}
} as OCRRecognizeOptions)
}
方法列表
异步识别方法
recognizeImage(options: OCRRecognizeOptions): void
参数说明
参数名 |
类型 |
必填 |
说明 |
url |
string |
是 |
要识别的图片URL |
language |
'zh'|'ja'|'ko'|'devanagari' |
否 |
识别语言类型,默认中文 |
success |
function |
否 |
识别成功的回调函数 |
fail |
function |
否 |
识别失败的回调函数 |
数据结构
OCRResult
字段 |
类型 |
说明 |
text |
string |
合并后的完整识别文本 |
textBlocks |
TextBlock[] |
结构化识别结果(多级结构) |
errMsg |
string |
结果状态信息 |
错误码说明
错误码 |
说明 |
9010001 |
图片加载失败 |
9010002 |
文字识别失败 |
9010003 |
不支持的语言类型 |
9010004 |
路径不存在 |
回调函数示例
成功回调结构:
(res: OCRResult) => {
text: "完整识别文本",
textBlocks: [{
text: "段落文本",
lines: [{
text: "行文本",
elements: [{
text: "单词",
bounds: { left: 0, top: 0, right: 100, bottom: 50 }
}]
}]
}]
}