Skip to content

fix(android): keep BGR channel order in PP-OCRv6 recognition preprocessing - #18384

Open
KaiyiQuan wants to merge 1 commit into
PaddlePaddle:mainfrom
KaiyiQuan:fix/18380-android-rec-bgr-channel
Open

KaiyiQuan wants to merge 1 commit into
PaddlePaddle:mainfrom
KaiyiQuan:fix/18380-android-rec-bgr-channel

Conversation

@KaiyiQuan

Copy link
Copy Markdown

Fixes #18380.

Problem

PP-OCRv6 recognition is trained with BGR images (DecodeImage: img_mode: BGR in configs/rec/PP-OCRv6/PP-OCRv6_small_rec.yml), but the Android RecPreprocessor unconditionally converts every crop with Imgproc.COLOR_BGR2RGB before inference:

Imgproc.cvtColor(crop, rgb, Imgproc.COLOR_BGR2RGB)  // then resize + normalize

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

DetPreprocessor gates its BGR→RGB conversion behind an imgMode switch (if (imgMode.uppercase() == "RGB")), so BGR-trained models can opt out. RecPreprocessor.preprocessBatch() has no such switch and is called unconditionally by RecognitionEngine — there is no way to keep BGR.

Change

Keep crops in BGR: remove the unconditional COLOR_BGR2RGB conversion (and its temporary Mat), resizing the crop directly. Channel-order-agnostic steps (resize, /127.5 - 1 normalization, CHW packing) are unchanged.

Verification

  • Diff reviewed against the training configs (configs/rec/PP-OCRv6/*.yml, all img_mode: BGR) and the Android inference pipeline (RecognitionEngine → RecPreprocessor.preprocessBatch).
  • No leftover references to the removed temporary; Mat/Imgproc.resize imports remain in use.

…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.
Copilot AI balanced review requested due to automatic review settings October 2, 2026 07:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@CLAassistant

CLAassistant commented Oct 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BGR/RGB mismatch in PP-OCRv6 Android recog preprocessing

3 participants