Example #1
0
        public static void Run()
        {
            // ExStart:SkewImageCorrectionUsingAlgorithm
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Load template file
            OmrTemplate template = OmrTemplate.Load(dataDir + "questions.amr");

            // Load the image to be analyzed
            OmrImage image = OmrImage.Load(dataDir + "answers.jpg");


            // Area of the image to be processed
            Rectangle area = new Rectangle(0, 0, image.Width, image.Height);

            // Grayscale conversion
            GrayscaleAlgorithm gs = new GrayscaleAlgorithm();

            gs.Process(image, area);

            // Binarization
            AverageThresholdAlgorithm threshold = new AverageThresholdAlgorithm();

            threshold.Process(image, area);

            // Skew correction
            SkewCorrectionAlgorithm skewCorrection = new SkewCorrectionAlgorithm();

            skewCorrection.Process(ref image, area);

            // save image
            image.AsBitmap().Save(dataDir + "result_out.jpg");
            // ExEnd:SkewImageCorrectionUsingAlgorithm
        }
Example #2
0
        public static void Run()
        {
            // ExStart:SkewedImageSecondMethod
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Load the image to be analyzed
            OmrImage image = OmrImage.Load(dataDir + "answers.jpg");

            OmrEngine engine = new OmrEngine(new OmrTemplate());

            // Get skew degree of the image
            double degree = engine.GetSkewDegree(image);

            // Rotate image to correct skew
            engine.RotateImage(ref image, degree);

            // Save image
            image.AsBitmap().Save(dataDir + "result_out.jpg");
            // ExEnd:SkewedImageSecondMethod
        }