Click here to Skip to main content
15,921,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As you know images after scanning get rotated to some extent.
how we can find the angle of rotation of scanned image with respect to original image and how we can rotate scanned image to become same as original one in GDI C#?
Posted

1 solution

Detect the bounding box of what text that is on the image. Depending on the quality of your scan you may have to tweak the parameters of what is considered background and what constitutes text. Once you have the bounding box you have the four coordinates (top,left) (top,right) (bottom, left) (bottom, right).
Let's consider the easy part first: The top and bottom left values are identical within some TBD epsilon. Ergo the box is already in an upright position, albeit it still might have to be flipped 180° or +90° respectively -90° ( == +270°).
The rest is basic maths: determine the inclination of the box using the difference between top and bottom (from the left side for instance) and use trigonometric functions to figure out what angle to rotate the Image.

Here is a short schematic sketch that should set you in the right direction: Determine angle of rotation by using the bounding box.

This formula only works if there is in fact a rotation involved i.e. |opposite| > 0.
The rotation by 180° as well as clock/counterclokwise rotation of 90° may also be nescessary. You can test the OCR process for every alignment. That part can be skipped of course if you know that the paper was already in the correct upright position and only needs some minor adjustments less than |90°|.

Regards,
— Manfred
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900