镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Fix repeated OCR crop conversion after table rotation - #5228

Open
MRNAQA wants to merge 1 commit into
PaddlePaddle:developfrom
MRNAQA:fix/5178-contiguous-table-rotation
Open

MRNAQA wants to merge 1 commit into
PaddlePaddle:developfrom
MRNAQA:fix/5178-contiguous-table-rotation

Conversation

@MRNAQA

@MRNAQA MRNAQA commented Oct 18, 2026

Copy link
Copy Markdown

What

Make the rotated page C-contiguous before OCR in both table-orientation paths in pipeline_v2.py: whole-page tables and layout-detected tables. Covers 90, 180, and 270 degrees.

Why

np.rot90 returns a view. Passing that non-contiguous page to the OCR crop loop makes OpenCV convert the full page for each text box. Normalize once after choosing the rotation, before OCR, preserving orientation and pixels.

Related to #5178 and complements #5179, which covers the UVDoc producer.

Direction: correct the page-producing boundary before repeated crops; keep table orientation and OCR behavior.

Common practice: follows NumPy's rotated-view contract and contiguous conversion, using the same boundary correction as #5179.

Correction: refactor.

Cut: repeated downstream conversion of the rotated page; no code removed.

Add: one np.ascontiguousarray call in each rotated-page path, before OCR.

Validation

  • Repository pre-commit hooks on the changed file: passed, including Black 24.4.2, Flake8 7.0.0, isort 5.12.0, license, import, and Python 3.8 checks.
  • Executed each added normalization statement with synthetic arrays for k=1/2/3: both paths produce contiguous pages with identical page and perspective-crop pixels.
  • Changed source compiles. No model inference or full OCR test was run for this PR.

Gain: the synthetic reproduction already posted on #5178 measured median crop time from 81.967041 ms to 0.203834 ms, with identical crop pixels (402.1x). It uses a seeded random 5600×4000×3 uint8 page, a 500×40 crop, five warmups, and 30 interleaved samples per layout. The one-time page conversion cost was 82.709770 ms, excluded from crop timing. Only k=1 was timed; this is not an end-to-end OCR speedup claim.

Benchmark environment: macOS 27.0 arm64, Python 3.12.13, NumPy 2.3.5, opencv-python-headless 4.10.0.84. The script requests one OpenCV thread; the build reports 18.

Test plan

Reproduction and pixel checks are described above. For model-level validation, run table recognition on a generated turned-table page at 90, 180, and 270 degrees, with and without layout detection, and compare crop pixels and OCR results against the base revision.

Compatibility

No public API, rotation, or model configuration changes. The zero-degree path is unchanged.

@CLAassistant

CLAassistant commented Oct 18, 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants