-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOCRProcess.cs
More file actions
72 lines (68 loc) · 2.42 KB
/
Copy pathOCRProcess.cs
File metadata and controls
72 lines (68 loc) · 2.42 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using Tesseract;
using UglyToad.PdfPig.DocumentLayoutAnalysis.Export;
namespace testApps.Libs
{
public class OCRProcess
{
public static string GetOCRFromText(string filepath)
{
string ocrText = "";
using (var ocrEngine = new TesseractEngine(@"./tessdata/ltsm", "tur", EngineMode.LstmOnly))
{
using (var img = Pix.LoadFromFile(filepath))
{
var result = ocrEngine.Process(img);
ocrText += result.GetText();
}
}
return ocrText;
}
public static void SearchablePdfCreateFromJpegs(string[] inputNames, string outputName, string dil)
{
using (IResultRenderer renderer = Tesseract.PdfResultRenderer.CreatePdfRenderer(outputName, @"./tessdata/ltsm", false))
{
// PDF Title
using (renderer.BeginDocument(outputName))
{
using (TesseractEngine engine = new TesseractEngine(@"./tessdata/ltsm", dil, EngineMode.LstmOnly))
{
foreach (string inputName in inputNames)
{
using (Pix img = Pix.LoadFromFile(inputName))
{
using (var page = engine.Process(img, inputName))
{
renderer.AddPage(page);
}
}
}
}
}
}
}
public static string GetOCRFromTextMulti(string[] filepath)
{
string ocrText = "";
using (var ocrEngine = new TesseractEngine(@"./tessdata/ltsm", "tur", EngineMode.LstmOnly))
{
foreach (var file in filepath)
{
using (var img = Pix.LoadFromFile(file))
{
using (var result = ocrEngine.Process(img))
{
ocrText += result.GetText();
}
}
}
}
return ocrText;
}
}
}