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

Rectify text lines before recognition #33

Open
robertknight opened this issue Feb 27, 2024 · 2 comments
Open

Rectify text lines before recognition #33

robertknight opened this issue Feb 27, 2024 · 2 comments

Comments

@robertknight
Copy link
Owner

robertknight commented Feb 27, 2024

Ocrs does not currently apply any perspective correction to extracted text lines before applying recognition. The recognition model is trained to handle skewed and rotated inputs, but this only works for moderate rotation. Text lines with significant rotation will have their characters squashed in the vertical direction during preprocessing, as recognition inputs have a fixed height of 64px. This harms recognition accuracy.

The library should rectify line images before recognition to better handle rotated/skewed inputs.

@robertknight
Copy link
Owner Author

robertknight commented Mar 1, 2024

Example of an image where this comes up (source):

slide

Text line images from the slides currently look like this when input to the recognition model (see output of ocrs image.jpeg --text-line-images):

If the line were rectified first, the accuracy should improve a lot.

@robertknight
Copy link
Owner Author

robertknight commented Mar 2, 2024

Reference implementation using OpenCV's image transform functions.

Usage:

python rectify.py slide.jpeg line.png '1105,316;1630,458;1622,498;1105,356' 517,64

Note the coordinate order is clockwise from top left. This produces line.png:

line

From the rectified image, Ocrs is able to correctly extract the text, whereas from the original the output is garbage.

@robertknight robertknight changed the title Rectify rotated lines before recognition Rectify rotated text lines before recognition Mar 2, 2024
@robertknight robertknight changed the title Rectify rotated text lines before recognition Apply perspective correction to text lines before recognition Mar 2, 2024
@robertknight robertknight changed the title Apply perspective correction to text lines before recognition Rectify text lines before recognition Mar 2, 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

No branches or pull requests

1 participant