Ejemplo n.º 1
0
 public void Execute_InputNull_ThrowsException()
 {
     ExceptionAssert.ThrowsArgumentException <ArgumentNullException>("input", () =>
     {
         var script = new TextCleanerScript();
         script.Execute(null);
     });
 }
 public void Test_Execute_Null()
 {
     ExceptionAssert.ThrowsArgumentException <ArgumentNullException>(() =>
     {
         var script = new TextCleanerScript();
         script.Execute(null);
     }, "input");
 }
        private void Test_Execute(string input, Action <TextCleanerScript> action, string output)
        {
            string inputFile = GetInputFile(input);

            using (MagickImage image = new MagickImage(inputFile))
            {
                TextCleanerScript script = new TextCleanerScript();
                action(script);

                MagickImage scriptOutput = script.Execute(image);
                TestOutput(scriptOutput, output);
            }
        }
Ejemplo n.º 4
0
        private static void AssertInvalidOperation(string expectedMessage, Action <TextCleanerScript> initAction)
        {
            var script = new TextCleanerScript();

            using (var logo = new MagickImage(Images.Logo))
            {
                initAction(script);

                ExceptionAssert.Throws <InvalidOperationException>(expectedMessage, () =>
                {
                    script.Execute(logo);
                });
            }
        }
Ejemplo n.º 5
0
        private void AssertExecute(string input, string methodName, Action <TextCleanerScript> action)
        {
            string inputFile = GetInputFile(input);

            /* LosslessCompress(inputFile); */

            using (var image = new MagickImage(inputFile))
            {
                TextCleanerScript script = new TextCleanerScript();
                action(script);

                using (var scriptOutput = script.Execute(image))
                {
                    string outputFile = GetOutputFile(input, methodName);
                    AssertOutput(scriptOutput, outputFile);
                }
            }
        }
Ejemplo n.º 6
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");
            }
        }
        public void Test_Settings()
        {
            var script = new TextCleanerScript();

            using (var logo = new MagickImage(Images.Logo))
            {
                script.Execute(logo);

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.AdaptiveBlur = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.CropOffset.Bottom = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.CropOffset.Left = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.CropOffset.Right = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.CropOffset.Top = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.FilterSize = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.Padding = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.Sharpen = -1;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.Saturation = (Percentage)(-1);
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.SmoothingThreshold = (Percentage)150;
                    script.Execute(logo);
                });

                ExceptionAssert.Throws <InvalidOperationException>(() =>
                {
                    script.Reset();
                    script.SmoothingThreshold = (Percentage)(-50);
                    script.Execute(logo);
                });
            }
        }