Skip to content

Commit

Permalink
Merge pull request #76 from litongjava/rapidocr-onnx
Browse files Browse the repository at this point in the history
Rapidocr onnx
  • Loading branch information
litongjava authored Apr 28, 2024
2 parents cf4f967 + e40f8d7 commit 98c12ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/luooqi/ocr/local/PaddlePaddleOCRV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import io.github.mymonstercat.Model;
import io.github.mymonstercat.ocr.InferenceEngine;
import io.github.mymonstercat.ocr.config.HardwareConfig;

/**
* Created by [email protected] on 11/23/2023_2:09 AM
Expand All @@ -21,14 +22,15 @@ public enum PaddlePaddleOCRV4 {

// noting not to do.but init
public static void init() {
engine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4_SERVER);
HardwareConfig onnxConfig = HardwareConfig.getOnnxConfig();
onnxConfig.setNumThread(2);
engine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4_SERVER, onnxConfig);
}

public OcrResult ocr(File imageFile) {
return engine.runOcr(imageFile.getAbsolutePath());
}

public void close() {

}
}
12 changes: 10 additions & 2 deletions src/test/java/com/litongjava/RapidOcrTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@

import io.github.mymonstercat.Model;
import io.github.mymonstercat.ocr.InferenceEngine;
import io.github.mymonstercat.ocr.config.HardwareConfig;

public class RapidOcrTest {
public static void main(String[] args) {
InferenceEngine engine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4_SERVER);
OcrResult ocrResult = engine.runOcr("images/01.png");
String imagePath = "C:\\Users\\Administrator\\Desktop\\01.jpg";

// init
HardwareConfig onnxConfig = HardwareConfig.getOnnxConfig();
onnxConfig.setNumThread(2);
InferenceEngine engine = InferenceEngine.getInstance(Model.ONNX_PPOCR_V4_SERVER, onnxConfig);

// run
OcrResult ocrResult = engine.runOcr(imagePath);
System.out.println(ocrResult.getStrRes().trim());
}
}

0 comments on commit 98c12ae

Please sign in to comment.