-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathProgram.cs
127 lines (106 loc) · 4.65 KB
/
Program.cs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using IronOcr;
using System;
namespace ImageToTextTutorial
{
internal class Program
{
private static void Main(string[] args)
{
Console.WriteLine("Example 1 - AutoOcr Screenshot OCR Example");
Console.WriteLine("------------------------------------------");
Examples.Example1();
Console.WriteLine("Example 2 - Advanced OCR with High Quality Scanned Input");
Console.WriteLine("--------------------------------------------------------");
Examples.Example2();
Console.WriteLine();
Console.WriteLine("Example 2A - Advanced OCR with Low Quality Scanned Input");
Console.WriteLine("--------------------------------------------------------");
Examples.Example2A();
Console.WriteLine();
Console.WriteLine("Example 3 - Crop Areas - Scanning only part of an Image");
Console.WriteLine("-------------------------------------------------------");
Examples.Example3();
Console.WriteLine();
Console.WriteLine("Example 4 - International Languages - Arabic Example ");
Console.WriteLine("-------------------------------------------------------");
Examples.Example4();
Console.WriteLine();
Console.Read();
}
}
internal static class Examples
{
public static void Example1()
{
// AutoOcr automatically detects input image properties and makes
// an educated best guess at the optimal OCR settings.
AutoOcr Ocr = new AutoOcr() { ReadBarCodes = false };
var Results = Ocr.Read("img/Screenshot.png");
Console.WriteLine(Results.Text);
// Check accuracy
Accuracy.Compare(Results, "txt/Example1.txt");
}
public static void Example2()
{
// Advanced OCR with High Quality Scanned Input
var Ocr = new AdvancedOcr()
{
CleanBackgroundNoise = false,
EnhanceContrast = true,
EnhanceResolution = false,
Language = IronOcr.Languages.English.OcrLanguagePack,
Strategy = IronOcr.AdvancedOcr.OcrStrategy.Advanced,
ColorSpace = AdvancedOcr.OcrColorSpace.Color,
DetectWhiteTextOnDarkBackgrounds = false,
InputImageType = AdvancedOcr.InputTypes.Document,
RotateAndStraighten = false,
ReadBarCodes = false,
ColorDepth = 4
};
var Results = Ocr.Read("img/Potter.tiff");
// Check accuracy
Accuracy.Compare(Results, "txt/Example2.txt");
}
public static void Example2A()
{
// Advanced OCR with Low Quality Scanned Input
var Ocr = new AdvancedOcr()
{
CleanBackgroundNoise = true,
EnhanceContrast = true,
EnhanceResolution = true,
Language = IronOcr.Languages.English.OcrLanguagePack,
Strategy = IronOcr.AdvancedOcr.OcrStrategy.Advanced,
ColorSpace = AdvancedOcr.OcrColorSpace.GrayScale,
DetectWhiteTextOnDarkBackgrounds = false,
InputImageType = AdvancedOcr.InputTypes.Document,
RotateAndStraighten = true,
ReadBarCodes = false,
ColorDepth = 4
};
var Results = Ocr.Read("img/Potter.LowQuality.tiff");
Accuracy.Compare(Results, "txt/Example2.txt");
}
public static void Example3()
{
//Crop Areas - Scanning only part of an Image
var Ocr = new AutoOcr();
var Area = new System.Drawing.Rectangle() { X = 215, Y = 1250, Height = 280, Width = 1335 };
var Results = Ocr.Read("img/ComSci.Png", Area);
Console.WriteLine(Results.Text);
// Check accuracy
Accuracy.Compare(Results, "txt/Example3.txt");
}
public static void Example4()
{
//International Languages - Arabic Example
var Ocr = new AutoOcr()
{
Language = IronOcr.Languages.Arabic.OcrLanguagePack
};
var Results = Ocr.Read("img/arabic.gif");
Console.WriteLine("{0} Characters of Arabic Read", Results.Text.Length);
// Note that the .Net Console can not yet display Arabic characters... they all print as question marks.
}
}
}