Question

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:

  • A function that calculates the "amount of white lines" in the image.
  • A function that can rotate the image by any angle.
  • Current approach: Rotate the image by an angle of 1 degree every time, check the solution with the most white lines, and use that image for the rest of the OCR process.
  • 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.

Is there any way I can detect the rotation in the image, such that I only need to do one expensive rotation?

Regards.

Was it helpful?

Solution

  • 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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top