ocr_recognition/src/main/java/com/ytlk/fusion/test.java

47 lines
1.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.ytlk.fusion;
import com.alibaba.fastjson.JSONObject;
import java.io.*;
/**
* @className:test
* @author:cwchen
* @date:2025-04-16-9:06
* @version:1.0
* @description:
*/
public class test {
public static void main(String[] args) {
try {
// 创建ProcessBuilder
String python = "D:\\miniconda3\\envs\\ocr\\python.exe";
String pythonScript = new File("C:\\Users\\10488\\Desktop\\ocr-release\\main.py").getAbsolutePath();
String param1 = "C:\\Users\\10488\\Desktop\\1.pdf";
String param2 = "C:\\Users\\10488\\Desktop\\test (2)";
ProcessBuilder pb = new ProcessBuilder(
python,
pythonScript,
"--input", param1,
"--output", param2
);
pb.directory(new File("C:\\Users\\10488\\Desktop\\ocr-release"));
Process p = pb.start();
// 读取输出
BufferedReader reader = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// 等待进程结束
int exitCode = p.waitFor();
System.out.println("Python脚本执行完毕退出码: " + exitCode);
} catch (Exception e) {
e.printStackTrace();
}
}
}