PaddleHelper.cs
2.1 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
73
74
75
using log4net;
using log4net.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace paddleOCR
{
public class PaddleHelper
{
public static void Init()
{
int code = VisionAPI.eyemInitNNDetector("", ".//yolact_base_169_14550_interrupt.onnx", 550, 550);
VisionAPI.log.Info($"初始化检测器 rtnCode={code}");
VisionAPI.eyemNNDetectorParams(0.15f, 0.45f);
VisionAPI.log.Info($"设置检测参数,{0.15f},{0.45f}");
PaddleSharpAPI.Init();
}
[HandleProcessCorruptedStateExceptions]
public static string StartCPlusOcr(string imgPath)
{
string result = "";
try
{
PaddleSharpAPI.OCRHandle(imgPath, out result);
}
catch (Exception ex)
{
VisionAPI.log.Error("StartCPlusOcr err",ex);
}
finally
{
}
return result;
}
[HandleProcessCorruptedStateExceptions]
public static string StartCPlusOcrRewrite(string imgPath)
{
string result = "";
try
{
PaddleSharpAPI.OCRHandleRewrite(imgPath, out result);
}
catch (Exception ex)
{
VisionAPI.log.Error("StartCPlusOcr err", ex);
}
finally
{
}
return result;
}
static List<T> DeserializeJsonToList<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
List<T> list = o as List<T>;
return list;
}
}
}