7
7
import java .nio .charset .Charset ;
8
8
9
9
public final class OcrEngine {
10
- /**
11
- * 图像外接白框,用于提升识别率,文字框没有正确框住所有文字时,增加此值。
12
- */
13
- private int padding ;
14
- /**
15
- * 文字框置信度门限,文字框没有正确框住所有文字时,减小此值
16
- */
17
- private float boxScoreThresh ;
18
-
19
- private float boxThresh ;
20
- /**
21
- * 单个文字框大小倍率,越大时单个文字框越大
22
- */
23
- private float unClipRatio ;
24
- /**
25
- * 启用(1)/禁用(0) 文字方向检测,只有图片倒置的情况下(旋转90~270度的图片),才需要启用文字方向检测
26
- */
27
- private boolean doAngle ;
28
- /**
29
- * 启用(1)/禁用(0) 角度投票(整张图片以最大可能文字方向来识别),当禁用文字方向检测时,此项也不起作用
30
- */
31
- private boolean mostAngle ;
32
-
33
- public native boolean setNumThread (int numThread );
34
-
35
- public native void initLogger (boolean isConsole , boolean isPartImg , boolean isResultImg );
36
-
37
- public native void enableResultText (String imagePath );
38
-
39
- public native boolean initModels (String modelsDir , String detName , String clsName , String recName , String keysName );
40
-
41
- /**
42
- * GPU0一般为默认GPU,参数选项:使用CPU(-1)/使用GPU0(0)/使用GPU1(1)/...
43
- */
44
- public native void setGpuIndex (int gpuIndex );
45
-
46
- public native String getVersion ();
47
-
48
- public native OcrResult detect (String input , int padding , int maxSideLen , float boxScoreThresh , float boxThresh , float unClipRatio , boolean doAngle , boolean mostAngle );
49
-
50
- public OcrEngine () {
51
- try {
52
- StaticLog .info ("java.library.path=" + System .getProperty ("java.library.path" ));
53
- System .loadLibrary ("RapidOcrNcnn" );
54
- } catch (Exception e ) {
55
- e .printStackTrace ();
56
- }
57
- this .padding = 15 ;
58
- this .boxScoreThresh = 0.25f ;
59
- this .boxThresh = 0.3f ;
60
- this .unClipRatio = 1.6f ;
61
- this .doAngle = true ;
62
- this .mostAngle = true ;
63
- }
64
-
65
- public int getPadding () {
66
- return this .padding ;
67
- }
68
-
69
- public void setPadding (int i ) {
70
- this .padding = i ;
71
- }
72
-
73
- public float getBoxScoreThresh () {
74
- return this .boxScoreThresh ;
75
- }
76
-
77
- public void setBoxScoreThresh (float f ) {
78
- this .boxScoreThresh = f ;
79
- }
80
-
81
- public float getBoxThresh () {
82
- return this .boxThresh ;
83
- }
84
-
85
- public void setBoxThresh (float f ) {
86
- this .boxThresh = f ;
87
- }
88
-
89
- public float getUnClipRatio () {
90
- return this .unClipRatio ;
91
- }
92
-
93
- public void setUnClipRatio (float f ) {
94
- this .unClipRatio = f ;
95
- }
96
-
97
- public boolean getDoAngle () {
98
- return this .doAngle ;
99
- }
100
-
101
- public void setDoAngle (boolean z ) {
102
- this .doAngle = z ;
103
- }
104
-
105
- public boolean getMostAngle () {
106
- return this .mostAngle ;
107
- }
108
-
109
- public void setMostAngle (boolean z ) {
110
- this .mostAngle = z ;
111
- }
112
-
113
- public OcrResult detect (String input ) {
114
- return detect (input , 0 );
115
- }
116
-
117
- public OcrResult detect (String input , int maxSideLen ) {
118
- return detect (input , this .padding , maxSideLen , this .boxScoreThresh , this .boxThresh , this .unClipRatio , this .doAngle , this .mostAngle );
10
+ /**
11
+ * 图像外接白框,用于提升识别率,文字框没有正确框住所有文字时,增加此值。
12
+ */
13
+ private int padding ;
14
+ /**
15
+ * 文字框置信度门限,文字框没有正确框住所有文字时,减小此值
16
+ */
17
+ private float boxScoreThresh ;
18
+
19
+ private float boxThresh ;
20
+ /**
21
+ * 单个文字框大小倍率,越大时单个文字框越大
22
+ */
23
+ private float unClipRatio ;
24
+ /**
25
+ * 启用(1)/禁用(0) 文字方向检测,只有图片倒置的情况下(旋转90~270度的图片),才需要启用文字方向检测
26
+ */
27
+ private boolean doAngle ;
28
+ /**
29
+ * 启用(1)/禁用(0) 角度投票(整张图片以最大可能文字方向来识别),当禁用文字方向检测时,此项也不起作用
30
+ */
31
+ private boolean mostAngle ;
32
+
33
+ public native boolean setNumThread (int numThread );
34
+
35
+ public native void initLogger (boolean isConsole , boolean isPartImg , boolean isResultImg );
36
+
37
+ public native void enableResultText (String imagePath );
38
+
39
+ public native boolean initModels (String modelsDir , String detName , String clsName , String recName , String keysName );
40
+
41
+ /**
42
+ * GPU0一般为默认GPU,参数选项:使用CPU(-1)/使用GPU0(0)/使用GPU1(1)/...
43
+ */
44
+ public native void setGpuIndex (int gpuIndex );
45
+
46
+ public native String getVersion ();
47
+
48
+ public native OcrResult detect (String input , int padding , int maxSideLen , float boxScoreThresh , float boxThresh , float unClipRatio , boolean doAngle , boolean mostAngle );
49
+
50
+ public OcrEngine () {
51
+ try {
52
+ StaticLog .info ("java.library.path=" + System .getProperty ("java.library.path" ));
53
+ System .loadLibrary ("RapidOcrNcnn" );
54
+ } catch (Exception e ) {
55
+ e .printStackTrace ();
119
56
}
57
+ this .padding = 15 ;
58
+ this .boxScoreThresh = 0.25f ;
59
+ this .boxThresh = 0.3f ;
60
+ this .unClipRatio = 1.6f ;
61
+ this .doAngle = true ;
62
+ this .mostAngle = true ;
63
+ }
64
+
65
+ public int getPadding () {
66
+ return this .padding ;
67
+ }
68
+
69
+ public void setPadding (int i ) {
70
+ this .padding = i ;
71
+ }
72
+
73
+ public float getBoxScoreThresh () {
74
+ return this .boxScoreThresh ;
75
+ }
76
+
77
+ public void setBoxScoreThresh (float f ) {
78
+ this .boxScoreThresh = f ;
79
+ }
80
+
81
+ public float getBoxThresh () {
82
+ return this .boxThresh ;
83
+ }
84
+
85
+ public void setBoxThresh (float f ) {
86
+ this .boxThresh = f ;
87
+ }
88
+
89
+ public float getUnClipRatio () {
90
+ return this .unClipRatio ;
91
+ }
92
+
93
+ public void setUnClipRatio (float f ) {
94
+ this .unClipRatio = f ;
95
+ }
96
+
97
+ public boolean getDoAngle () {
98
+ return this .doAngle ;
99
+ }
100
+
101
+ public void setDoAngle (boolean z ) {
102
+ this .doAngle = z ;
103
+ }
104
+
105
+ public boolean getMostAngle () {
106
+ return this .mostAngle ;
107
+ }
108
+
109
+ public void setMostAngle (boolean z ) {
110
+ this .mostAngle = z ;
111
+ }
112
+
113
+ public OcrResult detect (String input ) {
114
+ return detect (input , 0 );
115
+ }
116
+
117
+ public OcrResult detect (String input , int maxSideLen ) {
118
+ return detect (input , this .padding , maxSideLen , this .boxScoreThresh , this .boxThresh , this .unClipRatio , this .doAngle , this .mostAngle );
119
+ }
120
120
}
0 commit comments