Repository navigation
Conversation
…essing PP-OCRv6 recognition is trained with BGR images (DecodeImage img_mode: BGR in configs/rec/PP-OCRv6/*.yml), but the Android RecPreprocessor unconditionally converted each crop with Imgproc.COLOR_BGR2RGB before inference, feeding the model a channel order it never saw in training. Drop the conversion so crops stay in BGR, matching the training pipeline. The detection preprocessor already gates its BGR->RGB conversion behind an imgMode switch; recognition had no such switch and no way to opt out.
This branch has not been deployed
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.
Fixes #18380.
Problem
PP-OCRv6 recognition is trained with BGR images (
DecodeImage: img_mode: BGRinconfigs/rec/PP-OCRv6/PP-OCRv6_small_rec.yml), but the AndroidRecPreprocessorunconditionally converts every crop withImgproc.COLOR_BGR2RGBbefore inference:The model therefore receives RGB crops at inference while it was trained on BGR — a channel-order mismatch that degrades recognition accuracy.
Why the detection path is not affected
DetPreprocessorgates its BGR→RGB conversion behind animgModeswitch (if (imgMode.uppercase() == "RGB")), so BGR-trained models can opt out.RecPreprocessor.preprocessBatch()has no such switch and is called unconditionally byRecognitionEngine— there is no way to keep BGR.Change
Keep crops in BGR: remove the unconditional
COLOR_BGR2RGBconversion (and its temporary Mat), resizing the crop directly. Channel-order-agnostic steps (resize,/127.5 - 1normalization, CHW packing) are unchanged.Verification
configs/rec/PP-OCRv6/*.yml, allimg_mode: BGR) and the Android inference pipeline (RecognitionEngine→RecPreprocessor.preprocessBatch).Mat/Imgproc.resizeimports remain in use.