- Global - 全局对象
- Automator - 自动化
- AutoJs6 - 本体应用
- App - 通用应用
- Color - 颜色
- Image - 图像
- OCR - 光学字符识别
- Keys - 按键
- Device - 设备
- Storage - 储存
- File - 文件
- Engine - 引擎
- Task - 任务
- Module - 模块
- Plugins - 插件
- Toast - 消息浮动框
- Notice - 消息通知
- Console - 控制台
- Shell
- Media - 多媒体
- Sensor - 传感器
- Recorder - 记录器
- Timer - 定时器
- Thread - 线程
- Continuation - 协程
- Event - 事件监听
- Dialog - 对话框
- Floaty - 悬浮窗
- Canvas - 画布
- UI - 用户界面
- Web - 万维网
- HTTP
- Base64
- Crypto - 密文
- Internationalization - 国际化
- Standardization - 标准化
- E4X
- UiSelector - 选择器
- UiObject - 控件节点
- UiObjectCollection - 控件集合
- UiObjectActions - 控件节点行为
- ImageWrapper - 包装图像类
- App - 应用枚举类
- Color - 颜色类
- Version - 版本工具类
- Polyfill - 代码填泥
- Arrayx - Array 扩展
- Numberx - Number 扩展
- Mathx - Math 扩展
- Glossaries - 术语
- HttpHeader - HTTP 标头
- HttpRequestMethods - HTTP 请求方法
- MimeType - MIME 类型
- NotificationChannel - 通知渠道
- Data Types - 数据类型
- Omnipotent Types - 全能类型
- Storage - 存储类
- AndroidBundle
- AndroidRect
- CryptoCipherOptions
- CryptoKey
- CryptoKeyPair
- ConsoleBuildOptions
- HttpRequestBuilderOptions
- HttpRequestHeaders
- HttpResponseBody
- HttpResponseHeaders
- HttpResponse
- InjectableWebClient
- InjectableWebView
- NoticeOptions
- NoticeChannelOptions
- NoticePresetConfiguration
- NoticeBuilder
- Okhttp3HttpUrl
- OcrOptions
- Okhttp3Request
- OpencvPoint
- OpencvRect
- OpencvSize
AutoJs6 文档 - 6.3.3
光学字符识别 (OCR)#
ocr 模块用于识别图像中的文本.
AutoJs6 的 OCR 特性是基于 Google ML Kit 的 文字识别 API 实现的.
ocr
[@] ocr#
ocr 可作为全局对象使用:
typeof ocr; // "function"
typeof ocr.detect; // "function"
typeof ocr.recognizeText; // "function"
ocr(img, options?)#
6.3.0 Overload [1-2]/6
- img { ImageWrapper } - 包装图像对象
- [ options ] { OcrOptions } - OCR 识别选项
- returns { string[] }
识别图像包含的所有文本, 返回文本数组.
ocr.recognizeText(img, options?) 的别名方法.
/* 申请屏幕截图权限. */
images.requestScreenCapture();
/* 截屏并获取包装图像对象. */
let img = images.captureScreen();
/* OCR 识别并获取结果, 结果为字符串数组. */
let results = ocr(img);
/* 结果过滤, 筛选出文本中可部分匹配 "app" 的结果, 如 "apple", "disappear" 等. */
results.filter(text => text.includes('app'));
ocr(img, region)#
6.3.0 Overload 3/6
- img { ImageWrapper } - 包装图像对象
- region { OmniRegion } - OCR 识别区域
- returns { string[] }
识别指定区域内图像包含的所有文本, 返回文本数组.
ocr(img, { region: region }) 的便捷方法.
ocr.recognizeText(img, region) 的别名方法.
/* 申请屏幕截图权限. */
images.requestScreenCapture();
/* 截屏并获取包装图像对象. */
let img = images.captureScreen();
/* 在区域 [ 0, 0, 100, 150 ] 内进行 OCR 识别并获取结果, 结果为字符串数组. */
let results = ocr(img, [ 0, 0, 100, 150 ]);
/* 结果过滤, 筛选出文本中可部分匹配 "app" 的结果, 如 "apple", "disappear" 等. */
results.filter(text => text.includes('app'));
关于 OCR 区域参数 region 的更多用法, 参阅 OcrOptions#region 小节.
ocr(imgPath, options?)#
6.3.0 Overload [4-5]/6
- imgPath { string } - 图像路径
- [ options ] { OcrOptions } - OCR 识别选项
- returns { string[] }
识别指定路径对应图像包含的所有文本, 返回文本数组.
当指定路径无法解析为包装图像对象时, 将抛出 TypeError 异常.
ocr.recognizeText(imgPath, options?) 的别名方法.
ocr('./picture.jpg'); /* 获取本地图像文件中的所有文本. */
ocr(imgPath, region)#
6.3.0 Overload 6/6
- imgPath { string } - 图像路径
- region { OmniRegion } - OCR 识别区域
- returns { string[] }
识别指定路径对应图像在指定区域内包含的所有文本, 返回文本数组.
当指定路径无法解析为包装图像对象时, 将抛出 TypeError 异常.
ocr(imgPath, { region: region }) 的便捷方法.
ocr.recognizeText(imgPath, region) 的别名方法.
/* 获取本地图像文件在区域 [ 0, 0, 100, 150 ] 内的所有文本. */
ocr('./picture.jpg', [ 0, 0, 100, 150 ]);
关于 OCR 区域参数 region 的更多用法, 参阅 OcrOptions#region 小节.
[m] recognizeText#
recognizeText(img, options?)#
6.3.0 Overload [1-2]/6
- img { ImageWrapper } - 包装图像对象
- [ options ] { OcrOptions } - OCR 识别选项
- returns { string[] }
识别图像包含的所有文本, 返回文本数组.
ocr.recognizeText(img, options?) 与 ocr(img, options?) 等价.
images.requestScreenCapture(); /* 申请屏幕截图权限. */
let img = images.captureScreen(); /* 截屏并获取包装图像对象. */
ocr.recognizeText(img).filter(text => text.includes('app')); /* 过滤结果. */
recognizeText(img, region)#
6.3.0 Overload 3/6
- img { ImageWrapper } - 包装图像对象
- region { OmniRegion } - OCR 识别区域
- returns { string[] }
识别指定区域内图像包含的所有文本, 返回文本数组.
ocr.recognizeText(img, { region: region }) 的便捷方法.
ocr.recognizeText(img, region) 与 ocr(img, region) 等价.
images.requestScreenCapture(); /* 申请屏幕截图权限. */
let img = images.captureScreen(); /* 截屏并获取包装图像对象. */
ocr.recognizeText(img, [ 0, 0, 100, 150 ]).filter(text => text.includes('app')); /* 过滤结果. */
关于 OCR 区域参数 region 的更多用法, 参阅 OcrOptions#region 小节.
recognizeText(imgPath, options?)#
6.3.0 Overload [4-5]/6
- imgPath { string } - 图像路径
- [ options ] { OcrOptions } - OCR 识别选项
- returns { string[] }
识别指定路径对应图像包含的所有文本, 返回文本数组.
当指定路径无法解析为包装图像对象时, 将抛出 TypeError 异常.
ocr.recognizeText(imgPath, options?) 与 ocr(imgPath, options?) 等价.
ocr.recognizeText('./picture.jpg'); /* 获取本地图像文件中的所有文本. */
recognizeText(imgPath, region)#
6.3.0 Overload 6/6
- imgPath { string } - 图像路径
- region { OmniRegion } - OCR 识别区域
- returns { string[] }
识别指定路径对应图像在指定区域内包含的所有文本, 返回文本数组.
当指定路径无法解析为包装图像对象时, 将抛出 TypeError 异常.
ocr.recognizeText(imgPath, { region: region }) 的便捷方法.
ocr.recognizeText(imgPath, region) 与 ocr(imgPath, region) 等价.
/* 获取本地图像文件在区域 [ 0, 0, 100, 150 ] 内的所有文本. */
ocr.recognizeText('./picture.jpg', [ 0, 0, 100, 150 ]);
关于 OCR 区域参数 region 的更多用法, 参阅 OcrOptions#region 小节.
[m] detect#
detect(img, options?)#
6.3.0 Overload [1-2]/6
- img { ImageWrapper } - 包装图像对象
- [ options ] { OcrOptions } - OCR 识别选项
- returns { OcrResult[] }
识别图像包含的所有文本, 返回 OcrResult 数组.
/* 申请屏幕截图权限. */
images.requestScreenCapture();
/* 截屏并获取包装图像对象. */
let img = images.captureScreen();
/* 获取本地图像文件中的所有识别结果. */
let result = ocr.detect(img);
/* 筛选置信度高于 0.8 的结果. */
result.filter(o => o.confidence >= 0.8);
detect(img, region)#
6.3.0 Overload 3/6
- img { ImageWrapper } - 包装图像对象
- region { OmniRegion } - OCR 识别区域
- returns { OcrResult[] }
识别指定路径对应图像在指定区域内包含的所有文本, 返回 OcrResult 数组.
ocr.detect(img, { region: region }) 的便捷方法.
/* 申请屏幕截图权限. */
images.requestScreenCapture();
/* 截屏并获取包装图像对象. */
let img = images.captureScreen();
/* 获取本地图像文件在区域 [ 0, 0, 100, 150 ] 内的所有识别结果. */
let result = ocr.detect(img, [ 0, 0, 100, 150 ]);
/* 筛选置信度高于 0.8 的结果. */
result.filter(o => o.confidence >= 0.8);
关于 OCR 区域参数 region 的更多用法, 参阅 OcrOptions#region 小节.
detect(imgPath, options?)#
6.3.0 Overload [4-5]/6
- imgPath { string } - 图像路径
- [ options ] { OcrOptions } - OCR 识别选项
- returns { OcrResult[] }
识别指定路径对应图像包含的所有文本, 返回 OcrResult 数组.
当指定路径无法解析为包装图像对象时, 将抛出 TypeError 异常.
let result = ocr.detect('./picture.jpg'); /* 获取本地图像文件中的所有识别结果. */
result.filter(o => o.confidence >= 0.8); /* 筛选置信度高于 0.8 的结果. */
detect(imgPath, region)#
6.3.0 Overload 6/6
- imgPath { string } - 图像路径
- region { OmniRegion } - OCR 识别区域
- returns { OcrResult[] }
识别指定路径对应图像在指定区域内包含的所有文本, 返回 OcrResult 数组.
当指定路径无法解析为包装图像对象时, 将抛出 TypeError 异常.
ocr.detect(imgPath, { region: region }) 的便捷方法.
/* 获取本地图像文件在区域 [ 0, 0, 100, 150 ] 内的所有识别结果. */
let result = ocr.detect('./picture.jpg', [ 0, 0, 100, 150 ]);
/* 筛选置信度高于 0.8 的结果. */
result.filter(o => o.confidence >= 0.8);
关于 OCR 区域参数 region 的更多用法, 参阅 OcrOptions#region 小节.