Example #1
0
        public static Bitmap RecognizeDocumentInImage(Bitmap originalBmp)
        {
            var grayscale      = new GrayscaleImage(originalBmp);
            var compressionBmp = BitmapProcessing.ImageCompression(originalBmp);
            var processedImage = ImageFilters.ImageFiltering(compressionBmp);
            var resultSearch   = SearchSingularPoints.SerchSPForImage(originalBmp, compressionBmp, processedImage);

            var spPoints  = resultSearch.Item1;
            var equations = resultSearch.Item2;

            BitmapProcessing.SelectBackground(grayscale, equations);

            var widthAndHeight = MakeWidthAndHeightDocument(spPoints);
            var documentWidth  = widthAndHeight.Item1;
            var documentHeight = widthAndHeight.Item2;

            var anglePoints = MakeAnglePoints(documentWidth, documentHeight, spPoints);
            var H           = GetMatrixHomography(spPoints, anglePoints);
            var inverseH    = H.Inverse();

            var correctImage     = ImageCorrection(inverseH, grayscale);
            var correctSpPoints  = TransformPoints(inverseH, spPoints);
            var correctEquations = MakeEquationsLines(correctSpPoints);
            var angle            = correctEquations[2].AngleDeviationOX();

            correctImage = BitmapProcessing.RotateGrayscaleImage(correctImage, angle);
            var document = ImageCutter.CutDocument(correctImage);

            return(BitmapProcessing.MakeBitmap(document.Width, document.Height, document.Colors));
            //return BitmapProcessing.MakeBitmap(correctImage.Width, correctImage.Height, correctImage.Colors);
        }