:: AForge.NET Framework :: Articles :: Forums ::

## Rotation angle of scanned document

The forum is to discuss topics related to different areas of image processing and computer vision.

### Rotation angle of scanned document

Hi guys,

Here is the problem:
My document(image) has 4 solid black rectangles with fixed sizes (20 X 20 pixels).
After scanning the document I need to calculate the angle of rotation ? (using these small rectangles at the corners..)

I thing there should be very elegant way in AFORGE.NET.

P.S.
I know about DocumentSkewChecker, but this is not helpful in my case.
gghazaryan

Posts: 7
Joined: Sat Sep 17, 2011 4:18 pm

### Re: Rotation angle of scanned document

Hello,

gghazaryan wrote:My document(image) has 4 solid black rectangles with fixed sizes (20 X 20 pixels).

Show it then. Descriptions like this tend to be vague.

gghazaryan wrote:After scanning the document I need to calculate the angle of rotation ? (using these small rectangles at the corners..)

You may find those rectangles with Blob Counter routine. Then get coordinates of 4 corners using Quadrilateral Finder. When it is done it becomes quite simple geometry to calculate rotation of rectangle when its corners are known.
With best regards,
Andrew

Interested in supporting AForge.NET Framework?

andrew.kirillov

Posts: 2685
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

### Re: Rotation angle of scanned document

Thanks Andrew.
gghazaryan

Posts: 7
Joined: Sat Sep 17, 2011 4:18 pm

### Re: Rotation angle of scanned document

I did it like that:
Code: Select all
`//Rotating orginal image            sourceImage = AForge.Imaging.Image.Clone((Bitmap)Orginal, PixelFormat.Format24bppRgb);            double dx = centers[1].X - centers[0].X;  //centers - a collection of 2 centers of an Image no.0 is the top left center of cube, no.1 is  the top right            double dy = centers[0].Y - centers[1].Y;                double ang = Math.Atan2(dx,dy) * (180 / Math.PI);            RotateBicubic filter = new RotateBicubic(ang-90, false);//Apply the filter on your Image`

And it worked like a charm...
BombosColombos

Posts: 7
Joined: Mon Aug 08, 2011 5:52 pm
Location: Promised land