Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Tesseract's Orientation detection #111

Merged
merged 3 commits into from
Nov 28, 2024
Merged

Conversation

ZeeshanZulfiqarAli
Copy link
Contributor

@ZeeshanZulfiqarAli ZeeshanZulfiqarAli commented Nov 26, 2024

This PR replaces the orientation correction mechanism with Tesseract's. It resulted in ~60-70% reduction in time taken by the orientation correction step (1.862s -> 756.95ms).

The confidence returned by the Tesseract is based on the number of glyphs detected and can result in extremely low scores (<1) even for correct detections. This is why this PR doesn't have a confidence threshold, as finding a score that works universally is a hard problem.

This is how both approaches fared on our test data set of 47 randomly rotated pages:

Orientation detection mechanism Number of misclassifications Percentage of misclassifications
In-house chunking strategy 23 48.9%
Tesseract OSD 5 10.6%

Before this change, the test resulted in ~63% accuracy. The dataset was randomly rotated to either 0, 90, 180, or 270 degrees, indicated as "randomly rotated" in the table below. This dataset was then used to compare Tesseract OSD and the chunking strategy. Tesseract OSD produced almost perfect results (61%) coming in close to the original Zerox performance of 63% (This 3% step down is discussed later on). On the other hand, the chunking strategy produced 47.10% accuracy (25% down).

Orientation detection mechanism Dataset Accuracy
In-house chunking strategy Zerox test ~63% (baseline)
Tesseract OSD Zerox test - randomly rotated ~61%
In-house chunking strategy Zerox test - randomly rotated ~47.10%

This randomly rotated dataset can be found here.

Why the 2% step down?

Well, Tesseract failed to identify orientation for two images with the message "Too few characters. Skipping this page". For one of the image, cropping in to the receipt fixed this problem.
Tesseract has a configuration min_characters_to_try, which was set to 0 but got the same result.

And...

This PR also adds the image correction (trimming and orientation correction) if the image (PNG) is passed, which were bypassed before. This required in change in the temp directory folder structure which is expected to have no user facing impact.

Note:

When running this for the first time, tesseract downloads a file osd.traineddata sized 10.6MB

@tylermaran
Copy link
Contributor

To clarify, is the 63% accuracy the completion accuracy from running npm run test? Not specifically the flipping accuracy.

@ZeeshanZulfiqarAli
Copy link
Contributor Author

That is correct: all the tests were run using the npm run test. With an ideal orientation detection system, we'll get the same accuracy on the original test dataset and the randomly rotated (i-e, all pages were corrected accurately). With Tesseract OSD, we are getting a 2% reduction in the accuracy compared to how Zerox performed with the original dataset that had all but one correctly oriented pages.

@ZeeshanZulfiqarAli
Copy link
Contributor Author

@tylermaran your question made me realize that it'll be more helpful to know the exact count of misclassifications across both approaches, and if've now added that to the PR's description.

@annapo23 annapo23 merged commit 03c5cae into main Nov 28, 2024
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.

3 participants