AForge.Imaging.DocumentSkewChecker.GetSkewAngle C# (CSharp) Method

GetSkewAngle() public method

Get skew angle of the provided document image.
Unsupported pixel format of the source image.
public GetSkewAngle ( Bitmap image ) : double
image System.Drawing.Bitmap Document's image to get skew angle of.
return double
        public double GetSkewAngle( Bitmap image )
        {
            return GetSkewAngle( image, new Rectangle( 0, 0, image.Width, image.Height ) );
        }

Same methods

DocumentSkewChecker::GetSkewAngle ( Bitmap image, Rectangle rect ) : double
DocumentSkewChecker::GetSkewAngle ( BitmapData imageData ) : double
DocumentSkewChecker::GetSkewAngle ( BitmapData imageData, Rectangle rect ) : double
DocumentSkewChecker::GetSkewAngle ( UnmanagedImage image ) : double
DocumentSkewChecker::GetSkewAngle ( UnmanagedImage image, Rectangle rect ) : double

Usage Example

    protected void fastHarrisRansacBlendStraight(List <Bitmap> imgs)
    {
        List <IntPoint[]> harrisPoints = new List <IntPoint[]>();
        MatrixH           homography;

        //Calculate all the Harris Points
        HarrisCornersDetector harris = new HarrisCornersDetector(0.03f, 10000f);

        for (int i = 0; i < imgs.Count; i++)
        {
            harrisPoints.Add(harris.ProcessImage(imgs[i]).ToArray());
        }

        Bitmap final = imgs[0];

        for (int i = 1; i < imgs.Count; i++)
        {
            //Convert my frames to grayscale so I can find and adjust the normal vectors
            AForge.Imaging.Filters.GrayscaleBT709 grayscale = new AForge.Imaging.Filters.GrayscaleBT709();
            AForge.Imaging.DocumentSkewChecker    skew      = new AForge.Imaging.DocumentSkewChecker();

            double finalAngle = skew.GetSkewAngle(grayscale.Apply(final));
            double imgAngle   = skew.GetSkewAngle(grayscale.Apply(imgs[i]));

            //Less than 5% to account for human error with rotations and wobbles
            if (Math.Abs(finalAngle - imgAngle) < 5)
            {
                AForge.Imaging.Filters.RotateBilinear rotate = new AForge.Imaging.Filters.RotateBilinear(finalAngle - imgAngle);
                rotate.FillColor = Color.FromArgb(0, 255, 255, 255);
                imgs[i]          = rotate.Apply(imgs[i]);

                //Update harris
                harrisPoints[i] = harris.ProcessImage(imgs[i]).ToArray();
            }

            IntPoint[] harrisFinal = harris.ProcessImage(final).ToArray();

            //Correlate the Harris pts between imgs
            CorrelationMatching matcher = new CorrelationMatching(5, final, imgs[i]);
            IntPoint[][]        matches = matcher.Match(harrisFinal, harrisPoints[i]);

            //Create the homography matrix using ransac
            RansacHomographyEstimator ransac = new RansacHomographyEstimator(0.025, 0.99);
            homography = ransac.Estimate(matches[0], matches[1]);

            Blend blend = new Blend(homography, final);
            blend.Gradient = true;
            final          = blend.Apply(imgs[i]);
        }

        showImage(final);
    }
All Usage Examples Of AForge.Imaging.DocumentSkewChecker::GetSkewAngle