forked from nguyenq/VietOCR3.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConsoleApp.cs
91 lines (83 loc) · 2.53 KB
/
ConsoleApp.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
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Drawing;
using VietOCR.NET.Postprocessing;
using VietOCR.NET.Utilities;
namespace VietOCR.NET
{
class ConsoleApp
{
public static void Main(string[] args)
{
new ConsoleApp().PerformOCR(args);
}
void PerformOCR(string[] args)
{
if (args[0] == "-?" || args[0] == "-help" || args.Length == 1 || args.Length >= 8)
{
Console.WriteLine("Usage: vietocr imagefile outputfile [-l lang] [-psm pagesegmode] [hocr]");
return;
}
string outputFormat = "text";
foreach (string arg in args)
{
if ("hocr" == arg)
{
outputFormat = "hocr";
}
//else if ("pdf" == arg)
//{
// outputFormat = "pdf";
//}
else if ("text+" == arg)
{
outputFormat = "text+";
}
}
FileInfo imageFile = new FileInfo(args[0]);
FileInfo outputFile = new FileInfo(args[1]);
if (!imageFile.Exists)
{
Console.WriteLine("Input file does not exist.");
return;
}
string curLangCode = "eng"; //default language
string psm = "3"; // or alternatively, "Auto"; // 3 - Fully automatic page segmentation, but no OSD (default)
if ((args.Length == 4) || (args.Length == 5))
{
if (args[2].Equals("-l"))
{
curLangCode = args[3];
}
else if (args[2].Equals("-psm"))
{
psm = args[3];
}
}
else if ((args.Length == 6) || (args.Length == 7))
{
curLangCode = args[3];
psm = args[5];
try
{
Int16.Parse(psm);
}
catch
{
Console.WriteLine("Invalid input value.");
return;
}
}
try
{
OCRHelper.PerformOCR(imageFile.FullName, outputFile.FullName, curLangCode, psm, outputFormat);
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
}
}
}
}