Phone-shot document is oriented wrong; process EXIF first, then send to OCR
The contract photo on my phone looks portrait, but after uploading it appears sideways. The cause may be that the pixels themselves are not rotated, and the viewer only adjusts the display based on the EXIF orientation tag. If the OCR input ignores this tag, it will read the page in a different orientation.
Key Points of This Article
- Phone photos may appear in the wrong orientation because the pixels are not rotated; only the EXIF orientation tag is applied by the viewer.
- If OCR input ignores the EXIF orientation tag, it may read page content in a different orientation.
- Pillow's ImageOps.exif_transpose applies the orientation information and removes the tag, but it does not handle tilt or perspective distortion from shooting angle.
- Tilt, trapezoidal distortion, and a missing orientation tag must be judged separately and should not be conflated.
- Boxes returned by OCR on the adjusted image should be saved with the input dimensions and transformation information, and an inverse transformation should be applied when displaying them back on the original image.
Phone photos of contracts look vertical in the album, but after uploading they turn sideways, and many people assume the photo was taken crooked or the file is damaged. This article is for anyone who needs to send phone photos into an OCR or translation workflow, and helps you tell apart "display orientation" from "pixel orientation."
After reading this, you will understand what the EXIF orientation tag is, which function Pillow uses to handle it, and which problems it cannot solve. Before processing important files, keep the original, and verify against the boundaries and acceptance items described in the text.
What to do if a document photographed with a phone is oriented incorrectly? One-sentence conclusion
First apply the EXIF orientation tag with ImageOps.exif_transpose, then feed the adjusted image into OCR; skew and perspective issues must be handled separately.
| Your situation | Recommended Practices | Cause |
|---|---|---|
| The viewer displays normally, but the parsed result is rotated sideways | First apply the EXIF orientation using ImageOps.exif_transpose | The pixels are not rotated; only the display layer has been adjusted. |
| The photo is slightly tilted overall. | Evaluate skew correction separately | exif_transpose does not handle shooting angles |
| The paper is trapezoidal. | Detect the paper boundary, then apply perspective correction. | Perspective distortion is not an EXIF orientation issue. |
| Need to save the boxes returned by OCR | Simultaneously record the input size, orientation transformation, and output size | Adjusted graph coordinates differ from the original image |
Display orientation and pixel orientation should be considered separately
Phone photos may not actually be rotated at the pixel level. Instead, the EXIF orientation tag in the file tells the viewer how to display the image. The viewer uses this tag to adjust the picture, but if an OCR engine ignores it, the engine will read the page in a different orientation.
Pillow's ImageOps.exif_transpose adjusts pixels according to orientation information and removes the applied orientation tag so that it isn't rotated again later. It handles EXIF orientation, not arbitrary tilt or perspective distortion from shooting. Straightening a sheet of paper photographed at an angle with a phone still requires a different geometric transformation.
Testing Rotation Boundaries with Synthetic Pixels
The code below checks whether orientation markers are applied correctly, using synthetic images:
from PIL import Image, ImageOps
source = Image.new("RGB", (40, 20), "white")
source.putpixel((0, 0), (255, 0, 0))
source.getexif()[274] = 6
fixed = ImageOps.exif_transpose(source)
assert fixed.size == (20, 40)
assert fixed.getpixel((19, 0)) == (255, 0, 0)
assert fixed.getexif().get(274) is None
assert source.size == (40, 20)
again = ImageOps.exif_transpose(fixed)
assert again.size == fixed.size
assert again.tobytes() == fixed.tobytes()
Red pixels in the corners are used to help verify geometric relationships. No OCR engine is called, and no real text is simulated. Therefore, the test can only support the conclusion that "orientation markers are applied correctly," and cannot support any claim about "how much the text recognition rate improves." The example depends on Pillow and should be run with a pinned version.
Triage for directional anomalies
When facing direction-related problems, first observe the symptoms, then determine the cause. The table below can help you decide the next step:
| Observe | Possible causes | Next step |
|---|---|---|
| Viewer works normally; parser is set to landscape orientation. | EXIF not applied | Check direction labels and pixels |
| Slight tilt of the entire page | Shooting angle | Independent Evaluation Tilt Correction |
| The page is trapezoidal. | Perspective distortion | Correct after detecting paper boundaries |
| Text upside down but without markers | Missing metadata | Based on the page content, without guessing |
Coordinate recording should start after rotation
If OCR returns text boxes on the adjusted image, the box coordinates correspond to the adjusted image, not the originally captured one. So three pieces of information need to be kept: the input size, the orientation transform, and the output size. When displaying highlights, apply the inverse transform to the coordinates to map them back to their positions on the original image.
Only saving a set of boxes without recording which image they belong to will cause the highlight positions to drift away from the text.
Straighten the Figure Before Translating
When processing scanned materials through the OCR and translation entry point of OmniDoc (product entry point), you can first check the orientation against the original document. Orientation, perspective, and sharpness are three different checks, and each needs to be confirmed separately.
After the input conditions have been clearly organized, use the bilingual results to judge translation quality. If you attribute every omission to the translation model right away, you will often miss the real problems in the input.
References: Pillow ImageOps.
📊 Core Comparison
| Object being processed | Handling method | Was it completed by exif_transpose? |
|---|---|---|
| EXIF Orientation Tag | Adjust pixels by marker | Yes |
| Slight page tilt | Shooting Angle Correction | No, an independent assessment is required. |
| The page is trapezoidal. | Perspective correction | No, paper boundaries need to be detected. |
🎯 Which Approach Suits You?
If you...
- Viewer shows it correctly, but OCR result is sideways: apply the EXIF orientation first, then feed it into OCR again.
- Entire photo is tilted: treat skew correction as a separate step; don't rely on orientation handling to fix it.
- Paper edges appear trapezoidal: detect the paper boundary first, then apply perspective correction.
- Need to highlight positions on the original image: save the input dimensions and transformation information, and apply the inverse transformation at display time.
❓ Frequently Asked Questions (FAQ)
1. Can exif_transpose straighten a crooked photo of paper?
No. It only adjusts the pixels based on the EXIF orientation tag; it does not handle shooting angle or perspective distortion, which require separate geometric processing.
2. Why does the viewer display correctly, but the OCR result is horizontal?
The viewer applies the EXIF orientation tag, while the pixels themselves may not be rotated. If OCR ignores that tag, it will read the page in a different orientation.
3. Can the example code show how much the recognition rate has improved?
No. The example uses synthetic pixels to check whether the orientation marker is applied correctly. It does not call an OCR engine and does not simulate real text.
4. Why don't the OCR-returned boxes line up with the positions in the original image?
If OCR runs on the resized image, the box coordinates correspond to the resized image. You need to record the input size, the transform, and the output size, and apply the inverse transform when displaying the results.
📝 Summary
Orientation issues with phone photos: first determine whether the problem is display orientation or pixel orientation, then handle orientation, tilt, and perspective separately. Before processing important files, keep the original and complete a review.
Try it now: upload a document and start translating right away, with the original layout preserved.

