2026/4/16 11:33:14
网站建设
项目流程
代码模版 网站,网页游戏制作软件,仿淘宝网站制作,网站认证中心官网在 OCR 技术落地过程中#xff0c;Java 开发者常面临 Python 生态繁荣#xff0c;Java 集成困难 的困境 —— 要么依赖jni调用 exe/dll 外部文件#xff0c;要么跨平台部署踩坑不断。
JiaJiaOCR 为您带来革命性突破#xff01; #x1f389;
本项目将同步更…在 OCR 技术落地过程中Java 开发者常面临Python 生态繁荣Java 集成困难的困境 —— 要么依赖jni调用 exe/dll 外部文件要么跨平台部署踩坑不断。JiaJiaOCR 为您带来革命性突破本项目将同步更新升级轻量级版本和全功能版本版本大小核心功能适用场景 轻量版 (1.0)21MB通用OCR识别快速集成、资源受限环境⚡ 全功能版 (2.0)200MB通用OCR手写OCR版面检测表格识别企业级应用、复杂文档处理 版本更新速览 轻量版 (1.0) - 精简高效✅v1.0.1- 优化英文OCR空白识别 → 返回空串而非null✅v1.0.2- 新增PDF识别支持⚡ 全功能版 (2.0) - 功能全面✅v2.0.1- 优化英文OCR空白识别 → 返回空串而非null✅v2.0.2- 新增PDF识别支持性能提升40%- 模型懒加载机制按需加载功能扩容- 新增手写OCR、版面检测、表格检测与识别结果升级- 新增版面元素坐标、表格HTML格式输出 四大核心功能详解1. 通用OCR印刷体识别标杆延续 1.0 版本的高精度印刷体识别能力支持中英文、数字、符号混合识别返回文本内容与坐标适用于发票、标签、广告牌等印刷体场景。2. ✍️ 手写OCR突破手写识别难点新增针对中文手写体的专项优化模型支持工整手写、连笔手写等常见手写风格解决手写笔记数字化、手写表单录入等痛点识别准确率达92% 以上标准手写样本测试。3. 版面检测文档结构智能解析可自动识别文档中的标题、段落、图片、表格等版面元素返回各元素的坐标与类型标签为文档结构化处理提供基础适用于 PDF 转 Word、古籍数字化等场景。4. 表格检测与识别结构化数据直接提取业内少有的纯 Java 表格识别方案支持表格区域检测、单元格分割、内容识别全流程最终输出 HTML 格式的结构化结果可直接渲染为表格或导入 Excel彻底告别手动录入表格数据的繁琐。️ 快速上手5分钟集成教程 环境准备开发环境JDK 8 及以上版本运行环境Windows 10、Linux x86_64依赖管理Maven推荐 引入依赖与 Jar 包第一步添加 Maven 依赖dependencies !-- ONNX Runtime模型推理核心依赖 -- dependency groupIdcom.microsoft.onnxruntime/groupId artifactIdonnxruntime/artifactId version1.19.0/version /dependency !-- DJL MXNet引擎深度学习框架支持 -- dependency groupIdai.djl.mxnet/groupId artifactIdmxnet-engine/artifactId version0.31.0/version /dependency !-- OpenCV图像处理依赖 -- dependency groupIdai.djl.opencv/groupId artifactIdopencv/artifactId version0.31.0/version /dependency !-- DJL核心API模型管理 -- dependency groupIdai.djl/groupId artifactIdapi/artifactId version0.31.0/version /dependency !-- 操作pdf -- dependency groupIdorg.apache.pdfbox/groupId artifactIdpdfbox/artifactId version3.0.2/version /dependency /dependencies第二步下载核心 Jar 包前往 GitHub 仓库JiaJiaOCR releases 页面下载 JiaJiaOCR 2.0 版本的 jar 包放入项目依赖目录并引入。该 Jar 包 200MB集成了模型文件。【下载地址https://github.com/jiangnanboy/JiaJiaOCR】JiaJiaOCR 1.0只需使用通用OCR及PDF识别功能即可。 完整功能示例代码import com.jiajia.common_object.*; import com.jiajia.core.JiaJiaOCR; import org.apache.commons.lang3.tuple.Pair; import org.opencv.core.Mat; import org.opencv.core.MatOfPoint; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; import java.util.ArrayList; import java.util.List; import static com.jiajia.common_object.PdfConvert.convertPdfToImages; /** * JiaJiaOCR 2.0 全功能示例 * author sy * date 2025/12/4 19:56 */ public class JiaJiaOCR2Demo { public static void main(String...args) { String imgPath test.jpg; // 替换为你的图片路径 // 按需解锁功能注释解开即可使用 // generalOCRTest(imgPath); // 1.通用OCR印刷体 // handwrittingOCRTest(imgPath); // 2.手写OCR // layoutDetTest(imgPath); // 3.版面检测带可视化 // tableDetTest(imgPath); // 4.表格检测带可视化 // tableRecTest(imgPath); // 5.表格识别输出HTML // tableDetRecTest(imgPath); // 6.表格检测识别一站式 // textLineDetText(imgPath); // 7.文本行检测带可视化 // pdfOCR(); // 8.这是pdf识别示例 } /** * 1. 通用OCR印刷体识别 * param imgPath 图片路径 */ public static void generalOCRTest(String imgPath) { // 懒加载初始化此时不加载任何模型 JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); // 调用功能时才加载对应模型 ListPairText, Box result jiaJiaOCR.recognizeGeneralText(imgPath); // 输出文本内容四边形坐标 System.out.println(通用OCR结果 result); } /** * 2. 手写OCR识别 * param imgPath 图片路径 */ public static void handwrittingOCRTest(String imgPath) { JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); ListPairText, Box result jiaJiaOCR.recognizeHandwrittenText(imgPath); System.out.println(手写OCR结果 result); } /** * 3. 版面检测识别标题/段落/表格等元素带可视化 * param imgPath 图片路径 */ public static void layoutDetTest(String imgPath) { JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); ListLayout layoutList jiaJiaOCR.detectLayout(imgPath); // 可视化检测结果并保存 Mat img Imgcodecs.imread(imgPath); drawLayoutPredictions(img, layoutList); Imgcodecs.imwrite(layout_result.jpg, img); System.out.println(版面检测结果已保存元素信息 layoutList); } /** * 4. 表格检测仅检测表格区域带可视化 * param imgPath 图片路径 */ public static void tableDetTest(String imgPath) { JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); ListDetectionResult tableList jiaJiaOCR.detectTables(imgPath); // 可视化表格区域 Mat img Imgcodecs.imread(imgPath); Mat resultMat drawTableResults(img, tableList); Imgcodecs.imwrite(table_detect_result.jpg, resultMat); System.out.println(表格检测区域 tableList); } /** * 5. 表格识别基于通用OCR结果提取表格结构输出HTML * param imgPath 图片路径 */ public static void tableRecTest(String imgPath) { JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); // 先获取通用OCR结果 ListPairText, Box ocrResult jiaJiaOCR.recognizeGeneralText(imgPath); // 基于OCR结果提取表格结构 TableResult tableResult jiaJiaOCR.recognizeTableFromOCR(imgPath, ocrResult); // 输出HTML格式可直接渲染 System.out.println(表格识别HTML结果 tableResult.getHtmlContent()); } /** * 6. 表格检测识别一站式调用 * param imgPath 图片路径 */ public static void tableDetRecTest(String imgPath) { JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); // 一步获取表格结构化结果 ListTableResult tableResults jiaJiaOCR.recognizeTables(imgPath); for (TableResult table : tableResults) { System.out.println(表格HTML table.getHtmlContent()); System.out.println(表格坐标 table.getBox()); } } /** * 7. 文本行检测带可视化 * param imgPath 图片路径 */ public static void textLineDetText(String imgPath) { JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); Boxes textLines jiaJiaOCR.detectTextLines(imgPath); // 可视化文本行 Mat img Imgcodecs.imread(imgPath); drawTextLinePredictions(img, textLines); Imgcodecs.imwrite(textline_result.jpg, img); System.out.println(文本行检测结果 textLines); } /** * 8. pdf识别 */ public static void pdfOCR() throws IOException, OrtException { String pdfPath How_To.pdf; String pdfOutputDir pdf_image; // pdf转为图片的保存目录 JiaJiaOCR jiaJiaOCR JiaJiaOCR.builder(); ListString pdfPathList convertPdfToImages(pdfPath, pdfOutputDir); for(String pdfImgPath:pdfPathList) { ListPairText, Box pairList jiaJiaOCR.recognizeGeneralText(pdfImgPath); System.out.println(pairList); } } // ------------------- 可视化工具方法 ------------------- /** * 绘制版面检测结果 */ public static void drawLayoutPredictions(Mat img, ListLayout detLayout) { for(Layout layout : detLayout) { int[] bbox layout.getBbox(); // 绘制矩形框红色线宽2 Imgproc.rectangle(img, new Point(bbox[0], bbox[1]), new Point(bbox[2], bbox[3]), new Scalar(0, 0, 255), 2); // 绘制元素标签绿色文字 String label layout.getLabel(); Imgproc.putText(img, label, new Point(bbox[0]5, bbox[1]-10), Imgproc.FONT_HERSHEY_SIMPLEX, 0.7, new Scalar(0, 255, 0), 2); } } /** * 绘制表格检测结果 */ public static Mat drawTableResults(Mat image, ListDetectionResult results) { Mat resultImg image.clone(); for (DetectionResult result : results) { String label 表格 String.format(%.2f, result.getConfidence()); // 绘制标签与矩形框 Imgproc.putText(resultImg, label, new Point(result.getRect().x, result.getRect().y-10), Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(0, 0, 255), 2); Imgproc.rectangle(resultImg, new Point(result.getRect().x, result.getRect().y), new Point(result.getRect().xresult.getRect().width, result.getRect().yresult.getRect().height), new Scalar(0, 0, 255), 2); } return resultImg; } /** * 绘制文本行检测结果多边形适配任意角度 */ public static void drawTextLinePredictions(Mat img, Boxes detBoxes) { ListBox boxList detBoxes.getBoxes(); for(Box box : boxList) { double[] pos box.getLinePosition(); // 构建四边形顶点 Point[] points new Point[4]; points[0] new Point(pos[0], pos[1]); points[1] new Point(pos[2], pos[3]); points[2] new Point(pos[4], pos[5]); points[3] new Point(pos[6], pos[7]); // 绘制多边形红色线宽1 MatOfPoint polygon new MatOfPoint(points); ListMatOfPoint polygons new ArrayList(); polygons.add(polygon); Imgproc.polylines(img, polygons, true, new Scalar(0, 0, 255), 1); } } } 关键返回结果说明JiaJiaOCR 2.0 提供结构化、易解析的返回结果覆盖不同功能场景需求功能模块核心返回内容数据格式说明通用 OCR / 手写 OCR文本内容、坐标、置信度ListPairText, BoxText 含内容与置信度Box 含 8 个顶点坐标版面检测元素类型、坐标、置信度ListLayout含 label标题 / 段落等、bbox矩形坐标表格检测表格区域、置信度ListDetectionResult含矩形坐标与置信度表格识别表格结构、内容、坐标TableResult含 htmlContentHTML 格式、box坐标️ 效果展示 通用OCR效果✍️ 手写OCR效果 版面检测效果 表格检测效果 表格识别效果