File tree 2 files changed +14
-4
lines changed
main/java/com/luooqi/ocr/local
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change 6
6
7
7
import io .github .mymonstercat .Model ;
8
8
import io .github .mymonstercat .ocr .InferenceEngine ;
9
+ import io .github .mymonstercat .ocr .config .HardwareConfig ;
9
10
10
11
/**
11
12
* Created by [email protected] on 11/23/2023_2:09 AM
@@ -21,14 +22,15 @@ public enum PaddlePaddleOCRV4 {
21
22
22
23
// noting not to do.but init
23
24
public static void init () {
24
- engine = InferenceEngine .getInstance (Model .ONNX_PPOCR_V4_SERVER );
25
+ HardwareConfig onnxConfig = HardwareConfig .getOnnxConfig ();
26
+ onnxConfig .setNumThread (2 );
27
+ engine = InferenceEngine .getInstance (Model .ONNX_PPOCR_V4_SERVER , onnxConfig );
25
28
}
26
29
27
30
public OcrResult ocr (File imageFile ) {
28
31
return engine .runOcr (imageFile .getAbsolutePath ());
29
32
}
30
33
31
34
public void close () {
32
-
33
35
}
34
36
}
Original file line number Diff line number Diff line change 4
4
5
5
import io .github .mymonstercat .Model ;
6
6
import io .github .mymonstercat .ocr .InferenceEngine ;
7
+ import io .github .mymonstercat .ocr .config .HardwareConfig ;
7
8
8
9
public class RapidOcrTest {
9
10
public static void main (String [] args ) {
10
- InferenceEngine engine = InferenceEngine .getInstance (Model .ONNX_PPOCR_V4_SERVER );
11
- OcrResult ocrResult = engine .runOcr ("images/01.png" );
11
+ String imagePath = "C:\\ Users\\ Administrator\\ Desktop\\ 01.jpg" ;
12
+
13
+ // init
14
+ HardwareConfig onnxConfig = HardwareConfig .getOnnxConfig ();
15
+ onnxConfig .setNumThread (2 );
16
+ InferenceEngine engine = InferenceEngine .getInstance (Model .ONNX_PPOCR_V4_SERVER , onnxConfig );
17
+
18
+ // run
19
+ OcrResult ocrResult = engine .runOcr (imagePath );
12
20
System .out .println (ocrResult .getStrRes ().trim ());
13
21
}
14
22
}
You can’t perform that action at this time.
0 commit comments