Add optional rotate_pages and deskew parameters to OCR endpoint#132
Merged
gabriel-piles merged 4 commits intohuridocs:mainfrom Mar 2, 2026
Merged
Conversation
Member
|
Thank you for your contribution. We will review the code and will likely merge it next week. Best |
Member
|
I'm going to push a few small tweaks to speed this up, hope you don't mind! |
Member
|
We are merging it |
|
Very cool @NataliaVillegasC ! |
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.
Problem
When processing scanned PDFs with misrotated or skewed pages, the OCR output was producing incorrect text (gibberish). This is a known limitation when pages are not properly oriented before OCR is applied.
Solution
While reviewing the OCRmyPDF documentation (https://github.com/ocrmypdf/OCRmyPDF), I found two flags that address this:
--rotate-pages: automatically detects and fixes misrotated pages--deskew: straightens crooked/skewed scanned pagesBoth flags have been supported by OCRmyPDF for a long time and are compatible with the version used in this project.
These parameters are optional and default to false to avoid adding latency for users who don't need them.
Changes
src/adapters/infrastructure/ocr_service_adapter.py: addedrotate_pagesanddeskewoptional parameters toprocess_pdf_ocrsrc/ports/services/ocr_service.py: updated abstract method signaturesrc/use_cases/ocr/process_ocr_use_case.py: propagated parameters through the use casesrc/drivers/rest/app.py: addedrotate_pagesanddeskewform parameters to the/ocrendpointREADME.md: updated/ocrendpoint documentation with new parameters and usage examplesTesting
Tested locally with a scanned PDF with rotated pages — OCR output went from garbled text to correctly extracted content after enabling
rotate_pages=true.