61 lines
2.2 KiB
Java
61 lines
2.2 KiB
Java
import com.chinaweal.youfool.reportdetect.modules.ocr.service.OcrService;
|
|
import com.chinaweal.youfool.reportdetect.modules.ocr.service.LayoutDetectionService;
|
|
import com.chinaweal.youfool.reportdetect.modules.task.entity.OCRResult;
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import java.io.File;
|
|
import java.lang.reflect.Field;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
|
|
public class ManualTest {
|
|
public static void main(String[] args) throws Exception {
|
|
System.out.println("Starting Manual Batch Verification...");
|
|
|
|
// 1. Setup Services
|
|
LayoutDetectionService layoutService = new LayoutDetectionService();
|
|
layoutService.init();
|
|
|
|
OcrService ocrService = new OcrService();
|
|
ocrService.setVizPath("viz_manual_batch");
|
|
|
|
Field layoutServiceField = OcrService.class.getDeclaredField("layoutService");
|
|
layoutServiceField.setAccessible(true);
|
|
layoutServiceField.set(ocrService, layoutService);
|
|
|
|
ocrService.init();
|
|
|
|
// 2. Load results.json
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
JsonNode rootNode = mapper.readTree(new File("src/test/resources/data/results.json"));
|
|
|
|
File pdfDir = new File("src/test/resources/data/pdfs");
|
|
|
|
int count = 0;
|
|
Iterator<Map.Entry<String, JsonNode>> fields = rootNode.fields();
|
|
|
|
System.out.println("Processing first 20 PDFs...");
|
|
while (fields.hasNext() && count < 20) {
|
|
Map.Entry<String, JsonNode> entry = fields.next();
|
|
String pdfName = entry.getKey();
|
|
File pdfFile = new File(pdfDir, pdfName);
|
|
|
|
if (pdfFile.exists()) {
|
|
System.out.println("[" + (count + 1) + "/20] Processing: " + pdfName);
|
|
try {
|
|
ocrService.runOcr(pdfFile.getAbsolutePath());
|
|
} catch (Exception e) {
|
|
System.err.println("Error processing " + pdfName + ": " + e.getMessage());
|
|
e.printStackTrace();
|
|
}
|
|
count++;
|
|
}
|
|
}
|
|
|
|
System.out.println("Batch Verification Complete. Results in viz_manual_batch/");
|
|
}
|
|
}
|