简体   繁体   中英

Detect Rotation of a scanned image in C#

We want ac# solution to correct the scanned image because it is rotated. To solve this problem we must detect the rotation angle first and then rotate the image. This was our first thought for our problem. But then we thought image warping would be more accurate as I think it would make the scanned image like our template. Then we can process it as we know all the coordinates of our template... I searched for a free SDK or a free solution in c#. Helping me in this will be great as it is the last task in our work. Really, thanks for all.

We used the PrimeOCR product to do this. It's not free, but we couldn't find a free program that was comparable.

So, the hard part is to detect the angle of the page.

If you have full control over the template, the simplest way to do this is probably to come up with an easily-detectable symbol (eg a solid black circle) and stick 3 of them on the template. Then, detect them (just look for big blocks of pixels with high saturation, in the case of a solid black circle).

So, you'll then have 3 sets of coordinates. If you have a top circle, a left circle, and a right circle with all 3 circles at difference distances from one another, detecting which circle is the top circle should be pretty easy.

Then just call a rotation function. This part is easy and has been done before (eg http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate ).

Edit: I suggested a circle because it's easier to find the center, but a rectangle should work, too.

To be more explicit about how to actually locate the rectangles/circles, take the average Brightness value of every a × a group of pixels. If that value is greater than b, then that a × a group of pixels is part of a rectangle. a and b are varables you'll want to come up with yourself.

Use flood-fill (or, more precisely, Connected Component Labeling ) group the resulting pixels together. The end result should give you your rectangles.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM