Add Custom OpenCV and ONNX Runtime Builds and OCR performance optimization - #57
Open
283375 wants to merge 26 commits into
Open
Add Custom OpenCV and ONNX Runtime Builds and OCR performance optimization#57283375 wants to merge 26 commits into
283375 wants to merge 26 commits into
Conversation
- delete OcrDigits.kt (HOG feature extraction + findNearest helpers) - remove kNearestModel parameter from DeviceOcr constructor - remove pfl/pure/far/lost/score/maxRecall methods (dead code since ONNX migration) - remove FixRects (only used by removed KNN digit pipeline)
- remove kNearestModel parameter from DeviceOcrHelper.ocrImage - stop loading KNN model in OcrQueueOcrImageTaskExecutor and OcrFromShareViewModel.startOcr
- drop kNearestModel() loaders, KNearestModelStatusDetail and status builder - remove knnModelFile path constant and its deletion in emergency mode - add LegacyKnnModelCleanUpTask to clean up leftover digits.knn.dat on devices that installed before the removal
- delete OcrDependencyKNearestModelStatusViewer (status card + ui state) - remove KNearest status cards from OcrNavEntry, OcrFromShare card and OcrDependenciesScreen - remove importKNearestModel and related state from OcrDependenciesScreenViewModel
- delete ocr_dependency_knn_model strings (app + shared composeResources, zh-rCN) - delete ic_knearest_model drawable
- OpenCV 5.0 removes ml (KNearest) and HOG from the main repo; both were already removed from this codebase, so no migration needed - usage limited to stable core/imgproc/imgcodecs/android APIs, verified by Android Studio build (no problems)
Database version jumped from 2 to 4 in 80139db; version 3 was never published, but the AutoMigration was generated against a fictional 3.json (enqueue_buffer with uri_type column) which crashes on real v2 databases (no such column: uri_type). Remove the AutoMigration and the spec; old databases now hit the existing fallbackToDestructiveMigration(dropAllTables = true) path and are rebuilt cleanly as v4.
Switch to the local maven repo (maven-local/) that overrides official onnxruntime 1.26.0 and opencv 5.0.0 with custom-built AARs. Parse dual-block model_info.json for the dependency status card instead of OnnxModelMetadata, disable graph optimization (NO_OPT) for the reduced-op runtime, and read INT32 model output directly.
Add setup-custom-maven action that downloads maven_repo.zip from the custom-lib-builds stable release tags (onnxruntime-1.26.0, opencv-5.0.0) into maven-local/, overriding official artifacts with identical GAV. Wire it into build_unstable, check, and connected-android-test workflows. No cache: stable tags are overwritten on publish (URL stable, content changes), so version-based cache keys would serve stale artifacts.
Compare .so sha256 between maven-local/ AARs and built APKs, guarding against silent fallback to official onnxruntime/opencv artifacts. Warnings go to annotations and the job summary; continue-on-error keeps artifact upload and release drafting unblocked.
Move the download/extract logic out of the composite action and the apksigner checks out of the workflow, so both are runnable and testable locally. setup-custom-maven and verify-apk-signing keep hard-fail semantics; verify-custom-libs remains soft-fail. Cleaned up shellcheck findings along the way.
- Previous commit was mislead, this commit actually just fixes it.
283375
commented
Aug 18, 2026
Comment on lines
+24
to
+31
| val parallelCount: Int = defaultParallelCount(), | ||
| ) { | ||
| companion object { | ||
| fun defaultParallelCount(): Int = (Runtime.getRuntime().availableProcessors() / 2).coerceAtLeast(1) | ||
|
|
||
| fun parallelCountRange(): IntRange = 1..(Runtime.getRuntime().availableProcessors() * 2).coerceAtLeast(2) | ||
| } | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
Is it appropriate to put this "single source" in a datastore-related object?
283375
commented
Aug 18, 2026
Comment on lines
+91
to
+100
| /** | ||
| * Lightweight sanity check for the bundled model asset. Does not load or | ||
| * validate the model itself (a truncated file still passes); use | ||
| * [createOrtSession] for a full check. | ||
| */ | ||
| fun checkModelAsset(context: Context) { | ||
| context.assets.open(MODEL_ASSET_PATH).use { stream -> | ||
| if (stream.read(ByteArray(1)) == -1) throw IOException("OCR model asset is empty: $MODEL_ASSET_PATH") | ||
| } | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
How about comparing the version info in model metadata (and probably other lightweight fields) to improve accuracy?
283375
commented
Aug 18, 2026
Collaborator
Author
There was a problem hiding this comment.
Consider the file location. Now the import name for Mat.use is import xyz.sevive.arcaeaoffline.core.ocr.use, which might not clear or readable.
283375
commented
Aug 18, 2026
283375
left a comment
Collaborator
Author
There was a problem hiding this comment.
Needs further investigations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hammingDistanceis now allocation-free in image hash lookups, previous zip-based version caused severe GC pressure. Now queue throughput is roughly doubled