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);
}
|