Exemplo n.º 1
0
 private static void AssertSetCoordinates(string paramName, PointD topLeft, PointD topRight, PointD bottomLeft, PointD bottomRight)
 {
     ExceptionAssert.ThrowsArgumentException <ArgumentOutOfRangeException>(paramName, () =>
     {
         using (var logo = Images.Logo)
         {
             var script = new WhiteboardScript();
             script.SetCoordinates(topLeft, topRight, bottomLeft, bottomRight);
             script.Execute(logo);
         }
     });
 }
Exemplo n.º 2
0
        public static void EnhanceImageQuality(string ImageDirectory)
        {
            // do image Enhance then call Do OCR
            // convert - density 600 input.pdf output.tif;
            //System.Drawing.Image SelectedImage = new System.Drawing.Image();
            DirectoryInfo EnhancedImageDir = new DirectoryInfo(@"C:\OCR\EnhancedImage\");
            Bitmap        orgimg           = (Bitmap)Bitmap.FromFile(ImageDirectory);
            Bitmap        bitmap           = (Bitmap)Bitmap.FromFile(ImageDirectory);
            Bitmap        image2           = Grayscale.CommonAlgorithms.BT709.Apply(bitmap);


            Rectangle  rec        = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            BitmapData bitmapdata = bitmap.LockBits(rec, ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
            // create instance of skew checker
            DocumentSkewChecker skewChecker = new DocumentSkewChecker();
            // get documents skew angle
            double angle = skewChecker.GetSkewAngle(bitmapdata);
            // create rotation filter
            RotateBilinear rotationFilter = new RotateBilinear(-angle);

            rotationFilter.FillColor = Color.White;
            // rotate image applying the filter
            bitmap.UnlockBits(bitmapdata);

            Bitmap rotatedImage = rotationFilter.Apply(orgimg);

            rotatedImage.Save(ImageDirectory + ".tif");

            using (MagickImage image = new MagickImage(ImageDirectory))
            {
                TextCleanerScript Cleaner = new TextCleanerScript();

                // Cleaner.FilterSize = 12; // filter to clean up background;
                // Cleaner.FilterOffset = (Percentage)3; //filter in percent to reduce noise
                // Cleaner.Saturation = (Percentage)200;  // high value to Saturation
                //// Cleaner.Unrotate = true;
                // var newImage1 = Cleaner.Execute(image);
                // //newImage1.CannyEdge(); selcet the inner objects in the image

                // newImage1.Density = new PointD(600, 600);
                // newImage1.Write(EnhancedImageDir + Path.GetFileName(ImageDirectory)
                //     + ".tif");

                AutotrimScript WhiteB = new AutotrimScript();
                // WhiteB.InnerTrim = true;
                var a = WhiteB.GetLargestAreaP(image);

                WhiteboardScript AoutoTrim = new WhiteboardScript();
                //AoutoTrim.SetCoordinates(new Coordinate(01, 53), new Coordinate(313, 31),
                //new Coordinate(331, 218), new Coordinate(218, 200));
                //AoutoTrim.Enhance = WhiteboardEnhancements.Both;
                //AoutoTrim.FilterSize = 25; // filter to clean up background;
                //AoutoTrim.FilterOffset = (Percentage)3; //filter in percent to reduce noise
                //AoutoTrim.Saturation = (Percentage)200;  // high value to Saturation
                //AoutoTrim.SetCoordinates(new Coordinate(a[0].X, a[0].Y), new Coordinate(a[1].X, a[1].Y),
                //new Coordinate(a[2].X, a[2].Y), new Coordinate(a[3].X, a[3].Y));
                var new2mage2 = AoutoTrim.Execute(image);
                //  new2mage2.Deskew((Percentage)2);
                AoutoTrim.SetCoordinates(new Coordinate(13, 3), new Coordinate(342, 6),
                                         new Coordinate(331, 467), new Coordinate(38, 482));
                AoutoTrim.Enhance = WhiteboardEnhancements.Both;


                //  new2mage2.Density= new PointD(300, 300);
                new2mage2 = WhiteB.Execute(new2mage2);
                new2mage2 = Cleaner.Execute(new2mage2);

                new2mage2.Density = new PointD(600, 600);
                new2mage2.Write(EnhancedImageDir + Path.GetFileName(ImageDirectory)
                                + "2" + ".tif");
                string dir12 = (EnhancedImageDir + Path.GetFileName(ImageDirectory)
                                + "2" + ".tif");
                Bitmap     imageTobeDeske = new Bitmap(dir12);
                gmseDeskew deskew         = new gmseDeskew();
                deskew.New(imageTobeDeske);
                double angel = deskew.GetSkewAngle();
                if (angel > 0)
                {
                    angel = angel * -1;
                }



                WhiteB.BorderColorLocation = new Coordinate(10, 10);


                //AoutoTrim.SetCoordinates(ad);

                //WhiteB.ColorFuzz = (Percentage)20;
                //var new2mage3 = WhiteB.Execute(image);
                //new2mage3 = Cleaner.Execute(new2mage3);

                //new2mage3.Write(EnhancedImageDir + Path.GetFileName(ImageDirectory)
                //    + "3" + ".tif");
            }
        }