Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active February 1, 2021 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/dad6b4a35169ed7893fd376e819d7626 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/dad6b4a35169ed7893fd376e819d7626 to your computer and use it in GitHub Desktop.
This Gist contains code snippets from examples of Aspose.OCR for .NET.
This Gist contains code snippets from examples of Aspose.OCR for .NET.
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// Instantiate an instance of license and set the license file through its path
Aspose.OCR.License license = new Aspose.OCR.License();
license.SetLicense("Aspose.OCR.lic");
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// Instantiate an instance of license and set the license through a stream
Aspose.OCR.License license = new Aspose.OCR.License();
license.SetLicense(myStream);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
if (ocr.Process())
{
string resultString = Regex.Match(engine.Text, @"\d+").Value; //regular expression to extract numbers
Console.WriteLine(resultString);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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 3 rectangle blocks to user defined recognition blocks
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(27, 35, 857, 75));
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(899, 104, 552, 63));
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(702, 163, 623, 68));
// 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 page 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);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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 + "SampleSpellingCorrection.jpg");
// Set the DoSpellingCorrection to true
ocr.Config.DoSpellingCorrection = true;
// Perform OCR operation
if (ocr.Process())
{
// Display results
Console.WriteLine(ocr.Text);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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 = false;
if (ocr.Process())
{
// Do processing
Console.WriteLine(ocr.Text);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// 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+ "SampleNumbers.jpg");
// Call the Process method to retrieve the results
ocrEngine.Process();
Console.WriteLine("Output: " + ocrEngine.Text);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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.bmp");
// Set the DetectReadingOrder to true
ocr.Config.DetectReadingOrder = true;
// Perform OCR operation
if (ocr.Process())
{
// Display results
Console.WriteLine(ocr.Text);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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.bmp");
// Set the RemoveNonText to true
ocr.Config.RemoveNonText = true;
// Perform OCR operation
if (ocr.Process())
{
// Display results
Console.WriteLine(ocr.Text);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Create an instance of OcrEngine class
OcrEngine ocr = new OcrEngine();
// Set the DetectTextRegions to true
ocr.Config.DetectTextRegions = true;
// Set the Image property of OcrEngine by reading an image file
ocr.Image = ImageStream.FromFile(dataDir + "Sampleocr.bmp");
// Perform OCR operation on the image
if (ocr.Process())
{
// Display results
Console.WriteLine(ocr.Text);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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 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);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// 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();
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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 + "SampleText.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();
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// Set the auto image resolution detection property
image.AutoDetectResolution = true;
// Instantiate the recognition engine for the template
OmrEngine engine = new OmrEngine(template);
// Extract data. This template has only one page.
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// Load actual result from
Hashtable OmrResult = result.PageData[0];
// Get Collection of Keys
ICollection key = OmrResult.Keys;
foreach (string k in key)
{
Console.WriteLine(k + ": " + OmrResult[k]);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Load template file
OmrTemplate template = OmrTemplate.Load(dataDir + "questions.amr");
// Iterate over the pages in template
foreach (OmrPage page in template.Pages)
{
// Get elements of each page
OmrElementsCollection collection = page.Elements;
// Iterate over the element collection
foreach (Object obj in collection)
{
// Display element name
Console.WriteLine(obj.GetType().ToString());
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// Instantiate the recognition engine for the template
OmrEngine engine = new OmrEngine(template);
// Extract data. This template has only one page.
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// Load actual result from
Hashtable OmrResult = result.PageData[0];
// Get Collection of Keys
ICollection key = OmrResult.Keys;
foreach (string k in key)
{
Console.WriteLine(k + ": " + OmrResult[k]);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// Set resource for TextOcrElement
TextOcrElement.Resource = dataDir + "Aspose.OCR.Spanish.Resources.zip";
// Create an instance of TextOcrElement and initialize it by specifying the location of text and its size in mm
TextOcrElement textElement = new TextOcrElement("OCR Text", new PointF(23.6f, 15.5f), new SizeF(14.6f, 4.7f));
// Add the TextOcrElement to the page element collection
template.Pages[0].Elements.Add(textElement);
// Create an instance of OmrEngine and load the template using file path
OmrEngine engine = new OmrEngine(template);
// Extract OMR data and store the results in an instance of OmrProcessingResults
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// Get all page data into an instance of Hashtable
Hashtable[] pages = result.PageData;
// Loop over all the pages
foreach (Hashtable page in pages)
{
// Display key and value
foreach (string key in page.Keys)
{
Console.WriteLine("key: " + key + ": " + "value: " + page[key]);
}
}
// For complete examples and data files, please go to https://github.com/m-ikramulhaq/Aspose.OCR-for-.NET
// Create an instance of Metered class
Metered matered = new Metered();
// Set public & private keys
matered.SetMeteredKey("publicKeyValue", "privateKeyValue");
// Get consumed quantity before calling any API method
decimal amountBefore = Metered.GetConsumptionQuantity();
// Display value
Console.WriteLine(amountBefore.ToString());
// DO PROCDESSING
// The path to the documents directory
//string dataDir = RunExamples.GetDataDir_OCR();
// Create an instance of OmrEngine and load the template using file path
//OmrEngine omr = new OmrEngine(new OmrTemplate());
//string path = dataDir + "sampleimage.png";
//OmrImage omrImage = OmrImage.Load(path);
////Since upload data is running on another thread, so we need wait some time
//Thread.Sleep(10000);
// Get consumed quantity after calling any API method
decimal amountAfter = Metered.GetConsumptionQuantity();
// Display value
Console.WriteLine(amountAfter.ToString());
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// Get the first page of the template
OmrPage page = template.Pages[0];
// Create an element by passing the name, location and size
GridElement element = new GridElement("grid1", new PointF(10, 20), new SizeF(60, 30));
// Add element to the page
page.Elements.Add(element);
// Create configuration for the element
element.Configuration = new OmrConfig();
// Set the TrimWhitePixels to false
element.Configuration.TrimWhitePixels = false;
// Create an instance of OmrEngine and pass object of OmrTemplate as parameter
OmrEngine engine = new OmrEngine(template);
// Extract the data
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// Define new value of image resolution in decimal format
image.Resolution = 100.0;
// Instantiate the recognition engine for the template
OmrEngine engine = new OmrEngine(template);
// Extract data. This template has only one page.
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// Load actual result from
Hashtable OmrResult = result.PageData[0];
// Get Collection of Keys
ICollection key = OmrResult.Keys;
foreach (string k in key)
{
Console.WriteLine(k + ": " + OmrResult[k]);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// Get the first page of the template
OmrPage page = template.Pages[0];
// Create page configurations
page.Configuration = new OmrConfig();
// Set fill threshold
page.Configuration.FillThreshold = 0.21;
// Create an instance of OmrEngine and pass object of OmrTemplate as parameter
OmrEngine engine = new OmrEngine(template);
// Extract the data
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// Create an instance of OmrEngine and pass object of OmrTemplate as parameter
OmrEngine engine = new OmrEngine(template);
// Get the configurations of OmrEngine
OmrConfig config = engine.Configuration;
// Set fill threshold
config.FillThreshold = 0.12;
// Extract the data
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Calculate Angle
float angle = api.CalculateSkew(dataDir + "skew_image.png");
// Display the result
Console.WriteLine(angle);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
float angle = 0;
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Calculate Angle
using (MemoryStream ms = new MemoryStream())
using (FileStream file = new FileStream(dataDir + "skew_image.png", FileMode.Open, FileAccess.Read))
{
file.CopyTo(ms);
angle = api.CalculateSkew(ms);
}
// Display the result
Console.WriteLine(angle);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// 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);
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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
// Valid license is required for Multiple Recognition Blocks
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(27, 35, 857, 75));
ocrEngine.Config.AddRecognitionBlock(RecognitionBlock.CreateTextBlock(899, 104, 552, 63));
// 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);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// 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);
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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+ "Sample.jpg");
// 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();
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// 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();
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
string templateUrl = "https://Github.com/asposeocr/Aspose_OCR_NET/raw/master/Examples/Data/OCR/questions.amr";
string imageUrl = "https://Github.com/asposeocr/Aspose_OCR_NET/raw/master/Examples/Data/OCR/answers.jpg";
// Initialize an instance of OmrTemplate by loading the OMR template from URL
OmrTemplate template = OmrTemplate.LoadFromUrl(templateUrl);
// image loading from url
OmrImage image = OmrImage.LoadFromUrl(imageUrl);
// continue working with template and image as usual
OmrEngine engine = new OmrEngine(template);
OmrProcessingResult result = engine.ExtractData(new OmrImage[] { image });
// Get all page data into an instance of Hashtable
Hashtable[] pages = result.PageData;
// Loop over all the pages
foreach (Hashtable page in pages)
{
// Display key and value
foreach (string key in page.Keys)
{
Console.WriteLine("[KEY] " + key + " => " + "[VALUE] " + page[key]);
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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);
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Image Path
string fullPath = dataDir + "sample.png";
// Recognize image
RecognitionResult result = api.RecognizeImage(fullPath, new RecognitionSettings
{
DetectAreas = true,
RecognizeSingleLine = false,
AutoSkew = true,
Skew = 0.2F,
Language = Language.en,
});
// Print result
Console.WriteLine($"Text:\n {result.RecognitionText}");
Console.WriteLine("Areas:");
result.RecognitionAreasText.ForEach(a => Console.WriteLine($"{a}"));
Console.WriteLine("Warnings:");
result.Warnings.ForEach(w => Console.WriteLine($"{w}"));
Console.WriteLine($"JSON: {result.GetJson()}");
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
string result = api.RecognizeImage(dataDir + "Sampleocr.bmp");
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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())
{
// Display the recognized text
Console.WriteLine(ocrEngine.Text);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Get image for recognize
string uri = "https://qph.fs.quoracdn.net/main-qimg-0ff82d0dc3543dcd3b06028f5476c2e4";
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
RecognitionResult result = api.RecognizeImageFromUri(uri, new RecognitionSettings
{
DetectAreas = true,
RecognizeSingleLine = false,
AutoSkew = true,
RecognitionAreas = new List<Rectangle>()
{
new Rectangle(1,3,400,70),
new Rectangle(1,72,400,70)
}
});
// Print result
Console.WriteLine($"Text:\n {result.RecognitionText}");
Console.WriteLine("Areas:");
result.RecognitionAreasText.ForEach(a => Console.WriteLine($"{a}"));
Console.WriteLine("Warnings:");
result.Warnings.ForEach(w => Console.WriteLine($"{w}"));
Console.WriteLine($"JSON: {result.GetJson()}");
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
//Create an instance of Document to load the PDF
var pdfDocument = new Aspose.Pdf.Document(dataDir + "Sample.pdf");
//Create an instance of OcrEngine for recognition
var ocrEngine = new Aspose.OCR.OcrEngine();
//Iterate over the pages of PDF
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
//Creating a MemoryStream to hold the image temporarily
using (var imageStream = new System.IO.MemoryStream())
{
//Create Resolution object with DPI value
var resolution = new Aspose.Pdf.Devices.Resolution(300);
//Create JPEG device with specified attributes (Width, Height, Resolution, Quality)
//where Quality [0-100], 100 is Maximum
var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(resolution, 100);
//Convert a particular page and save the image to stream
jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
imageStream.Position = 0;
//Set Image property of OcrEngine to the stream obtained from previous step
ocrEngine.Image = Aspose.OCR.ImageStream.FromStream(imageStream, Aspose.OCR.ImageStreamFormat.Jpg);
//Perform OCR operation on one page at a time
if (ocrEngine.Process())
{
Console.WriteLine(ocrEngine.Text);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
List<Rectangle> rects = new List<Rectangle>()
{
new Rectangle(138, 352, 2033, 537),
new Rectangle(147, 890, 2033, 1157),
new Rectangle(923, 2045, 465, 102),
new Rectangle(104, 2147, 2076, 819)
};
List<string> listResult = api.RecognizeImage(dataDir + "sample.png", rects);
// Display the recognized text
foreach (string s in listResult)
{
Console.WriteLine(s);
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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");
// 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);
}
}
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
string result = "";
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
using (MemoryStream ms = new MemoryStream())
using (FileStream file = new FileStream(dataDir + "sample.png", FileMode.Open, FileAccess.Read))
{
file.CopyTo(ms);
result = api.RecognizeImage(ms);
}
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
string result = api.RecognizeImage(dataDir + "sample.png", false);
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
string result = api.RecognizeImage(dataDir + "sample.png", true, false);
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
string result = api.RecognizeLine(dataDir + "sample_line.png");
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
List<Rectangle> rects = new List<Rectangle>()
{
new Rectangle(138, 352, 2033, 537),
new Rectangle(147, 890, 2033, 1157),
new Rectangle(923, 2045, 465, 102),
new Rectangle(104, 2147, 2076, 819)
};
string result = api.RecognizeImage(dataDir + "sample.png", rects[0]);
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr with allowed symbols
AsposeOcr api = new AsposeOcr("0123456789");
// Recognize image
string result = api.RecognizeLine(dataDir + "0001460985.Jpeg");
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_OCR();
// Initialize an instance of AsposeOcr
AsposeOcr api = new AsposeOcr();
// Recognize image
string result = api.RecognizeImage(dataDir + "SpanishOCR.bmp");
// Display the recognized text
Console.WriteLine(result);
// For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
// 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);
}
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' Instantiate an instance of license and set the license file through its path
Dim license As Aspose.OCR.License = New Aspose.OCR.License()
license.SetLicense("Aspose.OCR.lic")
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' Instantiate an instance of license and set the license through a stream
Dim license As Aspose.OCR.License = New Aspose.OCR.License()
license.SetLicense(myStream)
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
If ocr.Process() Then
Dim resultString As String = Regex.Match(engine.Text, "\d+").Value 'regular expression to extract numbers
Console.WriteLine(resultString)
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OMR()
' Initialize an instance of OcrEngine
Dim ocrEngine As 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 & Convert.ToString("sample1.jpg"))
' Run recognition process
If ocrEngine.Process() Then
' Retrieve user defined blocks that determines the paye layout
Dim blocks = ocrEngine.Config.RecognitionBlocks
' Loop over the list of blocks
For Each block In blocks
' Display if block is set to be recognized
Console.WriteLine(block.ToRecognize)
' Check if block has recognition data
If block.RecognitionData Is Nothing Then
Console.WriteLine("Null{0}", Environment.NewLine)
Continue For
End If
' Display dimension & size of rectangle that defines the recognition block
Console.WriteLine("Block: {0}", block.Rectangle)
If TypeOf block.RecognitionData Is IRecognizedTextPartInfo Then
' Display the recognition results
Dim textPartInfo As IRecognizedTextPartInfo = DirectCast(block.RecognitionData, IRecognizedTextPartInfo)
Console.WriteLine("Text: {0}{1}", textPartInfo.Text, Environment.NewLine)
End If
Next
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As OcrEngine = New OcrEngine()
'Set Image property by loading an image from file path
ocrEngine.Image = ImageStream.FromFile(dataDir & "Sampleocr.bmp")
'Create CorrectionFilters collection
Dim filters As CorrectionFilters = New CorrectionFilters()
Dim filter As Filter = Nothing
'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() Then
'Display results
Console.WriteLine(ocrEngine.Text)
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Create an instance of OcrEngine class
Dim ocr As 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() Then
'Display results
Console.WriteLine(ocr.Text)
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR() + "Sampleocr.bmp"
' Initialize an instance of OcrEngine.
Dim ocr As 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
' Do processing
If ocr.Process() Then
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As New OcrEngine()
'Retrieve the OcrConfig of the OcrEngine object
Dim ocrConfig As OCRConfig = ocrEngine.Config
'Set the Whitelist property to recognize numbers only
ocrConfig.Whitelist = New Char() {"1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c, "0"c}
'Set the Image property of OcrEngine object
ocrEngine.Image = ImageStream.FromFile(dataDir & "Sampleocr.bmp")
'Call the Process method to retrieve the results
ocrEngine.Process()
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Create an instance of OcrEngine class
Dim ocr As New OcrEngine()
'Set the Image property of OcrEngine by reading an image file
ocr.Image = ImageStream.FromFile(dataDir & "Sampleocr.bmp")
'Set the DetectReadingOrder to true
ocr.Config.DetectReadingOrder = True
'Perform OCR operation
If ocr.Process() Then
'Display results
Console.WriteLine(ocr.Text)
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Create an instance of OcrEngine class
Dim ocr As 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() Then
'Display results
Console.WriteLine(ocr.Text)
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Create an instance of OcrEngine class
Dim ocr As New OcrEngine()
'Set the DetectTextRegions to true
ocr.Config.DetectTextRegions = True
'Set the Image property of OcrEngine by reading an image file
ocr.Image = ImageStream.FromFile(dataDir & "Sampleocr.bmp")
'Perform OCR operation on the image
If ocr.Process() Then
'Display results
Console.WriteLine(ocr.Text)
End If
End Sub
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Create an initialize an instance of OcrEngine
Dim engine As New OcrEngine()
' Set the OcrEngine.Image property by loading an image from disk, memory or URL
engine.Image = ImageStream.FromFile(dataDir & Convert.ToString("Sample.bmp"))
' Create text recognition block by supplying X,Y coordinates and Width,Height values
Dim block As IRecognitionBlock = RecognitionBlock.CreateTextBlock(6, 9, 120, 129)
' Set the Whitelist property by specifying a new block whitelist
block.Whitelist = New Char() {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c, "6"c, "7"c, "8"c, "9"c}
' 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() Then
' Display the recognized text from each Page
Console.WriteLine(engine.Text)
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Set the auto image resolution detection property
image.AutoDetectResolution = true;
' Instantiate the recognition engine for the template
Dim engine As New OmrEngine(template)
' Extract data. This template has only one page.
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' Load actual result from
Dim OmrResult As Hashtable = result.PageData(0)
' Get Collection of Keys
Dim key As ICollection = OmrResult.Keys
For Each k As String In key
Console.WriteLine((k & Convert.ToString(": ")) + OmrResult(k))
Next
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Iterate over the pages in template
For Each page As OmrPage In template.Pages
' Get elements of each page
Dim collection As OmrElementsCollection = page.Elements
' Iterate over the element collection
For Each obj As [Object] In collection
' Display element name
Console.WriteLine(obj.[GetType]().ToString())
Next
Next
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Instantiate the recognition engine for the template
Dim engine As New OmrEngine(template)
' Extract data. This template has only one page.
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' Load actual result from
Dim OmrResult As Hashtable = result.PageData(0)
' Get Collection of Keys
Dim key As ICollection = OmrResult.Keys
For Each k As String In key
Console.WriteLine((k & Convert.ToString(": ")) + OmrResult(k))
Next
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Set resource for TextOcrElement
TextOcrElement.Resource = dataDir & Convert.ToString("Aspose.OCR.Spanish.Resources.zip")
' Create an instance of TextOcrElement and initialize it by specifying the location of text and its size in mm
Dim textElement As New TextOcrElement("OCR Text", New PointF(23.6F, 15.5F), New SizeF(14.6F, 4.7F))
' Add the TextOcrElement to the page element collection
template.Pages(0).Elements.Add(textElement)
' Create an instance of OmrEngine and load the template using file path
Dim engine As New OmrEngine(template)
' Extract OMR data and store the results in an instance of OmrProcessingResults
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' Get all page data into an instance of Hashtable
Dim pages As Hashtable() = result.PageData
' Loop over all the pages
For Each page As Hashtable In pages
' Display key and value
For Each key As String In page.Keys
Console.WriteLine((Convert.ToString("key: ") & key) + ": " + "value: " + page(key))
Next
Next
' For complete examples and data files, please go to https://github.com/m-ikramulhaq/Aspose.OCR-for-.NET
' Create an instance of Metered class
Dim matered As New Metered()
' Set public & private keys
matered.SetMeteredKey("publicKeyValue", "privateKeyValue")
' Get consumed quantity before calling any API method
Dim amountBefore As Decimal = Metered.GetConsumptionQuantity()
' Display value
Console.WriteLine(amountBefore.ToString())
' DO PROCDESSING
' The path to the documents directory
'string dataDir = RunExamples.GetDataDir_OCR();
' Create an instance of OmrEngine and load the template using file path
'OmrEngine omr = new OmrEngine(new OmrTemplate());
'string path = dataDir + "sampleimage.png";
'OmrImage omrImage = OmrImage.Load(path);
''Since upload data is running on another thread, so we need wait some time
'Thread.Sleep(10000);
' Get consumed quantity after calling any API method
Dim amountAfter As Decimal = Metered.GetConsumptionQuantity()
' Display value
Console.WriteLine(amountAfter.ToString())
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Get the first page of the template
Dim page As OmrPage = template.Pages(0)
' Create an element by passing the name, location and size
Dim element As New GridElement("grid1", New PointF(10, 20), New SizeF(60, 30))
' Add element to the page
page.Elements.Add(element)
' Create configuration for the element
element.Configuration = New OmrConfig()
' Set the TrimWhitePixels to false
element.Configuration.TrimWhitePixels = False
' Create an instance of OmrEngine and pass object of OmrTemplate as parameter
Dim engine As New OmrEngine(template)
' Extract the data
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Define new value of image resolution in decimal format
image.Resolution = 100.0
' Instantiate the recognition engine for the template
Dim engine As New OmrEngine(template)
' Extract data. This template has only one page.
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' Load actual result from
Dim OmrResult As Hashtable = result.PageData(0)
' Get Collection of Keys
Dim key As ICollection = OmrResult.Keys
For Each k As String In key
Console.WriteLine((k & Convert.ToString(": ")) + OmrResult(k))
Next
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Get the first page of the template
Dim page As OmrPage = template.Pages(0)
' Create page configurations
page.Configuration = New OmrConfig()
' Set fill threshold
page.Configuration.FillThreshold = 0.21
' Create an instance of OmrEngine and pass object of OmrTemplate as parameter
Dim engine As New OmrEngine(template)
' Extract the data
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Create an instance of OmrEngine and pass object of OmrTemplate as parameter
Dim engine As New OmrEngine(template)
' Get the configurations of OmrEngine
Dim config As OmrConfig = engine.Configuration
' Set fill threshold
config.FillThreshold = 0.12
' Extract the data
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
Dim engine As New OmrEngine(New OmrTemplate())
' Get skew degree of the image
Dim degree As Double = engine.GetSkewDegree(image)
' Rotate image to correct skew
engine.RotateImage(image, degree)
' Save image
image.AsBitmap().Save(dataDir & Convert.ToString("result_out.jpg"))
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Load template file
Dim template As OmrTemplate = OmrTemplate.Load(dataDir & Convert.ToString("questions.amr"))
' Load the image to be analyzed
Dim image As OmrImage = OmrImage.Load(dataDir & Convert.ToString("answers.jpg"))
' Area of the image to be processed
Dim area As New Rectangle(0, 0, image.Width, image.Height)
' Grayscale conversion
Dim gs As New GrayscaleAlgorithm()
gs.Process(image, area)
' Binarization
Dim threshold As New AverageThresholdAlgorithm()
threshold.Process(image, area)
' Skew correction
Dim skewCorrection As New SkewCorrectionAlgorithm()
skewCorrection.Process(image, area)
' save image
image.AsBitmap().Save(dataDir & Convert.ToString("result_out.jpg"))
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Initialize an instance of OcrEngine
Dim ocrEngine As 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() Then
' Display text block locations
For Each part As IRecognizedPartInfo In ocrEngine.Text.PartsInfo
Console.WriteLine(part.Box)
Next part
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As 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() Then
Console.WriteLine(ocrEngine.Text)
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As 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() Then
Console.WriteLine(ocrEngine.Text)
'Retrieve an array of recognized text by parts
Dim text() As IRecognizedPartInfo = ocrEngine.Text.PartsInfo
'Iterate over the text parts
For Each symbol As IRecognizedTextPartInfo In text
'Display the part information
Console.WriteLine("Symbol:" & symbol.Text)
'Get the rectangle sourronding the symbol
Dim box As Rectangle = symbol.Box
'Display the rectangle location on the image canvas
Console.WriteLine("Box Location:" & box.Location.ToString())
'Display the rectangle dimensions
Console.WriteLine("Box Size:" & box.Size.ToString())
Next symbol
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OMR()
' Initialize an instance of OcrEngine
Dim ocrEngine As New OcrEngine()
' Set Image property by loading an image from file path
ocrEngine.Image = ImageStream.FromFile(dataDir & Convert.ToString("Sampleocr.bmp"))
' Run recognition process
If ocrEngine.Process Then
Console.WriteLine(ocrEngine.Text)
' Retrieve an array of recognized text by parts
Dim text() As IRecognizedPartInfo = ocrEngine.Text.PartsInfo
' Iterate over the text parts
For Each recognizedPartInfo In text
Dim symbol = CType(recognizedPartInfo, IRecognizedTextPartInfo)
' Display the part information
Console.WriteLine(("Symbol:" + symbol.Text))
' Get the rectangle sourronding the symbol
Dim box As Rectangle = symbol.Box
' Display the rectangle location on the image canvas
Console.WriteLine("Box Location:")
Console.Write(box.Location)
' Display the rectangle dimensions
Console.WriteLine("Box Size:")
Console.Write(box.Size)
Next
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As 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() Then
'Retrieve the first block of the recognized text part
Dim firstBlock As IRecognizedTextPartInfo = (TryCast(ocrEngine.Text.PartsInfo(0), IRecognizedTextPartInfo))
'Get the children of the first block that will the the lines in the block
Dim linesOfFirstBlock() As IRecognizedPartInfo = firstBlock.Children
'Retrieve the fist line from the collection of lines
Dim firstLine As IRecognizedTextPartInfo = (TryCast(linesOfFirstBlock(0), IRecognizedTextPartInfo))
'Display the level of line
Console.WriteLine(firstLine.Level.ToString())
'Retrieve the fist word from the collection of words
Dim firstWord As IRecognizedTextPartInfo = (TryCast(firstLine.Children(0), IRecognizedTextPartInfo))
'Display the level of word
Console.WriteLine(firstWord.Level.ToString())
'Retrieve the fist character from the collection of characters
Dim firstCharacter As IRecognizedTextPartInfo = (TryCast(firstWord.Children(0), IRecognizedTextPartInfo))
'Display the level of character
Console.WriteLine(firstCharacter.Level.ToString())
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As 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")
Dim processorWord As INotifier = NotifierFactory.WordNotifier()
AddHandler processorWord.Elapsed, AddressOf [Delegate]
' Add the word processor to the OcrEngine
ocrEngine.AddNotifier(processorWord)
'Process the image
ocrEngine.Process()
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
Dim templateUrl As String = "https://Github.com/asposeocr/Aspose_OCR_NET/raw/master/Examples/Data/OCR/questions.amr"
Dim imageUrl As String = "https://Github.com/asposeocr/Aspose_OCR_NET/raw/master/Examples/Data/OCR/answers.jpg"
' Initialize an instance of OmrTemplate by loading the OMR template from URL
Dim template As OmrTemplate = OmrTemplate.LoadFromUrl(templateUrl)
' image loading from url
Dim image As OmrImage = OmrImage.LoadFromUrl(imageUrl)
' continue working with template and image as usual
Dim engine As OmrEngine = New OmrEngine(template)
Dim result As OmrProcessingResult = engine.ExtractData(New OmrImage() {image})
' Get all page data into an instance of Hashtable
Dim pages() As Hashtable = result.PageData
' Loop over all the pages
For Each page As Hashtable In pages
' Display key and value
For Each key As String In page.Keys
Console.WriteLine(("[KEY] " _
+ (key + (" => " + ("[VALUE] " + page(key))))))
Next
Next
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR() + "SampleTiff.tiff"
' Create an initialize an instance of OcrEngine
Dim engine As 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() Then
' Retrieve the list of Pages
Dim pages As Page() = engine.Pages
' Iterate over the list of Pages
For Each page As Page In pages
' Display the recognized text from each Page
Console.WriteLine(page.PageText)
Next
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
' Source file: the file on which OCR will be performed.
Dim imageFile As String = dataDir & "Sampleocr.bmp"
Console.WriteLine("Performing OCR on " & imageFile & "....")
' Initialize OcrEngine.
Dim ocr As New OcrEngine()
' Set the image.
ocr.Image = ImageStream.FromFile(imageFile)
Try
' Process the whole image
If ocr.Process() Then
' Get the complete recognized text found from the image
Console.WriteLine("Text recognized: " & ocr.Text.ToString())
File.WriteAllText(dataDir & "Output.txt", ocr.Text.ToString())
End If
Catch ex As Exception
Console.WriteLine("Exception: " & ex.ToString())
End Try
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As 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() Then
Console.WriteLine(ocrEngine.Text)
' Retrieve an array of recognized text by parts
Dim text() As IRecognizedPartInfo = ocrEngine.Text.PartsInfo
' Iterate over the text parts
For Each symbol As IRecognizedTextPartInfo In text
' Display part intomation
Console.WriteLine("Text : " & symbol.Text)
Console.WriteLine("isItalic : " & symbol.Italic)
Console.WriteLine("Language : " & symbol.Language)
Next symbol
End If
' For complete examples and data files, please go to https://github.com/aspose-ocr/Aspose.OCR-for-.NET
' The path to the documents directory.
Dim dataDir As String = RunExamples.GetDataDir_OCR()
'Initialize an instance of OcrEngine
Dim ocrEngine As 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() Then
'Display the recognized text
Console.WriteLine(ocrEngine.Text)
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment