# OnnxOCRAndroid **Repository Path**: lincyang/onnxocr-android ## Basic Information - **Project Name**: OnnxOCRAndroid - **Description**: OnnxOCR的安卓版本 - **Primary Language**: Android - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-14 - **Last Updated**: 2026-08-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OnnxOCR Android 基于 [OnnxOCRSharp](https://github.com/lincyang/OnnxOCRSharp) 移植的 Android OCR 引擎,默认使用 **PP-OCRv6 tiny** ONNX 模型。 ## 项目结构 ``` onnxocr-android/ ├── app/ # Demo 应用 │ └── src/main/ │ └── assets/models/ppocrv6_tiny/ ├── onnxocr-core/ # OCR 核心类库(AAR) │ └── src/main/java/com/linc/onnxocr/ │ ├── config/ # 配置类(v6 默认参数) │ ├── detection/ # 检测模块 │ ├── recognition/ # 识别模块 │ ├── imaging/ # 图像处理 │ ├── inference/ # ONNX 推理 │ ├── model/ # 数据模型 │ └── pipeline/ # 核心管线 ├── README.md └── LICENSE ``` ## 环境要求 - Android Studio Hedgehog (2023.1.1) 或更新版本 - Gradle 8.5 - Kotlin 1.9.20 - Android SDK 34 - minSdk 24 ## 快速开始 ### 1. 模型文件 Demo 已包含 PP-OCRv6 tiny 资源,布局如下: ``` app/src/main/assets/models/ppocrv6_tiny/ ├── det/det.onnx ├── rec/rec.onnx └── ppocrv6_tiny_dict.txt ``` 首次运行时会复制到应用 `filesDir`。自定义模型时传入对应绝对路径即可。 ### 2. 构建运行 1. 打开 Android Studio 2. 导入项目 `onnxocr-android/` 3. 等待 Gradle 同步完成 4. 运行 `app` 模块 ## API 使用 ```kotlin // 创建配置(默认即为 PP-OCRv6:det limit_type=min, side=736) val options = OcrOptions.createDefault(context) // 或手动指定路径: // val options = OcrOptions( // detModelPath = "path/to/det.onnx", // recModelPath = "path/to/rec.onnx", // dictPath = "path/to/ppocrv6_tiny_dict.txt" // ) val textSystem = TextSystem(context, options) val mat = Mat() // OpenCV BGR / RGBA Mat val result = textSystem.run(mat) for (line in result.lines) { println("Text: ${line.text}, Score: ${line.score}") } textSystem.close() ``` ### PP-OCRv6 关键默认参数 与 OnnxOCRSharp `ApplyPpOcrV6Defaults` 对齐: | 参数 | 默认值 | |------|--------| | `detLimitType` | `"min"` | | `detLimitSideLen` | `736` | | `detMaxSideLimit` | `4000` | | `detDbThresh` | `0.2` | | `detDbBoxThresh` | `0.4` | | `detDbUnclipRatio` | `1.4` | | `detDbMaxCandidates` | `3000` | | `recImageShape` | `"3, 48, 320"` | ## 核心类说明 | 类名 | 说明 | |------|------| | `TextSystem` | 核心管线控制器,协调检测和识别 | | `TextDetector` | 文本检测模块 | | `TextRecognizer` | 文本识别模块 | | `OcrOptions` | 配置类 | | `OcrResult` | 识别结果 | ## 许可证 ``` Copyright 2026 程序员Linc Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` ## 公众号 欢迎关注我的公众号 **程序员Linc**,获取更多技术分享! ## 上游项目 本项目基于以下开源项目开发: - [OnnxOCRSharp](https://github.com/lincyang/OnnxOCRSharp) - [OnnxOCR](https://github.com/jingsongliujing/OnnxOCR)