Reputation: 69269
I am working on an OCR which main function is to OCR invoices, now it can happen that they have a (slight) rotation when being scanned.
What would you suggest to fix the rotation?
What I currently have:
Is there any way I can detect the rotation in the image, such that I only need to do one expensive rotation?
Regards.
Upvotes: 1
Views: 1676
Reputation: 1073
I would suggest you to first downgrade the image and convert it into monochrome
so we have only 0 and 255 in the 8 bit
color format that will help in identifying) and then track black
lines instead of white
on the invoices(that should not be a big change on your algorithm), as generally invoices contain horizontal black lines so as soon as you can find the slope of the black line(that are 30 degree +/- to you plane
as i guess input won't be more tilted then that) you can get the degree rotation that you need for the main image.
To optimize the process i would suggest you to also use the image thinning before tracking the black lines, that will get you better results as there may be thick black lines.
Upvotes: 2
Reputation: 168825
- The downside: Every rotation takes 0.5 seconds, the images are scanned in a fairly reasonable high resolution (2000 width x 3000 height), and the resolution is definitely needed for the OCR process.
Sure, but the high resolution is probably not needed in order to analyze the white lines.
I would recommend trying to shrink or crop the image (to a smaller copy) before the first angle determination, and use the low resolution version consistently until the angle is determined. Then swap back to the large resolution image for the final rotation and for the OCR.
Upvotes: 3