Skip to content

fix(ocr): make UVDoc output C-contiguous - #5179

Open
1443858742 wants to merge 1 commit into
PaddlePaddle:developfrom
1443858742:agent/uvdoc-contiguous-output
Open

fix(ocr): make UVDoc output C-contiguous#5179
1443858742 wants to merge 1 commit into
PaddlePaddle:developfrom
1443858742:agent/uvdoc-contiguous-output

Conversation

@1443858742

Copy link
Copy Markdown

What

  • make the UVDoc RGB-to-BGR output C-contiguous at the document-preprocessor boundary
  • add CPU-only regression tests for pixel equivalence and memory layout

Why

The current channel reversal returns a NumPy view with a negative channel
stride. The OCR pipeline then passes the full page to cv2.warpPerspective
once per detected text region. OpenCV has to handle the incompatible layout
for every crop, which makes region cropping dominate OCR latency on
text-dense pages.

Converting the page once with np.ascontiguousarray preserves the current
BGR pixels while avoiding repeated downstream layout conversion.

Fixes #5178.

Validation

  • pytest -q tests/test_doc_preprocessor_pipeline.py: 4 passed
  • repository pre-commit hooks on both changed files: passed
  • tests cover contiguous, sliced, transposed, and read-only inputs
  • output pixels equal the previous expression
  • output is writable, C_CONTIGUOUS=True, and has no negative strides

A deterministic synthetic 1600x1132 image with 200 perspective crops
measured:

Input layout Crop p50
negative channel stride 1.664214s
C-contiguous 0.021812s

In a separate 20-run warm OCR check on two text-dense pages, normalized OCR
output remained identical and end-to-end p50 changed from 1.330s to
0.537s and from 3.209s to 1.172s.

No private images or OCR text are included in this pull request.

Compatibility

There is no public API or model-behavior change. The no-unwarping path is
unchanged. If appropriate, this fix can also be backported to release/3.7.

@paddle-bot

paddle-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown

Thanks for your contribution!

@CLAassistant

CLAassistant commented Jul 26, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@paddle-bot paddle-bot Bot added the contributor External developers label Jul 26, 2026
@1443858742
1443858742 force-pushed the agent/uvdoc-contiguous-output branch from 2a6b3f6 to 25509fb Compare July 26, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants