还有如下使用全局唯一的实例 scanner 可以么?
- Code: Select all
public class OcrAccessor {
private static OcrScanner scanner ;
public static String[] win = new String[]{"libiomp5md.dll","mkldnn.dll"
,"mklml.dll","opencv_world3416.dll","spire_ocrlib.dll","spire_ocrsystem.dll"};
public static String[] linux = new String[]{"libdnnl.so.1","libiomp5.so","libmkldnn.so.0","libmklml_intel.so","libspire_ocrsystem.so"};
private OcrAccessor(){
}
public static void init() {
try{
String[] dependencies;
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("win")) {
dependencies = win;
} else {
dependencies = linux;
}
var path = dependencyPath(dependencies);
log.info("依赖路径:{}",path);
scanner = new OcrScanner();
scanner.setDependencies(path);
}catch (Exception e){
log.error("OCR 初始化失败",e);
}
}
}