public static bool FindTextInImageFile(string fileFullPath, string text, ref CancellationTokenSource cts)
        {
            try
            {
                // Create an instance of OcrEngine class
                var ocr = new OcrEngine();

                // Set the Image property of OcrEngine by reading an image file
                ocr.Image = ImageStream.FromFile(fileFullPath);

                // Set the RemoveNonText to true
                ocr.Config.DetectTextRegions = true;

                // Perform OCR operation
                if (ocr.Process())
                {
                    if (ocr.Text.ToString().Contains(text))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }

            return(false);
        }
        public static void Run()
        {
            // ExStart:ExtractPreprocessedImages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream 
            ocrEngine.Image = ImageStream.FromFile(dataDir + "sample1.jpg");
            ocrEngine.Config.SavePreprocessedImages = true;

            // Process the image
            if (ocrEngine.Process())
            {
                // Save binarized,filtered image on disc
                ocrEngine.PreprocessedImages.BinarizedImage.Save(dataDir + "BinarizedImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
                ocrEngine.PreprocessedImages.FilteredImage.Save(dataDir + "FilteredImage_out.png", System.Drawing.Imaging.ImageFormat.Png);

                // Save image after removing non-textual fragments,  skew correction and textual block detection
                ocrEngine.PreprocessedImages.NonTextRemovedImage.Save(dataDir + "NonTextRemovedImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
                ocrEngine.PreprocessedImages.RotatedImage.Save(dataDir + "RotatedImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
                ocrEngine.PreprocessedImages.TextBlocksImage.Save(dataDir + "TextBlocksImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
            }
            // ExEnd:ExtractPreprocessedImages
        }
        public static void Run()
        {
            // ExStart:WorkingWithDifferentLanguages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of Stream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "SpanishOCR.bmp");

            // Clear the default language (English)
            ocrEngine.LanguageContainer.Clear();

            // Load the resources of the language from file path location or an instance of Stream
            ocrEngine.LanguageContainer.AddLanguage(LanguageFactory.Load(dataDir + "Aspose.OCR.Spanish.Resources.zip"));

            // Process the image
            if (ocrEngine.Process())
            {
                // Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:WorkingWithDifferentLanguages
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Get an instance of INotifier
            INotifier processorWord = NotifierFactory.WordNotifier();

            //Write a delegate to handle the Elapsed event
            processorWord.Elapsed += delegate
            {
                //Display the recognized text on screen
                Console.WriteLine(processorWord.Text);
            };

            // Add the word processor to the OcrEngine
            ocrEngine.AddNotifier(processorWord);

            //Process the image
            ocrEngine.Process();
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Clear notifier list
            ocrEngine.ClearNotifies();

            //Clear recognition blocks
            ocrEngine.Config.ClearRecognitionBlocks();

            //Add 2 rectangles to user defined recognition blocks
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(27, 63, 34, 38));   //Detecting A
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(209, 111, 28, 34)); //Detecting 6

            //Ignore everything else on the image other than the user defined recognition blocks
            ocrEngine.Config.DetectTextRegions = false;

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "sampleocr.bmp");

            //Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
            }
        }
        public static void Run()
        {
            // ExStart:OCROnMultipageTIFF   
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR() + "SampleTiff.tiff";

            // Create an initialize an instance of OcrEngine
            OcrEngine engine = new OcrEngine();

            // Set the OcrEngine.Image property by loading a multipage TIFF from disk, memory or URL
            engine.Image = ImageStream.FromFile(dataDir);

            // Set OcrEngine.ProcessAllPages to true in order to process all pages of TIFF in single run
            engine.ProcessAllPages = true;

            // Call OcrEngine.Process method to perform OCR operation
            if (engine.Process())
            {
                // Retrieve the list of Pages
                Page[] pages = engine.Pages;

                // Iterate over the list of Pages
                foreach (Page page in pages)
                {
                    // Display the recognized text from each Page
                    Console.WriteLine(page.PageText);
                }
            }
            // ExStart:OCROnMultipageTIFF   
        }
Beispiel #7
0
        public static void Run()
        {
            // ExStart:ReadPartInformation
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
                // Retrieve an array of recognized text by parts
                IRecognizedPartInfo[] text = ocrEngine.Text.PartsInfo;
                // Iterate over the text parts
                foreach (IRecognizedTextPartInfo symbol in text)
                {
                    // Display part intomation
                    Console.WriteLine("Text : " + symbol.Text);
                    Console.WriteLine("isItalic : " + symbol.Italic);
                    Console.WriteLine("Language : " + symbol.Language);
                }
            }
            // ExStart:ReadPartInformation
        }
        public static void Run()
        {
            // ExStart:DetectingTextBlocks  
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            // Remove non-textual blocks
            ocrEngine.Config.RemoveNonText = true;

            // Run recognition process
            if (ocrEngine.Process())
            {
                // Display text block locations
                foreach (IRecognizedPartInfo part in ocrEngine.Text.PartsInfo)
                {
                    Console.WriteLine(part.Box);
                }
            }
            // ExEnd:DetectingTextBlocks  
        }
Beispiel #9
0
        public static void Run()
        {
            // ExStart:DetectingTextBlocks
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Remove non-textual blocks
            ocrEngine.Config.RemoveNonText = true;

            // Run recognition process
            if (ocrEngine.Process())
            {
                // Display text block locations
                foreach (IRecognizedPartInfo part in ocrEngine.Text.PartsInfo)
                {
                    Console.WriteLine(part.Box);
                }
            }
            // ExEnd:DetectingTextBlocks
        }
        public static void Run()
        {
            // ExStart:GetLocationAndSizeExample  
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
                // Retrieve an array of recognized text by parts
                IRecognizedPartInfo[] text = ocrEngine.Text.PartsInfo;
                // Iterate over the text parts
                foreach (var recognizedPartInfo in text)
                {
                    var symbol = (IRecognizedTextPartInfo)recognizedPartInfo;
                    // Display the part information
                    Console.WriteLine("Symbol:" + symbol.Text);
                    // Get the rectangle sourronding the symbol
                    Rectangle box = symbol.Box;
                    // Display the rectangle location on the image canvas
                    Console.WriteLine("Box Location:" + box.Location);
                    // Display the rectangle dimensions
                    Console.WriteLine("Box Size:" + box.Size);

                }
            }
            // ExEnd:GetLocationAndSizeExample  
        }
        public static void Run()
        {
            // ExStart:ExtractPreprocessedImages
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "sample1.jpg");
            ocrEngine.Config.SavePreprocessedImages = true;

            // Process the image
            if (ocrEngine.Process())
            {
                // Save binarized,filtered image on disc
                ocrEngine.PreprocessedImages.BinarizedImage.Save(dataDir + "BinarizedImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
                ocrEngine.PreprocessedImages.FilteredImage.Save(dataDir + "FilteredImage_out.png", System.Drawing.Imaging.ImageFormat.Png);

                // Save image after removing non-textual fragments,  skew correction and textual block detection
                ocrEngine.PreprocessedImages.NonTextRemovedImage.Save(dataDir + "NonTextRemovedImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
                ocrEngine.PreprocessedImages.RotatedImage.Save(dataDir + "RotatedImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
                ocrEngine.PreprocessedImages.TextBlocksImage.Save(dataDir + "TextBlocksImage_out.png", System.Drawing.Imaging.ImageFormat.Png);
            }
            // ExEnd:ExtractPreprocessedImages
        }
Beispiel #12
0
        public static void Run()
        {
            // ExStart:ApplyingCorrectionFilters
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();
            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Create CorrectionFilters collection
            CorrectionFilters filters = new CorrectionFilters();
            Filter            filter  = null;

            // Initialize Median filter
            filter = new MedianFilter(5);
            filters.Add(filter);

            // Create Gaussian Blur filter
            filter = new GaussBlurFilter();
            filters.Add(filter);

            // Assign collection to OcrEngine
            ocrEngine.Config.CorrectionFilters = filters;

            // Run recognition process
            if (ocrEngine.Process())
            {
                // Display results
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:ApplyingCorrectionFilters
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Get an instance of INotifier
            INotifier processorWord = NotifierFactory.WordNotifier();

            //Write a delegate to handle the Elapsed event
            processorWord.Elapsed += delegate
            {
                //Display the recognized text on screen
                Console.WriteLine(processorWord.Text);
            };

            // Add the word processor to the OcrEngine
            ocrEngine.AddNotifier(processorWord);

            //Process the image
            ocrEngine.Process();
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Create an initialize an instance of OcrEngine
            OcrEngine engine = new OcrEngine();

            // Set the OcrEngine.Image property by loading an image from disk, memory or URL
            engine.Image = ImageStream.FromFile(dataDir + "Sample.bmp");

            // Create text recognition block by supplying X,Y coordinates and Width,Height values
            IRecognitionBlock block = RecognitionBlock.CreateTextBlock(6, 9, 120, 129);

            // Set the Whitelist property by specifying a new block whitelist
            block.Whitelist = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

            // YOU CAN ADD MORE TEXT BLOCK AND SET WHITE LISTS.

            // Set different configurations and add recognition block(s)
            engine.Config.ClearRecognitionBlocks();
            engine.Config.AddRecognitionBlock(block);
            engine.Config.DetectTextRegions = false;

            // Call OcrEngine.Process method to perform OCR operation
            if (engine.Process())
            {
                // Display the recognized text from each Page
                Console.WriteLine(engine.Text);
            }
        }
Beispiel #15
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Clear notifier list
            ocrEngine.ClearNotifies();

            //Clear recognition blocks
            ocrEngine.Config.ClearRecognitionBlocks();

            //Add 2 rectangles to user defined recognition blocks
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(27, 63, 34, 38)); //Detecting A
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(209, 111, 28, 34)); //Detecting 6

            //Ignore everything else on the image other than the user defined recognition blocks
            ocrEngine.Config.DetectTextRegions = false;

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "sampleocr.bmp");

            //Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
            }
        }
        public static void Run()
        {
            // ExStart:ExtractingText
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Clear notifier list
            ocrEngine.ClearNotifies();

            // Clear recognition blocks
            ocrEngine.Config.ClearRecognitionBlocks();

            // Add 2 rectangles to user defined recognition blocks
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(27, 63, 34, 38));   // Detecting A
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(209, 111, 28, 34)); // Detecting 6

            // Ignore everything else on the image other than the user defined recognition blocks
            ocrEngine.Config.DetectTextRegions = false;

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "sampleocr.bmp");

            // Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:ExtractingText
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
                // Retrieve an array of recognized text by parts
                IRecognizedPartInfo[] text = ocrEngine.Text.PartsInfo;
                // Iterate over the text parts
                foreach (IRecognizedTextPartInfo symbol in text)
                {
                    // Display part intomation
                    Console.WriteLine("Text : " + symbol.Text);
                    Console.WriteLine("isItalic : " + symbol.Italic);
                    Console.WriteLine("isUnderline : " + symbol.Underline);
                    Console.WriteLine("isBold : " + symbol.Bold);
                    Console.WriteLine("FontSize : " + symbol.FontSize);
                    Console.WriteLine("Language : " + symbol.Language);
                }
            }
        }
        public static void Run()
        {
            // ExStart:OCROnMultipageTIFF
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR() + "SampleTiff.tiff";

            // Create an initialize an instance of OcrEngine
            OcrEngine engine = new OcrEngine();

            // Set the OcrEngine.Image property by loading a multipage TIFF from disk, memory or URL
            engine.Image = ImageStream.FromFile(dataDir);

            // Set OcrEngine.ProcessAllPages to true in order to process all pages of TIFF in single run
            engine.ProcessAllPages = true;

            // Call OcrEngine.Process method to perform OCR operation
            if (engine.Process())
            {
                // Retrieve the list of Pages
                Page[] pages = engine.Pages;

                // Iterate over the list of Pages
                foreach (Page page in pages)
                {
                    // Display the recognized text from each Page
                    Console.WriteLine(page.PageText);
                }
            }
            // ExStart:OCROnMultipageTIFF
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
                //Retrieve an array of recognized text by parts
                IRecognizedPartInfo[] text = ocrEngine.Text.PartsInfo;
                //Iterate over the text parts
                foreach (IRecognizedTextPartInfo symbol in text)
                {
                    //Display the part information
                    Console.WriteLine("Symbol:" + symbol.Text);
                    //Get the rectangle sourronding the symbol
                    Rectangle box = symbol.Box;
                    //Display the rectangle location on the image canvas
                    Console.WriteLine("Box Location:" + box.Location);
                    //Display the rectangle dimensions
                    Console.WriteLine("Box Size:" + box.Size);

                }
            }
        }
        public static void Run()
        {
            // ExStart:GettingNotification
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();
            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Get an instance of INotifier
            INotifier processorWord = NotifierFactory.WordNotifier();

            //Write a delegate to handle the Elapsed event
            processorWord.Elapsed += delegate
            {
                // Display the recognized text on screen
                Console.WriteLine(processorWord.Text);
            };

            // Add the word processor to the OcrEngine
            ocrEngine.AddNotifier(processorWord);

            // Process the image
            ocrEngine.Process();
            // ExEnd:GettingNotification
        }
        public static void Run()
        {
            // ExStart:ExtractPreprocessedImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // set SavePreprocessedImages to true to save preprocessed images
            ocrEngine.Config.SavePreprocessedImages = true;

            // Set the Image property by loading the image from file path location or an instance of Stream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sample.jpg");

            if (ocrEngine.Process())
            {
                //Save binarized image on disc
                ocrEngine.PreprocessedImages.BinarizedImage.Save(dataDir + "Output\\BinarizedImage.png", System.Drawing.Imaging.ImageFormat.Png);

                //Save filtered image on disc
                ocrEngine.PreprocessedImages.FilteredImage.Save(dataDir + "Output\\FilteredImage.png", System.Drawing.Imaging.ImageFormat.Png);

                //Save image after removing non-textual fragments
                ocrEngine.PreprocessedImages.NonTextRemovedImage.Save(dataDir + "Output\\NonTextRemovedImage.png", System.Drawing.Imaging.ImageFormat.Png);

                //Save image after skew correction
                ocrEngine.PreprocessedImages.RotatedImage.Save(dataDir + "Output\\RotatedImage.png", System.Drawing.Imaging.ImageFormat.Png);

                //Save image after textual block detection
                ocrEngine.PreprocessedImages.TextBlocksImage.Save(dataDir + "Output\\TextBlocksImage.png", System.Drawing.Imaging.ImageFormat.Png);
            }
            Console.WriteLine(ocrEngine.Text);
            // ExEnd:ExtractPreprocessedImage
        }
        public static void Run()
        {
            // ExStart:GettingNotification   
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();
            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream 
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            // Get an instance of INotifier
            INotifier processorWord = NotifierFactory.WordNotifier();

            //Write a delegate to handle the Elapsed event
            processorWord.Elapsed += delegate
            {
                // Display the recognized text on screen
                Console.WriteLine(processorWord.Text);
            };

            // Add the word processor to the OcrEngine
            ocrEngine.AddNotifier(processorWord);

            // Process the image
            ocrEngine.Process();
            // ExEnd:GettingNotification               
        }
        public static void Run()
        {
            // ExStart:ExtractingText  
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Clear notifier list
            ocrEngine.ClearNotifies();

            // Clear recognition blocks
            ocrEngine.Config.ClearRecognitionBlocks();

            // Add 2 rectangles to user defined recognition blocks
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(27, 63, 34, 38)); // Detecting A
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(209, 111, 28, 34)); // Detecting 6
            
            // Ignore everything else on the image other than the user defined recognition blocks
            ocrEngine.Config.DetectTextRegions = false;

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "sampleocr.bmp"); 

            // Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:ExtractingText  
        }
        public static void Run()
        {
            // ExStart:UsingNotifierFactory
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "answers.jpg");

            // Get an instance of WordNotifier, Write a delegate to handle the Elapsed event and Display the recognized text on screen
            INotifier processorBlock = NotifierFactory.BlockNotifier();

            processorBlock.Elapsed += delegate
            {
                Console.WriteLine(processorBlock.Text);
            };

            // Add the word processor to the OcrEngine and Process the image
            ocrEngine.AddNotifier(processorBlock);
            ocrEngine.Process();
            // ExEnd:UsingNotifierFactory
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Create an initialize an instance of OcrEngine
            OcrEngine engine = new OcrEngine();

            // Set the OcrEngine.Image property by loading an image from disk, memory or URL
            engine.Image = ImageStream.FromFile(dataDir + "Sample.bmp");

            // Create text recognition block by supplying X,Y coordinates and Width,Height values
            IRecognitionBlock block = RecognitionBlock.CreateTextBlock(6, 9, 120, 129);

            // Set the Whitelist property by specifying a new block whitelist
            block.Whitelist = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

            // YOU CAN ADD MORE TEXT BLOCK AND SET WHITE LISTS.

            // Set different configurations and add recognition block(s)
            engine.Config.ClearRecognitionBlocks();
            engine.Config.AddRecognitionBlock(block);
            engine.Config.DetectTextRegions = false;

            // Call OcrEngine.Process method to perform OCR operation
            if (engine.Process())
            {
                // Display the recognized text from each Page
                Console.WriteLine(engine.Text);
            }
        }
Beispiel #26
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
                // Retrieve an array of recognized text by parts
                IRecognizedPartInfo[] text = ocrEngine.Text.PartsInfo;
                // Iterate over the text parts
                foreach (IRecognizedTextPartInfo symbol in text)
                {
                    // Display part intomation
                    Console.WriteLine("Text : " + symbol.Text);
                    Console.WriteLine("isItalic : " + symbol.Italic);
                    Console.WriteLine("isUnderline : " + symbol.Underline);
                    Console.WriteLine("isBold : " + symbol.Bold);
                    Console.WriteLine("FontSize : " + symbol.FontSize);
                    Console.WriteLine("Language : " + symbol.Language);
                }
            }
        }
        public static void Run()
        {
            // ExStart:ReadPartInformation
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            // Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
                // Retrieve an array of recognized text by parts
                IRecognizedPartInfo[] text = ocrEngine.Text.PartsInfo;
                // Iterate over the text parts
                foreach (IRecognizedTextPartInfo symbol in text)
                {
                    // Display part intomation
                    Console.WriteLine("Text : " + symbol.Text);
                    Console.WriteLine("isItalic : " + symbol.Italic);                    
                    Console.WriteLine("Language : " + symbol.Language);
                }
            }
            // ExStart:ReadPartInformation            
        }
Beispiel #28
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Run recognition process
            if (ocrEngine.Process())
            {
                Console.WriteLine(ocrEngine.Text);
                //Retrieve an array of recognized text by parts
                IRecognizedPartInfo[] text = ocrEngine.Text.PartsInfo;
                //Iterate over the text parts
                foreach (IRecognizedTextPartInfo symbol in text)
                {
                    //Display the part information
                    Console.WriteLine("Symbol:" + symbol.Text);
                    //Get the rectangle sourronding the symbol
                    Rectangle box = symbol.Box;
                    //Display the rectangle location on the image canvas
                    Console.WriteLine("Box Location:" + box.Location);
                    //Display the rectangle dimensions
                    Console.WriteLine("Box Size:" + box.Size);
                }
            }
        }
Beispiel #29
0
        public static void Run()
        {
            // ExStart:UserDefinedRecognitionBlocks
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Clear notifier list
            ocrEngine.ClearNotifies();

            // Clear recognition blocks
            ocrEngine.Config.ClearRecognitionBlocks();

            // Add 3 rectangle blocks to user defined recognition blocks
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 10, 20, 40));
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 4, 5, 6));
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 5, 5, 6));

            // Ignore everything else on the image other than the user defined recognition blocks
            ocrEngine.Config.DetectTextRegions = false;

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Run recognition process
            if (ocrEngine.Process())
            {
                // Retrieve user defined blocks that determines the paye layout
                var blocks = ocrEngine.Config.RecognitionBlocks;
                // Loop over the list of blocks
                foreach (var block in blocks)
                {
                    // Display if block is set to be recognized
                    Console.WriteLine(block.ToRecognize);
                    // Check if block has recognition data
                    if (block.RecognitionData == null)
                    {
                        Console.WriteLine("Null{0}", Environment.NewLine);
                        continue;
                    }
                    // Display dimension & size of rectangle that defines the recognition block
                    Console.WriteLine("Block: {0}", block.Rectangle);
                    if (block.RecognitionData is IRecognizedTextPartInfo)
                    {
                        // Display the recognition results
                        IRecognizedTextPartInfo textPartInfo = (IRecognizedTextPartInfo)block.RecognitionData;
                        Console.WriteLine("Text: {0}{1}", textPartInfo.Text, Environment.NewLine);
                    }
                }
            }
            // ExEnd:UserDefinedRecognitionBlocks
        }
        public static void Run()
        {
            // ExStart:AddingUserDefinedRecognitionBlocks
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Clear notifier list
            ocrEngine.ClearNotifies();

            // Clear recognition blocks
            ocrEngine.Config.ClearRecognitionBlocks();

            // Add 3 rectangle blocks to user defined recognition blocks
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 10, 20, 40));
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 4, 5, 6));
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 5, 5, 6));
            
            // Ignore everything else on the image other than the user defined recognition blocks
            ocrEngine.Config.DetectTextRegions = false;

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "sample1.jpg");

            // Run recognition process
            if (ocrEngine.Process())
            {
                // Retrieve user defined blocks that determines the paye layout
                var blocks = ocrEngine.Config.RecognitionBlocks;
                // Loop over the list of blocks
                foreach (var block in blocks)
                {
                    // Display if block is set to be recognized
                    Console.WriteLine(block.ToRecognize);
                    // Check if block has recognition data
                    if (block.RecognitionData == null)
                    {
                        Console.WriteLine("Null{0}", Environment.NewLine);
                        continue;
                    }
                    // Display dimension & size of rectangle that defines the recognition block
                    Console.WriteLine("Block: {0}", block.Rectangle);
                    if (block.RecognitionData is IRecognizedTextPartInfo)
                    {
                        // Display the recognition results
                        IRecognizedTextPartInfo textPartInfo = (IRecognizedTextPartInfo)block.RecognitionData;
                        Console.WriteLine("Text: {0}{1}", textPartInfo.Text, Environment.NewLine);
                    }
                }
            }
            // ExEnd:AddingUserDefinedRecognitionBlocks            
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Clear notifier list
            ocrEngine.ClearNotifies();

            //Clear recognition blocks
            ocrEngine.Config.ClearRecognitionBlocks();

            //Add 3 rectangle blocks to user defined recognition blocks
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 60, 700, 50));
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(0, 10, 700, 50));
            ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreatePictureBlock(0, 10, 700, 50));

            //Ignore everything else on the image other than the user defined recognition blocks
            ocrEngine.Config.DetectTextRegions = false;

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Run recognition process
            if (ocrEngine.Process())
            {
                //Retrieve user defined blocks that determines the paye layout
                var blocks = ocrEngine.Config.RecognitionBlocks;
                //Loop over the list of blocks
                foreach (var block in blocks)
                {
                    //Display if block is set to be recognized
                    Console.WriteLine(block.ToRecognize);
                    //Check if block has recognition data
                    if (block.RecognitionData == null)
                    {
                        Console.WriteLine("Null{0}", Environment.NewLine);
                        continue;
                    }
                    //Display dimension & size of rectangle that defines the recognition block
                    Console.WriteLine("Block: {0}", block.Rectangle);
                    if (block.RecognitionData is IRecognizedTextPartInfo)
                    {
                        //Display the recognition results
                        IRecognizedTextPartInfo textPartInfo = (IRecognizedTextPartInfo)block.RecognitionData;
                        Console.WriteLine("Text: {0}{1}", textPartInfo.Text, Environment.NewLine);
                    }
                }
            }
        }
Beispiel #32
0
        public static void Run()
        {
            // ExStart:GetTextPartHierarchy
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Process the image
            if (ocrEngine.Process())
            {
                // Retrieve the first block of the recognized text part
                IRecognizedTextPartInfo firstBlock = (ocrEngine.Text.PartsInfo[0] as IRecognizedTextPartInfo);

                // Get the children of the first block that will be the lines in the block
                if (firstBlock != null)
                {
                    IRecognizedPartInfo[] linesOfFirstBlock = firstBlock.Children;

                    // Retrieve the fist line from the collection of lines
                    IRecognizedTextPartInfo firstLine = (linesOfFirstBlock[0] as IRecognizedTextPartInfo);

                    // Display the level of line
                    if (firstLine != null)
                    {
                        Console.WriteLine(firstLine.Level);

                        // Retrieve the fist word from the collection of words
                        IRecognizedTextPartInfo firstWord = (firstLine.Children[0] as IRecognizedTextPartInfo);

                        // Display the level of word
                        Console.WriteLine(firstWord.Level);

                        // Retrieve the fist character from the collection of characters
                        IRecognizedTextPartInfo firstCharacter = (firstWord.Children[0] as IRecognizedTextPartInfo);

                        // Display the level of character
                        Console.WriteLine(firstCharacter.Level);
                    }
                }
            }
            // ExEnd:GetTextPartHierarchy
        }
        public static void Run()
        {
            // ExStart:GetTextPartHierarchy  
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream 
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Process the image
            if (ocrEngine.Process())
            {
                // Retrieve the first block of the recognized text part
                IRecognizedTextPartInfo firstBlock = (ocrEngine.Text.PartsInfo[0] as IRecognizedTextPartInfo);

                // Get the children of the first block that will the the lines in the block
                if (firstBlock != null)
                {
                    IRecognizedPartInfo[] linesOfFirstBlock = firstBlock.Children;

                    // Retrieve the fist line from the collection of lines
                    IRecognizedTextPartInfo firstLine = (linesOfFirstBlock[0] as IRecognizedTextPartInfo);

                    // Display the level of line
                    if (firstLine != null)
                    {
                        Console.WriteLine(firstLine.Level);

                        // Retrieve the fist word from the collection of words
                        IRecognizedTextPartInfo firstWord = (firstLine.Children[0] as IRecognizedTextPartInfo);

                        // Display the level of word
                        Console.WriteLine(firstWord.Level);

                        // Retrieve the fist character from the collection of characters
                        IRecognizedTextPartInfo firstCharacter = (firstWord.Children[0] as IRecognizedTextPartInfo);

                        // Display the level of character
                        Console.WriteLine(firstCharacter.Level);
                    }
                }
            }
            // ExEnd:GetTextPartHierarchy  
        }
Beispiel #34
0
        public static void Run()
        {
            // ExStart:LoadImagefromURLtoPerformOCR
            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from remote location
            ocrEngine.Image = ImageStream.FromUrl("https://blog.aspose.com/wp-content/uploads/sites/2/2019/03/SampleTextOnline.jpg");

            // Run recognition process
            if (ocrEngine.Process())
            {
                // Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:LoadImagefromURLtoPerformOCR
        }
Beispiel #35
0
        public static void DoWork(CaptureOption option)
        {
            //    Point StartPoint = new Point(_topLeft.X, _topLeft.Y);
            //    Rectangle bounds = new Rectangle(_topLeft.X, _topLeft.Y, _bottomRight.X - _topLeft.X, _bottomRight.Y - _topLeft.Y);
            //    ScreenShot.CaptureImage(StartPoint, Point.Empty, bounds, _screenShotFilePath);
            Size area = new Size(option.EndPoint.X - option.StartPoint.X, option.EndPoint.Y - option.StartPoint.Y);

            using (Bitmap screenBmpTmp = new Bitmap(area.Width, area.Height))
            {
                using (Graphics g = Graphics.FromImage(screenBmpTmp))
                {
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
                    g.CopyFromScreen(option.StartPoint, Point.Empty, area);
                }

                if (option.CopyToClipboard)
                {
                    System.Windows.Forms.Clipboard.SetDataObject(screenBmpTmp, true);
                }

                ImageFormat fmt         = ImageFmtMapper.ToImageFormat(option.ImageFormat);
                string      scrFilePath = option.FilePath;
                if (!string.IsNullOrEmpty(scrFilePath))
                {
                    if (string.Compare(fmt.ToString(), Path.GetExtension(scrFilePath), true) != 0)
                    {
                        scrFilePath = scrFilePath + "." + fmt.ToString();
                    }

                    screenBmpTmp.Save(scrFilePath, fmt);

                    if (option.OCRCapturedImage)
                    {
                        if (fmt != ImageFormat.Tiff)
                        {
                            scrFilePath = Path.GetTempFileName() + ".tif";
                            screenBmpTmp.Save(scrFilePath, ImageFormat.Tiff);
                        }

                        OcrEngine ocrEngine = new OcrEngine();
                        ocrEngine.Process(scrFilePath, Path.ChangeExtension(scrFilePath, ".txt"));
                    }
                }
            }
        }
Beispiel #36
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Process the image
            if (ocrEngine.Process())
            {
                //Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Process the image
            if (ocrEngine.Process())
            {
                //Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
        }
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Process the image
            if (ocrEngine.Process())
            {
                //Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
        }
Beispiel #39
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Create an instance of OcrEngine class
            OcrEngine ocr = new OcrEngine();

            //Set the Image property of OcrEngine by reading an image file
            ocr.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Set the RemoveNonText to true
            ocr.Config.RemoveNonText = true;

            //Perform OCR operation
            if (ocr.Process())
            {
                //Display results
                Console.WriteLine(ocr.Text);
            }
        }
        public static void Run()
        {
            // ExStart:PerformOCROnImage
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Process the image
            if (ocrEngine.Process())
            {
                // Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:PerformOCROnImage
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Create an instance of OcrEngine class
            OcrEngine ocr = new OcrEngine();

            //Set the Image property of OcrEngine by reading an image file
            ocr.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Set the RemoveNonText to true
            ocr.Config.RemoveNonText = true;

            //Perform OCR operation
            if (ocr.Process())
            {
                //Display results
                Console.WriteLine(ocr.Text);
            }
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Retrieve the OcrConfig of the OcrEngine object
            OCRConfig ocrConfig = ocrEngine.Config;

            //Set the Whitelist property to recognize numbers only
            ocrConfig.Whitelist = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

            //Set the Image property of OcrEngine object
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Call the Process method to retrieve the results
            ocrEngine.Process();
        }
        public static void Run()
        {
            // ExStart:PerformOCROnImage   
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream 
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            // Process the image
            if (ocrEngine.Process())
            {
                // Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:PerformOCROnImage   
        }
Beispiel #44
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Retrieve the OcrConfig of the OcrEngine object
            OCRConfig ocrConfig = ocrEngine.Config;

            //Set the Whitelist property to recognize numbers only
            ocrConfig.Whitelist = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

            //Set the Image property of OcrEngine object
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Call the Process method to retrieve the results
            ocrEngine.Process();
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Retrieve the OcrConfig of the OcrEngine object
            OCRConfig ocrConfig = ocrEngine.Config;

            //Set the Whitelist property to recognize numbers only
            ocrConfig.Whitelist = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

            //Set the Image property of OcrEngine object
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Call the Process method to retrieve the results
            ocrEngine.Process();
        }
Beispiel #46
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //Create an instance of OcrEngine class
            OcrEngine ocr = new OcrEngine();

            //Set the Image property of OcrEngine by reading an image file
            ocr.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Set the RemoveNonText to true
            ocr.Config.RemoveNonText = true;

            //Perform OCR operation
            if (ocr.Process())
            {
                //Display results
                Console.WriteLine(ocr.Text);
            }
        }
Beispiel #47
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);



            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Process the image
            if (ocrEngine.Process())
            {
                //Retrieve the first block of the recognized text part
                IRecognizedTextPartInfo firstBlock = (ocrEngine.Text.PartsInfo[0] as IRecognizedTextPartInfo);

                //Get the children of the first block that will the the lines in the block
                IRecognizedPartInfo[] linesOfFirstBlock = firstBlock.Children;

                //Retrieve the fist line from the collection of lines
                IRecognizedTextPartInfo firstLine = (linesOfFirstBlock[0] as IRecognizedTextPartInfo);

                //Display the level of line
                Console.WriteLine(firstLine.Level);

                //Retrieve the fist word from the collection of words
                IRecognizedTextPartInfo firstWord = (firstLine.Children[0] as IRecognizedTextPartInfo);

                //Display the level of word
                Console.WriteLine(firstWord.Level);

                //Retrieve the fist character from the collection of characters
                IRecognizedTextPartInfo firstCharacter = (firstWord.Children[0] as IRecognizedTextPartInfo);

                //Display the level of character
                Console.WriteLine(firstCharacter.Level);
            }
        }
        public static void Run()
        {
            // ExStart:PreprocesImagesFromOCROperation
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR() + "Sampleocr.bmp";

            // Initialize an instance of OcrEngine.
            OcrEngine ocr = new OcrEngine();

            // Set the Image property by loading the image from file path location.
            ocr.Image = ImageStream.FromFile(dataDir);

            // Set the SavePreprocessedImages property to false.
            ocr.Config.SavePreprocessedImages = true;

            if (ocr.Process())
            {
                // Do processing
            }
            // ExEnd:PreprocesImagesFromOCROperation
        }
        public static void Run()
        {
            // ExStart:PreprocesImagesFromOCROperation
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR() + "Sampleocr.bmp";

            // Initialize an instance of OcrEngine.
            OcrEngine ocr = new OcrEngine();

            // Set the Image property by loading the image from file path location.
            ocr.Image = ImageStream.FromFile(dataDir);

            // Set the SavePreprocessedImages property to false.
            ocr.Config.SavePreprocessedImages = true;

            if (ocr.Process())
            {
                // Do processing
            }
            // ExEnd:PreprocesImagesFromOCROperation
        }
Beispiel #50
0
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");

            //Remove non-textual blocks
            ocrEngine.Config.RemoveNonText = true;

            //Run recognition process
            if (ocrEngine.Process())
            {
                //Display text block locations
                Console.WriteLine(ocrEngine.Text.PartsInfo[0].Box);
                Console.WriteLine(ocrEngine.Text.PartsInfo[1].Box);
            }
        }
        public static void Run()
        {
            // ExStart:SettingtheOcrEngine
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();
            // Create an instance of OcrEngine class
            OcrEngine ocr = new OcrEngine();

            // Set the Image property of OcrEngine by reading an image file
            ocr.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            // Set the RemoveNonText to true
            ocr.Config.RemoveNonText = true;

            // Perform OCR operation
            if (ocr.Process())
            {
                // Display results
                Console.WriteLine(ocr.Text);
            }
            // ExEnd:SettingtheOcrEngine            
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of MemoryStream
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Process the image
            if (ocrEngine.Process())
            {
                //Retrieve the first block of the recognized text part
                IRecognizedTextPartInfo firstBlock = (ocrEngine.Text.PartsInfo[0] as IRecognizedTextPartInfo);

                //Get the children of the first block that will the the lines in the block
                IRecognizedPartInfo[] linesOfFirstBlock = firstBlock.Children;

                //Retrieve the fist line from the collection of lines
                IRecognizedTextPartInfo firstLine = (linesOfFirstBlock[0] as IRecognizedTextPartInfo);

                //Display the level of line
                Console.WriteLine(firstLine.Level);

                //Retrieve the fist word from the collection of words
                IRecognizedTextPartInfo firstWord = (firstLine.Children[0] as IRecognizedTextPartInfo);

                //Display the level of word
                Console.WriteLine(firstWord.Level);

                //Retrieve the fist character from the collection of characters
                IRecognizedTextPartInfo firstCharacter = (firstWord.Children[0] as IRecognizedTextPartInfo);

                //Display the level of character
                Console.WriteLine(firstCharacter.Level);
            }
        }
        public static void Run()
        {
            // ExStart:AutomaticallyCorrectTheSpellings
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();
            // Create an instance of OcrEngine class
            OcrEngine ocr = new OcrEngine();

            // Set the Image property of OcrEngine by reading an image file
            ocr.Image = ImageStream.FromFile(dataDir + "sampleocr_spell.bmp");

            // Set the DoSpellingCorrection to true
            ocr.Config.DoSpellingCorrection = true;

            // Perform OCR operation
            if (ocr.Process())
            {
                // Display results
                Console.WriteLine(ocr.Text);
            }
            // ExEnd:AutomaticallyCorrectTheSpellings            
        }
        public static void Run()
        {
            // ExStart:RecognizeWhiteListedCharacters
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Retrieve the OcrConfig of the OcrEngine object
            OCRConfig ocrConfig = ocrEngine.Config;

            // Set the Whitelist property to recognize numbers only
            ocrConfig.Whitelist = new char[] { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

            // Set the Image property of OcrEngine object
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            // Call the Process method to retrieve the results
            ocrEngine.Process();
            // ExEnd:RecognizeWhiteListedCharacters
        }
        public static void Run()
        {
            // ExStart:ApplyingCorrectionFilters
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OMR();
            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            // Create CorrectionFilters collection
            CorrectionFilters filters = new CorrectionFilters();
            Filter filter = null;

            // Initialize Median filter
            filter = new MedianFilter(5);
            filters.Add(filter);

            // Create Gaussian Blur filter
            filter = new GaussBlurFilter();
            filters.Add(filter);

            // Create Noise Removal filter
            filter = new RemoveNoiseFilter();
            filters.Add(filter);

            // Assign collection to OcrEngine
            ocrEngine.Config.CorrectionFilters = filters;

            // Run recognition process
            if (ocrEngine.Process())
            {
                // Display results
                Console.WriteLine(ocrEngine.Text);
            }
            // ExEnd:ApplyingCorrectionFilters
        }
Beispiel #56
0
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            // Resource file
            string resourceFilePath = Path.GetFullPath("../../../../../../../Resources/Aspose.OCR.Resources.zip");
            // Source file: the file on which OCR will be performed.
            string imageFile = "Sampleocr.bmp";

            Console.WriteLine("Performing OCR on " + imageFile + "....");

            // Initialize OcrEngine.
            OcrEngine ocr = new OcrEngine();
            // Set the image.
            ocr.Image = ImageStream.FromFile(dataDir + imageFile);
            // Add language.
            ocr.Languages.AddLanguage(Language.Load("english"));
            // Load the resource file.
            using (ocr.Resource = new FileStream(resourceFilePath, FileMode.Open))
            {
                try
                {
                    // Process the whole image
                    if (ocr.Process())
                    {
                        // Get the complete recognized text found from the image
                        Console.WriteLine("Text recognized: " + ocr.Text);
                        File.WriteAllText(dataDir + "Output.txt", ocr.Text.ToString());
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: " + ex.ToString());
                }
            }
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set the Image property by loading the image from file path location or an instance of Stream
            ocrEngine.Image = ImageStream.FromFile(dataDir + "SpanishOCR.bmp");

            //Clear the default language (English)
            ocrEngine.LanguageContainer.Clear();

            //Load the resources of the language from file path location or an instance of Stream
            ocrEngine.LanguageContainer.AddLanguage(LanguageFactory.Load(dataDir+ "Aspose.OCR.Spanish.Resources.zip"));

            //Process the image
            if (ocrEngine.Process())
            {
                //Display the recognized text
                Console.WriteLine(ocrEngine.Text);
            }
        }
        public static void Run()
        {
            // ExStart:UsingNotifierFactory
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_OCR();

            // Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            // Set the Image property by loading the image from file path location or an instance of MemoryStream 
            ocrEngine.Image = ImageStream.FromFile(dataDir + "answers.jpg");

            // Get an instance of WordNotifier, Write a delegate to handle the Elapsed event and Display the recognized text on screen
            INotifier processorBlock = NotifierFactory.BlockNotifier();
            processorBlock.Elapsed += delegate
            {
                Console.WriteLine(processorBlock.Text);                
            };

            // Add the word processor to the OcrEngine and Process the image
            ocrEngine.AddNotifier(processorBlock);
            ocrEngine.Process();
            // ExEnd:UsingNotifierFactory            
        }
        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Aspose.OCR.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            //Initialize an instance of OcrEngine
            OcrEngine ocrEngine = new OcrEngine();

            //Set Image property by loading an image from file path
            ocrEngine.Image = ImageStream.FromFile(dataDir+ "Sampleocr.bmp");

            //Create CorrectionFilters collection
            CorrectionFilters filters = new CorrectionFilters();
            Filter filter = null;

            //Initialize Median filter
            filter = new MedianFilter(5);
            filters.Add(filter);

            //Create Gaussian Blur filter
            filter = new GaussBlurFilter();
            filters.Add(filter);

            //Create Noise Removal filter
            filter = new RemoveNoiseFilter();
            filters.Add(filter);

            //Assign collection to OcrEngine
            ocrEngine.Config.CorrectionFilters = filters;

            //Run recognition process
            if (ocrEngine.Process())
            {
                //Display results
                Console.WriteLine(ocrEngine.Text);
            }
        }