dotnet-Snippets.com
Snippets: 75 | Registered User: 84 | Visitors online: 13
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Jobs

dotnet Jobs
Google Ads

Sri Lanka .NET 
                Forum Member
Extract Text From a Specific Part of the Image Using Aspose.

Author: Guest
Programming Language: C# Rating:
not yet rated

Views: 236

Description:

This technical tip shows how to Extract Text from Specific Part of the Image. Aspose.OCR for .NET provides OcrEngine class to extract text from a specific part of the image document. The OcrEngine class requires following three items for character recognition:

1. Source Image
2. Language
3. Resource file

Steps to Extract Text from a Specific Recognition Block

Below are the steps to perform OCR on image using OcrEngine class of Aspose.OCR for .NET component.

1. Create an instance of OcrEngine and initialize using default constructor.
2. Set the image file using OcrEngine.Image property on which OCR is to be performed.
3. Add language(s) using OcrEngine.Languages.AddLanguage() method.
4. Set start point, width and height of the recognition block using RecognitionBlock.FromRectangle method.
5. Set the resource file using OcrEngine.Resource property.
6. Call OcrEngine.Process() method to perform OCR on the whole image.
7. If OcrEngine.Process() returns true, then get the recognized text with IRecognitionBlock.Text property.

More about Aspose.OCR for .NET

- Homepage of Aspose.OCR for .NET: http://www.aspose.com/categories/.net-components/aspose.ocr-for-.net/default.aspx




C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
const string resourceFileName = @"2011.07.02 v1.0 Aspose.OCR.Resources.zip";
 
try
{
    //Create OcrEngine instance and assign 
    //image, language and image configuration
    OcrEngine ocrEngine = new OcrEngine();
    ocrEngine.Image = ImageStream.FromFile("Sample.bmp");
 
    ocrEngine.Languages.AddLanguage(Language.Load("english"));
    ocrEngine.Config.NeedRotationCorrection = false;
    ocrEngine.Config.UseDefaultDictionaries = true;
 
    //Select the block to recognize text
    int startX = 0, startY = 0, width = 120, height = 100;
    IRecognitionBlock rectangleBlock = Aspose.OCR.RecognitionBlock.FromRectangle(startX, startY, width, height);
    ocrEngine.AddRecognitionBlock(rectangleBlock);
 
    //Set resource file name and extract OCR text
    using (ocrEngine.Resource = new FileStream(resourceFileName, FileMode.Open))
    {
        try
        {
            if (ocrEngine.Process())
            {
                Console.WriteLine(rectangleBlock.Text.ToString());
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception: " + ex.Message);
        }
    }
    ocrEngine = null;
}
catch (Exception ex)
{
    Console.WriteLine("Exception: " + ex.Message);
}



This Snippets could be interesting for you:
No results available

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)