Fork me on GitHub

java实现文档图片版面检测分析

利用java实现版面检测

利用java加载yolov8模型,进行推理,以及前后处理均以java实现。

项目地址:https://github.com/jiangnanboy/layout_analysis4j

模型推理

本项目根据开源中文版面数据CDLA ,利用yolov8进行训练

CDLA是一个中文文档版面分析数据集,面向中文文献类(论文)场景。包含以下10个label:

正文标题图片图片标题表格表格标题页眉页脚注释公式
Text Title Figure Figure caption Table Table caption Header Footer Reference Equation

推理:src/main/java/sy

public static void main(String...args) {
        String modelPath = MainTest.class.getClassLoader().getResource(PropertiesReader.get("model_path")).getPath().replaceFirst("/", "");
        String labelPath = MainTest.class.getClassLoader().getResource(PropertiesReader.get("table_det_labels_path")).getPath().replaceFirst("/", "");
        String imgPath = "D:\\project\\idea_workspace\\layout_analysis4j\\img\\test.webp";

        try {
            ModelDet modelDet = new ModelDet(modelPath, labelPath);
            Mat img = Imgcodecs.imread(imgPath);
            if (img.dataAddr() == 0) {
                System.out.println("Could not open image: " + imgPath);
                System.exit(1);
            }
            // run detection
            try {
                List<Detection> detectionList = modelDet.detectObjects(img);

                ImageUtil.drawPredictions(img, detectionList);
                System.out.println(JSON.toJSONString(detectionList));
                Imgcodecs.imwrite("D:\\project\\idea_workspace\\layout_analysis4j\\img\\prediction.jpg", img);
            } catch (OrtException ortException) {
                ortException.printStackTrace();
            }

        } catch (OrtException e) {
            e.printStackTrace();
        }
    }
posted @ 2023-05-05 21:58  石头木  阅读(285)  评论(0编辑  收藏  举报