/
Programa.cs
46 lines (43 loc) · 1.37 KB
/
Programa.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
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using journeyofcode.Images.OnenoteOCR;
namespace OcrToText
{
class Programa
{
static void Main(string[] args)
{
var imagePath = args.FirstOrDefault();
if (String.IsNullOrWhiteSpace(imagePath) || !File.Exists(args[0]))
{
Console.WriteLine("Passo: {0} [Caminho do Arquivo de Imagem]", Path.GetFileName(Assembly.GetAssembly(typeof(Program)).CodeBase));
return;
}
Console.WriteLine("Execução do OCR para Arquivo " + imagePath);
try
{
using (var ocrEngine = new OnenoteOcrEngine())
using (var image = Image.FromFile(imagePath))
{
var text = ocrEngine.Recognize(image);
if (text == null)
Console.WriteLine("Não reconhecido");
else
Console.WriteLine("Reconhecido: " + text);
}
}
catch (OcrException ex)
{
Console.WriteLine("Excessão de OCR:\n" + ex);
}
catch (Exception ex)
{
Console.WriteLine("Excessão Geral:\n" + ex);
}
Console.ReadLine();
}
}
}