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); }
private void OpenFile(PictureBox pictureBox1) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG)|*.BMP;*.JPG;*.GIF;*.PNG|All files (*.*)|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { try { OriginalBmp = new Bitmap(ofd.FileName); CompressionBmp = BitmapProcessing.ImageCompression(OriginalBmp); pictureBox1.Image = new Bitmap(OriginalBmp, pictureBox1.ClientSize); } catch { MessageBox.Show("Невозможно открыть выбранный файл", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public GrayscaleImage(Bitmap bmp) { Width = bmp.Width; Height = bmp.Height; Colors = BitmapProcessing.ConvertRgbToGrayscale(bmp); }