{"id":6685,"date":"2025-09-29T12:50:02","date_gmt":"2025-09-29T04:50:02","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6685"},"modified":"2025-09-29T12:50:08","modified_gmt":"2025-09-29T04:50:08","slug":"%e5%9f%ba%e4%ba%8e-springboot3-x-%e4%b8%8e-ocr-%e6%9e%84%e5%bb%ba%e7%9a%84%e5%8c%bb%e7%96%97%e8%be%85%e5%8a%a9%e7%b3%bb%e7%bb%9f%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/%e5%9f%ba%e4%ba%8e-springboot3-x-%e4%b8%8e-ocr-%e6%9e%84%e5%bb%ba%e7%9a%84%e5%8c%bb%e7%96%97%e8%be%85%e5%8a%a9%e7%b3%bb%e7%bb%9f%e5%ae%9e%e6%88%98\/","title":{"rendered":"\u57fa\u4e8e SpringBoot3.x \u4e0e OCR \u6784\u5efa\u7684\u533b\u7597\u8f85\u52a9\u7cfb\u7edf\u5b9e\u6218"},"content":{"rendered":"\n<p>\u5728\u533b\u7597\u884c\u4e1a\u6570\u5b57\u5316\u8f6c\u578b\u8fc7\u7a0b\u4e2d\uff0c\u201c\u6587\u6863\u5904\u7406\u6548\u7387\u201d \u4e0e \u201c\u6570\u636e\u51c6\u786e\u6027\u201d \u4e00\u76f4\u662f\u533b\u62a4\u4eba\u5458\u9762\u4e34\u7684\u6838\u5fc3\u75db\u70b9 \u2014\u2014 \u4ece\u7eb8\u8d28\u75c5\u5386\u7684\u624b\u5de5\u5f55\u5165\u3001\u68c0\u67e5\u62a5\u544a\u7684\u4fe1\u606f\u63d0\u53d6\uff0c\u5230\u5904\u65b9\u836f\u54c1\u7684\u4eba\u5de5\u6838\u5bf9\uff0c\u4f20\u7edf\u65b9\u5f0f\u4e0d\u4ec5\u6d88\u8017\u5927\u91cf\u65f6\u95f4\uff0c\u8fd8\u5bb9\u6613\u56e0\u4eba\u4e3a\u5931\u8bef\u5bfc\u81f4\u533b\u7597\u5dee\u9519\u3002\u800c OCR\uff08\u5149\u5b66\u5b57\u7b26\u8bc6\u522b\uff09\u6280\u672f\u4e0e SpringBoot3.x \u6846\u67b6\u7684\u7ed3\u5408\uff0c\u6070\u597d\u4e3a\u89e3\u51b3\u8fd9\u4e9b\u75db\u70b9\u63d0\u4f9b\u4e86\u9ad8\u6548\u65b9\u6848\u3002<\/p>\n\n\n\n<p>\u672c\u4e13\u9898\u5c06\u805a\u7126\u533b\u7597\u8f85\u52a9\u7cfb\u7edf\u7684\u5b9e\u6218\u5f00\u53d1\uff0c\u6df1\u5165\u5256\u6790 OCR \u6280\u672f\u5728\u75c5\u5386\u7ed3\u6784\u5316\u3001\u5904\u65b9\u8bc6\u522b\u3001\u68c0\u67e5\u62a5\u544a\u89e3\u6790\u7b49\u573a\u666f\u7684\u5e94\u7528\uff0c\u4ece\u9700\u6c42\u5b9a\u4e49\u5230\u4ee3\u7801\u5b9e\u73b0\uff0c\u5b8c\u6574\u5448\u73b0\u4e00\u5957\u53ef\u843d\u5730\u7684\u533b\u7597\u6587\u6863\u667a\u80fd\u5904\u7406\u65b9\u6848\uff0c\u52a9\u529b\u533b\u62a4\u4eba\u5458\u91ca\u653e\u53cc\u624b\uff0c\u4e13\u6ce8\u4e8e\u4e34\u5e8a\u6838\u5fc3\u5de5\u4f5c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"432\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6686 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png 881w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776-300x147.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776-768x377.png 768w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"432\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png\" alt=\"\" class=\"wp-image-6686\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png 881w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776-300x147.png 300w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776-768x377.png 768w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><\/noscript><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u7cfb\u7edf\u76ee\u6807\u4e0e\u6838\u5fc3\u9700\u6c42<\/h2>\n\n\n\n<p>\u533b\u7597\u8f85\u52a9\u7cfb\u7edf\u7684\u6838\u5fc3\u4ef7\u503c\u662f \u201c\u8ba9\u533b\u7597\u6587\u6863\u5904\u7406\u66f4\u9ad8\u6548\u3001\u66f4\u51c6\u786e\u201d\uff0c\u9700\u56f4\u7ed5\u533b\u7597\u573a\u666f\u7684\u7279\u6b8a\u6027\u660e\u786e\u76ee\u6807\u4e0e\u9700\u6c42\uff0c\u907f\u514d\u901a\u7528 OCR \u7cfb\u7edf\u5728\u533b\u7597\u9886\u57df\u7684 \u201c\u6c34\u571f\u4e0d\u670d\u201d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u7cfb\u7edf\u76ee\u6807<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9e\u73b0\u533b\u7597\u6587\u6863\uff08\u75c5\u5386\u3001\u5904\u65b9\u3001\u68c0\u67e5\u62a5\u544a\uff09\u7684<strong>\u81ea\u52a8\u8bc6\u522b\u4e0e\u7ed3\u6784\u5316\u63d0\u53d6<\/strong>\uff0c\u5c06 \u201c\u975e\u7ed3\u6784\u5316\u6587\u672c\u201d \u8f6c\u5316\u4e3a \u201c\u53ef\u68c0\u7d22\u3001\u53ef\u5206\u6790\u7684\u7ed3\u6784\u5316\u6570\u636e\u201d\uff0c\u652f\u6491\u540e\u7eed\u7684\u75c5\u5386\u5f52\u6863\u3001\u5904\u65b9\u5ba1\u6838\u7b49\u4e1a\u52a1\u3002<\/li>\n\n\n\n<li>\u6784\u5efa<strong>\u7a33\u5b9a\u9ad8\u53ef\u7528\u7684\u670d\u52a1<\/strong>\uff0c\u5e94\u5bf9\u533b\u9662\u9ad8\u5cf0\u671f\uff08\u5982\u65e9\u8bca\u3001\u4f53\u68c0\u5b63\uff09\u7684\u5e76\u53d1\u8bf7\u6c42\uff0c\u4fdd\u8bc1\u5355\u6587\u6863\u8bc6\u522b\u54cd\u5e94\u65f6\u95f4\u22643 \u79d2\uff0c\u8bc6\u522b\u51c6\u786e\u7387\u226595%\uff08\u6838\u5fc3\u533b\u7597\u5b57\u6bb5\u5982\u60a3\u8005\u59d3\u540d\u3001\u836f\u54c1\u540d\u79f0\uff09\u3002<\/li>\n\n\n\n<li>\u6ee1\u8db3<strong>\u533b\u7597\u6570\u636e\u5b89\u5168\u89c4\u8303<\/strong>\uff0c\u6240\u6709\u8bc6\u522b\u6570\u636e\u9700\u52a0\u5bc6\u5b58\u50a8\uff0c\u64cd\u4f5c\u65e5\u5fd7\u53ef\u8ffd\u6eaf\uff0c\u7b26\u5408\u300a\u4e2a\u4eba\u4fe1\u606f\u4fdd\u62a4\u6cd5\u300b\u4e0e\u300a\u533b\u7597\u673a\u6784\u6570\u636e\u5b89\u5168\u7ba1\u7406\u529e\u6cd5\u300b\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u6838\u5fc3\u9700\u6c42<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u652f\u6301\u591a\u683c\u5f0f\u6587\u6863\u8f93\u5165\uff1a\u5305\u62ec\u7eb8\u8d28\u75c5\u5386\u626b\u63cf\u4ef6\uff08JPG\/PNG\uff09\u3001\u7535\u5b50\u68c0\u67e5\u62a5\u544a\uff08PDF\uff09\u3001\u624b\u5199\u5904\u65b9\u7167\u7247\uff0c\u9700\u517c\u5bb9\u533b\u7597\u573a\u666f\u4e2d\u5e38\u89c1\u7684\u6587\u6863\u683c\u5f0f\u3002<\/li>\n\n\n\n<li>\u63d0\u4f9b\u53cb\u597d\u7684\u7528\u6237\u4ea4\u4e92\uff1a\u5f00\u53d1 Web \u7aef\u4e0a\u4f20\u754c\u9762\uff0c\u652f\u6301\u5355\u6587\u4ef6 \/ \u591a\u6587\u4ef6\u6279\u91cf\u4e0a\u4f20\uff0c\u8bc6\u522b\u5b8c\u6210\u540e\u76f4\u89c2\u5c55\u793a\u7ed3\u6784\u5316\u7ed3\u679c\uff08\u5982\u60a3\u8005\u4fe1\u606f\u8868\u3001\u68c0\u67e5\u9879\u76ee\u6e05\u5355\uff09\uff0c\u5e76\u5141\u8bb8\u4eba\u5de5\u4fee\u6b63\u9519\u8bef\u3002<\/li>\n\n\n\n<li>\u7279\u6b8a\u6587\u6863\u5904\u7406\u80fd\u529b\uff1a\u9488\u5bf9\u533b\u7597\u573a\u666f\u4e2d\u7684 \u201c\u7279\u6b8a\u6587\u6863\u201d\uff08\u5982\u624b\u5199\u6f66\u8349\u7684\u5904\u65b9\u3001\u6cdb\u9ec4\u6a21\u7cca\u7684\u65e7\u75c5\u5386\u3001\u5e26\u8868\u683c\u7684\u68c0\u67e5\u62a5\u544a\uff09\uff0c\u9700\u901a\u8fc7\u9884\u5904\u7406\u4f18\u5316\u8bc6\u522b\u6548\u679c\u3002<\/li>\n\n\n\n<li>\u5173\u952e\u4fe1\u606f\u6821\u9a8c\u673a\u5236\uff1a\u8bc6\u522b\u540e\u9700\u5bf9\u533b\u7597\u4e13\u7528\u5b57\u6bb5\uff08\u5982\u836f\u54c1\u901a\u7528\u540d\u3001\u75be\u75c5 ICD \u7f16\u7801\uff09\u8fdb\u884c\u6821\u9a8c\uff0c\u5339\u914d\u533b\u7597\u672f\u8bed\u5e93\uff08\u5982\u300a\u4e2d\u56fd\u836f\u5178\u300b\u300aICD-10 \u75be\u75c5\u5206\u7c7b\u300b\uff09\uff0c\u964d\u4f4e\u8bc6\u522b\u9519\u8bef\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6838\u5fc3\u6280\u672f\u9009\u578b<\/h2>\n\n\n\n<p>\u533b\u7597\u8f85\u52a9\u7cfb\u7edf\u7684\u6280\u672f\u9009\u578b\u9700\u517c\u987e \u201c\u8bc6\u522b\u51c6\u786e\u6027\u201d \u4e0e \u201c\u533b\u7597\u573a\u666f\u9002\u914d\u6027\u201d\uff0c\u907f\u514d\u76f2\u76ee\u9009\u7528\u901a\u7528 OCR \u5de5\u5177\uff0c\u91cd\u70b9\u5173\u6ce8\u4ee5\u4e0b\u6838\u5fc3\u7ec4\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u6280\u672f\u7ec4\u4ef6<\/th><th>\u9009\u578b\u65b9\u6848<\/th><th>\u9009\u578b\u7406\u7531<\/th><\/tr><\/thead><tbody><tr><td>OCR \u5f15\u64ce<\/td><td>Tesseract OCR\uff084.1.1 \u7248\u672c\uff09<\/td><td>\u5f00\u6e90\u514d\u8d39\uff0c\u652f\u6301\u81ea\u5b9a\u4e49\u8bad\u7ec3\u533b\u7597\u4e13\u7528\u5b57\u5e93\uff08\u5982\u624b\u5199\u5904\u65b9\u5b57\u4f53\u3001\u533b\u7597\u4e13\u7528\u7b26\u53f7\uff09\uff0c\u793e\u533a\u751f\u6001\u6210\u719f\u3002<\/td><\/tr><tr><td>\u56fe\u50cf\u5904\u7406<\/td><td>OpenCV + Leptonica<\/td><td>OpenCV \u63d0\u4f9b\u503e\u659c\u6821\u6b63\u3001\u53bb\u566a\u3001\u5bf9\u6bd4\u5ea6\u589e\u5f3a\u7b49 API\uff0cLeptonica \u4f18\u5316\u56fe\u50cf\u9884\u5904\u7406\u6548\u7387\uff0c\u9002\u914d\u533b\u7597\u6587\u6863\u7684\u590d\u6742\u80cc\u666f\u3002<\/td><\/tr><tr><td>PDF \u89e3\u6790<\/td><td>Apache PDFBox<\/td><td>\u8f7b\u91cf\u7ea7\u5f00\u6e90\u5e93\uff0c\u652f\u6301\u5c06 PDF \u683c\u5f0f\u7684\u7535\u5b50\u62a5\u544a\u8f6c\u4e3a\u56fe\u7247\uff08\u89e3\u51b3 PDF \u5185\u6587\u5b57\u65e0\u6cd5\u76f4\u63a5\u590d\u5236\u7684\u95ee\u9898\uff09\u3002<\/td><\/tr><tr><td>\u540e\u7aef\u6846\u67b6<\/td><td>SpringBoot3.x<\/td><td>\u7b80\u5316\u670d\u52a1\u642d\u5efa\uff0c\u652f\u6301 RESTful API \u8bbe\u8ba1\uff0c\u96c6\u6210 Spring Security \u4fbf\u4e8e\u5b9e\u73b0\u6743\u9650\u63a7\u5236\u4e0e\u6570\u636e\u52a0\u5bc6\u3002<\/td><\/tr><tr><td>\u533b\u7597\u672f\u8bed\u6821\u9a8c<\/td><td>\u81ea\u5b9a\u4e49\u533b\u7597\u672f\u8bed\u5e93\uff08JSON\uff09<\/td><td>\u5185\u7f6e\u836f\u54c1\u901a\u7528\u540d\u3001\u75be\u75c5 ICD \u7f16\u7801\u3001\u68c0\u67e5\u9879\u76ee\u540d\u79f0\u7b49\u6838\u5fc3\u672f\u8bed\uff0c\u7528\u4e8e\u8bc6\u522b\u7ed3\u679c\u7684\u4e8c\u6b21\u6821\u9a8c\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u9879\u76ee\u4f9d\u8d56\u914d\u7f6e<\/h2>\n\n\n\n<p>\u57fa\u4e8e Maven \u6784\u5efa\u9879\u76ee\uff0c\u9700\u5f15\u5165 OCR \u5f15\u64ce\u3001\u56fe\u50cf\u5904\u7406\u3001PDF \u89e3\u6790\u53ca SpringBoot \u6838\u5fc3\u4f9d\u8d56\uff0c\u786e\u4fdd\u5404\u7ec4\u4ef6\u7248\u672c\u517c\u5bb9\uff08\u907f\u514d\u56e0\u7248\u672c\u51b2\u7a81\u5bfc\u81f4\u7684\u670d\u52a1\u542f\u52a8\u5931\u8d25\uff09\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&lt;!-- SpringBoot Web\u6838\u5fc3\u4f9d\u8d56 --&gt;<\/code><code>&lt;dependency&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;version&gt;3.2.4&lt;\/version&gt;<\/code><code>&lt;\/dependency&gt;<\/code><code>&lt;!-- Spring Security\uff08\u6570\u636e\u5b89\u5168\u4e0e\u6743\u9650\u63a7\u5236\uff09 --&gt;<\/code><code>&lt;dependency&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;artifactId&gt;spring-boot-starter-security&lt;\/artifactId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;version&gt;3.2.4&lt;\/version&gt;<\/code><code>&lt;\/dependency&gt;<\/code><code>&lt;!-- OCR\u6838\u5fc3\u4f9d\u8d56\uff1aTesseract + Leptonica --&gt;<\/code><code>&lt;dependency&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;groupId&gt;org.bytedeco&lt;\/groupId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;artifactId&gt;leptonica-platform&lt;\/artifactId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;version&gt;1.78.0-1.5.3&lt;\/version&gt;<\/code><code>&lt;\/dependency&gt;<\/code><code>&lt;dependency&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;groupId&gt;org.bytedeco&lt;\/groupId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;artifactId&gt;tesseract-platform&lt;\/artifactId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;version&gt;4.1.1-1.5.3&lt;\/version&gt;<\/code><code>&lt;\/dependency&gt;<\/code><code>&lt;!-- OpenCV\uff08\u56fe\u50cf\u5904\u7406\uff09 --&gt;<\/code><code>&lt;dependency&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;groupId&gt;org.openpnp&lt;\/groupId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;artifactId&gt;opencv&lt;\/artifactId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;version&gt;4.5.5-0&lt;\/version&gt;<\/code><code>&lt;\/dependency&gt;<\/code><code>&lt;!-- PDF\u89e3\u6790\uff1aApache PDFBox --&gt;<\/code><code>&lt;dependency&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;groupId&gt;org.apache.pdfbox&lt;\/groupId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;artifactId&gt;pdfbox&lt;\/artifactId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;version&gt;2.0.32&lt;\/version&gt;<\/code><code>&lt;\/dependency&gt;<\/code><code>&lt;!-- \u5de5\u5177\u7c7b\uff1aJSON\u5904\u7406 --&gt;<\/code><code>&lt;dependency&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;groupId&gt;com.alibaba&lt;\/groupId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;artifactId&gt;fastjson2&lt;\/artifactId&gt;<\/code><code>&nbsp; &nbsp;&nbsp;&lt;version&gt;2.0.41&lt;\/version&gt;<\/code><code>&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u5173\u952e\u6a21\u5757\u4ee3\u7801\u5b9e\u73b0<\/h2>\n\n\n\n<p>\u7cfb\u7edf\u91c7\u7528 \u201c\u5206\u5c42\u8bbe\u8ba1\u201d\uff0c\u5206\u4e3a<strong>\u6587\u6863\u9884\u5904\u7406\u5c42<\/strong>\uff08\u5904\u7406\u7279\u6b8a\u6587\u6863\uff09\u3001<strong>OCR \u8bc6\u522b\u5c42<\/strong>\uff08\u63d0\u53d6\u6587\u672c\uff09\u3001<strong>\u7ed3\u6784\u5316\u5c42<\/strong>\uff08\u8f6c\u5316\u4e3a\u533b\u7597\u6570\u636e\uff09\u3001<strong>\u63a7\u5236\u5c42<\/strong>\uff08\u63d0\u4f9b API\uff09\uff0c\u5404\u5c42\u804c\u8d23\u6e05\u6670\uff0c\u4fbf\u4e8e\u7ef4\u62a4\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6587\u6863\u9884\u5904\u7406\u670d\u52a1\uff1aMedicalDocumentPreprocessService<\/h3>\n\n\n\n<p>\u533b\u7597\u6587\u6863\u5e38\u5b58\u5728 \u201c\u503e\u659c\u3001\u6a21\u7cca\u3001\u624b\u5199\u5e72\u6270\u201d \u7b49\u95ee\u9898\uff0c\u9700\u5148\u901a\u8fc7\u9884\u5904\u7406\u4f18\u5316\u56fe\u50cf\u8d28\u91cf\uff0c\u4e3a OCR \u8bc6\u522b\u94fa\u8def\u3002\u6838\u5fc3\u5904\u7406\u6b65\u9aa4\u5305\u62ec\uff1aPDF \u8f6c\u56fe\u7247\u3001\u503e\u659c\u6821\u6b63\u3001\u53bb\u566a\u3001\u5bf9\u6bd4\u5ea6\u589e\u5f3a\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>import&nbsp;org.openpnp.opencv.OpenCv;<\/code><code>import&nbsp;org.opencv.core.*;<\/code><code>import&nbsp;org.opencv.imgcodecs.Imgcodecs;<\/code><code>import&nbsp;org.opencv.imgproc.Imgproc;<\/code><code>import&nbsp;org.apache.pdfbox.pdmodel.PDDocument;<\/code><code>import&nbsp;org.apache.pdfbox.rendering.PDFRenderer;<\/code><code>import&nbsp;org.springframework.stereotype.Service;<\/code><code>import&nbsp;javax.imageio.ImageIO;<\/code><code>import&nbsp;java.awt.image.BufferedImage;<\/code><code>import&nbsp;java.io.File;<\/code><code>import&nbsp;java.io.IOException;<\/code><code>@Service<\/code><code>public&nbsp;class&nbsp;MedicalDocumentPreprocessService&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u9759\u6001\u52a0\u8f7dOpenCV\u539f\u751f\u5e93<\/code><code>&nbsp; &nbsp;&nbsp;static&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; OpenCv.loadShared();<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/**<\/code><code>&nbsp; &nbsp; &nbsp;* PDF\u6587\u6863\u8f6c\u56fe\u7247\uff08\u533b\u7597\u7535\u5b50\u62a5\u544a\u5e38\u7528\u683c\u5f0f\uff09<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;pdfPath PDF\u6587\u4ef6\u8def\u5f84<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@return&nbsp;\u8f6c\u5316\u540e\u7684\u56fe\u7247\u8def\u5f84<\/code><code>&nbsp; &nbsp; &nbsp;*\/<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;String&nbsp;pdfToImage(String pdfPath)&nbsp;throws&nbsp;IOException {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;PDDocument&nbsp;document&nbsp;=&nbsp;PDDocument.load(new&nbsp;File(pdfPath));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;PDFRenderer&nbsp;renderer&nbsp;=&nbsp;new&nbsp;PDFRenderer(document);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u533b\u7597PDF\u901a\u5e38\u4e3a\u5355\u9875\uff08\u5982\u68c0\u67e5\u62a5\u544a\uff09\uff0c\u53d6\u7b2c\u4e00\u9875\u8f6c\u5316<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;BufferedImage&nbsp;bufferedImage&nbsp;=&nbsp;renderer.renderImageWithDPI(0,&nbsp;300);&nbsp;\/\/ 300DPI\u4fdd\u8bc1\u6e05\u6670\u5ea6<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;imagePath&nbsp;=&nbsp;pdfPath.replace(\".pdf\",&nbsp;\".png\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; ImageIO.write(bufferedImage,&nbsp;\"png\",&nbsp;new&nbsp;File(imagePath));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; document.close();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;imagePath;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/**<\/code><code>&nbsp; &nbsp; &nbsp;* \u56fe\u50cf\u9884\u5904\u7406\uff08\u9488\u5bf9\u6a21\u7cca\/\u503e\u659c\/\u624b\u5199\u6587\u6863\uff09<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;imagePath \u539f\u59cb\u56fe\u7247\u8def\u5f84<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@return&nbsp;\u9884\u5904\u7406\u540e\u7684\u56fe\u7247\u8def\u5f84<\/code><code>&nbsp; &nbsp; &nbsp;*\/<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;String&nbsp;preprocessImage(String imagePath)&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u8bfb\u53d6\u56fe\u50cf\uff08\u7070\u5ea6\u6a21\u5f0f\uff0c\u51cf\u5c11\u8272\u5f69\u5e72\u6270\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mat&nbsp;src&nbsp;=&nbsp;Imgcodecs.imread(imagePath, Imgcodecs.IMREAD_GRAYSCALE);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mat&nbsp;dst&nbsp;=&nbsp;new&nbsp;Mat();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u503e\u659c\u6821\u6b63\uff08\u533b\u7597\u6587\u6863\u626b\u63cf\u5e38\u503e\u659c\uff0c\u5f71\u54cdOCR\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mat&nbsp;edges&nbsp;=&nbsp;new&nbsp;Mat();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; Imgproc.Canny(src, edges,&nbsp;50,&nbsp;150);&nbsp;\/\/ \u8fb9\u7f18\u68c0\u6d4b<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mat&nbsp;lines&nbsp;=&nbsp;new&nbsp;Mat();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; Imgproc.HoughLinesP(edges, lines,&nbsp;1, Math.PI \/&nbsp;180,&nbsp;50,&nbsp;50,&nbsp;10);&nbsp;\/\/ \u68c0\u6d4b\u503e\u659c\u7ebf\u6761<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;double&nbsp;angle&nbsp;=&nbsp;calculateAngle(lines);&nbsp;\/\/ \u8ba1\u7b97\u503e\u659c\u89d2\u5ea6<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mat&nbsp;rotated&nbsp;=&nbsp;rotateImage(src, angle);&nbsp;\/\/ \u65cb\u8f6c\u6821\u6b63<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u53bb\u566a\uff08\u53bb\u9664\u7eb8\u5f20\u6c61\u6e0d\u3001\u626b\u63cf\u566a\u70b9\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; Imgproc.fastNlMeansDenoising(rotated, dst,&nbsp;10,&nbsp;7,&nbsp;21);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 4. \u5bf9\u6bd4\u5ea6\u589e\u5f3a\uff08\u9488\u5bf9\u6cdb\u9ec4\u65e7\u75c5\u5386\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; Imgproc.equalizeHist(dst, dst);&nbsp;\/\/ \u5168\u5c40\u76f4\u65b9\u56fe\u5747\u8861\u5316<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;CLAHE&nbsp;clahe&nbsp;=&nbsp;Imgproc.createCLAHE(4.0,&nbsp;new&nbsp;Size(8,&nbsp;8));&nbsp;\/\/ \u5c40\u90e8\u5bf9\u6bd4\u5ea6\u589e\u5f3a<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; clahe.apply(dst, dst);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 5. \u4fdd\u5b58\u9884\u5904\u7406\u540e\u7684\u56fe\u50cf<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;processedPath&nbsp;=&nbsp;imagePath.replace(\".png\",&nbsp;\"_processed.png\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; Imgcodecs.imwrite(processedPath, dst);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;processedPath;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u8ba1\u7b97\u56fe\u50cf\u503e\u659c\u89d2\u5ea6<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;double&nbsp;calculateAngle(Mat lines)&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;double&nbsp;angle&nbsp;=&nbsp;0.0;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;lineCount&nbsp;=&nbsp;lines.rows();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(lineCount ==&nbsp;0)&nbsp;return&nbsp;angle;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;i&nbsp;=&nbsp;0; i &lt; lineCount; i++) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;double[] points = lines.get(i,&nbsp;0);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;double&nbsp;x1&nbsp;=&nbsp;points[0], y1 = points[1], x2 = points[2], y2 = points[3];<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;double&nbsp;lineAngle&nbsp;=&nbsp;Math.atan2(y2 - y1, x2 - x1) *&nbsp;180&nbsp;\/ Math.PI;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle += lineAngle;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; angle \/= lineCount;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u53ea\u6821\u6b63\u00b115\u00b0\u5185\u7684\u503e\u659c\uff08\u907f\u514d\u8fc7\u5ea6\u65cb\u8f6c\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;Math.abs(angle) &gt;&nbsp;15&nbsp;?&nbsp;0&nbsp;: angle;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u65cb\u8f6c\u56fe\u50cf\uff08\u6839\u636e\u503e\u659c\u89d2\u5ea6\uff09<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;Mat&nbsp;rotateImage(Mat src,&nbsp;double&nbsp;angle)&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;height&nbsp;=&nbsp;src.rows();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;width&nbsp;=&nbsp;src.cols();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Point&nbsp;center&nbsp;=&nbsp;new&nbsp;Point(width \/&nbsp;2, height \/&nbsp;2);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mat&nbsp;rotationMatrix&nbsp;=&nbsp;Imgproc.getRotationMatrix2D(center, angle,&nbsp;1.0);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; Imgproc.warpAffine(src, src, rotationMatrix,&nbsp;new&nbsp;Size(width, height), Imgproc.INTER_CUBIC);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;src;<\/code><code>&nbsp; &nbsp; }<\/code><code>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. OCR \u8bc6\u522b\u4e0e\u7ed3\u6784\u5316\u670d\u52a1\uff1aMedicalOcrRecognitionService<\/h3>\n\n\n\n<p>\u8c03\u7528 Tesseract OCR \u8bc6\u522b\u9884\u5904\u7406\u540e\u7684\u56fe\u50cf\uff0c\u63d0\u53d6\u6587\u672c\u540e\uff0c\u901a\u8fc7 \u201c\u6b63\u5219\u8868\u8fbe\u5f0f + \u533b\u7597\u672f\u8bed\u5e93\u201d \u5c06\u975e\u7ed3\u6784\u5316\u6587\u672c\u8f6c\u5316\u4e3a\u7ed3\u6784\u5316\u6570\u636e\uff08\u5982\u60a3\u8005\u4fe1\u606f\u3001\u5904\u65b9\u4fe1\u606f\uff09\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>import&nbsp;org.bytedeco.javacpp.BytePointer;<\/code><code>import&nbsp;org.bytedeco.leptonica.PIX;<\/code><code>import&nbsp;org.bytedeco.leptonica.global.lept;<\/code><code>import&nbsp;org.bytedeco.tesseract.TessBaseAPI;<\/code><code>import&nbsp;org.bytedeco.tesseract.global.tesseract;<\/code><code>import&nbsp;org.springframework.beans.factory.annotation.Value;<\/code><code>import&nbsp;org.springframework.stereotype.Service;<\/code><code>import&nbsp;java.io.File;<\/code><code>import&nbsp;java.util.HashMap;<\/code><code>import&nbsp;java.util.Map;<\/code><code>import&nbsp;java.util.regex.Matcher;<\/code><code>import&nbsp;java.util.regex.Pattern;<\/code><code>@Service<\/code><code>public&nbsp;class&nbsp;MedicalOcrRecognitionService&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ Tesseract\u5b57\u5e93\u8def\u5f84\uff08\u914d\u7f6e\u5728application.yml\u4e2d\uff0c\u4fbf\u4e8e\u90e8\u7f72\uff09<\/code><code>&nbsp; &nbsp;&nbsp;@Value(\"${tesseract.tessdata.path}\")<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;String&nbsp;tessdataPath;<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u533b\u7597\u672f\u8bed\u5e93\uff08\u7b80\u5316\u7248\uff0c\u5b9e\u9645\u53ef\u4ece\u6570\u636e\u5e93\u52a0\u8f7d\uff09<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;static&nbsp;final&nbsp;Map&lt;String,&nbsp;String&gt;&nbsp;MEDICAL_TERM_MAP&nbsp;=&nbsp;new&nbsp;HashMap&lt;&gt;();<\/code><code>&nbsp; &nbsp;&nbsp;static&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u836f\u54c1\u901a\u7528\u540d\u6620\u5c04\uff08\u907f\u514dOCR\u8bc6\u522b\u9519\u8bef\uff0c\u5982\u201c\u963f\u83ab\u897f\u6797\u201d\u8bef\u8bc6\u522b\u4e3a\u201c\u963f\u5960\u897f\u6797\u201d\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;MEDICAL_TERM_MAP.put(\"\u963f\u5960\u897f\u6797\",&nbsp;\"\u963f\u83ab\u897f\u6797\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;MEDICAL_TERM_MAP.put(\"\u5934\u5b62\u514b\u572c\",&nbsp;\"\u5934\u5b62\u514b\u809f\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u75be\u75c5ICD\u7f16\u7801\u6620\u5c04<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;MEDICAL_TERM_MAP.put(\"2\u578b\u7cd6\u5c3f\u75c5\",&nbsp;\"E11.x\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;MEDICAL_TERM_MAP.put(\"\u9ad8\u8840\u538b1\u7ea7\",&nbsp;\"I10.x\");<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/**<\/code><code>&nbsp; &nbsp; &nbsp;* \u533b\u7597\u6587\u6863OCR\u8bc6\u522b\u4e0e\u7ed3\u6784\u5316<\/code><code>&nbsp; &nbsp; &nbsp;* @param processedImagePath \u9884\u5904\u7406\u540e\u7684\u56fe\u50cf\u8def\u5f84<\/code><code>&nbsp; &nbsp; &nbsp;* @param docType \u6587\u6863\u7c7b\u578b\uff1aPATIENT\uff08\u75c5\u5386\uff09\u3001PRESCRIPTION\uff08\u5904\u65b9\uff09\u3001REPORT\uff08\u68c0\u67e5\u62a5\u544a\uff09<\/code><code>&nbsp; &nbsp; &nbsp;* @return \u7ed3\u6784\u5316\u533b\u7597\u6570\u636e<\/code><code>&nbsp; &nbsp; &nbsp;*\/<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;Map&lt;String,&nbsp;String&gt; recognizeAndStructure(String&nbsp;processedImagePath,&nbsp;String&nbsp;docType) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u521d\u59cb\u5316Tesseract OCR<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;TessBaseAPI&nbsp;api&nbsp;=&nbsp;new&nbsp;TessBaseAPI();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u52a0\u8f7d\u4e2d\u6587\u5b57\u5e93\uff08\u533b\u7597\u6587\u6863\u4ee5\u4e2d\u6587\u4e3a\u4e3b\uff09+ \u533b\u7597\u81ea\u5b9a\u4e49\u5b57\u5e93<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(api.Init(tessdataPath,&nbsp;\"chi_sim+medical_custom\")&nbsp;!=&nbsp;0) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(\"Tesseract\u521d\u59cb\u5316\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u5b57\u5e93\u8def\u5f84\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u8bfb\u53d6\u9884\u5904\u7406\u540e\u7684\u56fe\u50cf<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;PIX&nbsp;image&nbsp;=&nbsp;lept.pixRead(processedImagePath);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(image&nbsp;==&nbsp;null) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new&nbsp;RuntimeException(\"\u56fe\u50cf\u8bfb\u53d6\u5931\u8d25\uff0c\u8def\u5f84\uff1a\"&nbsp;+&nbsp;processedImagePath);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; api.SetImage(image);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u6267\u884cOCR\u8bc6\u522b\uff08\u83b7\u53d6\u7eaf\u6587\u672c\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;BytePointer&nbsp;outText&nbsp;=&nbsp;api.GetUTF8Text();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;ocrResult&nbsp;=&nbsp;outText.getString();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.out.println(\"OCR\u539f\u59cb\u7ed3\u679c\uff1a\"&nbsp;+&nbsp;ocrResult);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 4. \u7ed3\u6784\u5316\u63d0\u53d6\uff08\u6309\u6587\u6863\u7c7b\u578b\u5206\u522b\u5904\u7406\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Map&lt;String,&nbsp;String&gt; structuredData&nbsp;=&nbsp;new&nbsp;HashMap&lt;&gt;();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;switch&nbsp;(docType) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;case&nbsp;\"PATIENT\":<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; structuredData&nbsp;=&nbsp;extractPatientData(ocrResult);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;break;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;case&nbsp;\"PRESCRIPTION\":<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; structuredData&nbsp;=&nbsp;extractPrescriptionData(ocrResult);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;break;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;case&nbsp;\"REPORT\":<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; structuredData&nbsp;=&nbsp;extractReportData(ocrResult);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;break;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;default:<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new&nbsp;IllegalArgumentException(\"\u4e0d\u652f\u6301\u7684\u6587\u6863\u7c7b\u578b\uff1a\"&nbsp;+&nbsp;docType);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 5. \u533b\u7597\u672f\u8bed\u6821\u9a8c\u4e0e\u4fee\u6b63\uff08\u964d\u4f4e\u8bc6\u522b\u9519\u8bef\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; structuredData&nbsp;=&nbsp;correctMedicalTerms(structuredData);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 6. \u91ca\u653e\u8d44\u6e90\uff08\u907f\u514d\u5185\u5b58\u6cc4\u6f0f\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; api.End();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; outText.deallocate();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; lept.pixDestroy(image);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;structuredData;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u63d0\u53d6\u75c5\u5386\u4e2d\u7684\u60a3\u8005\u4fe1\u606f\uff08\u59d3\u540d\u3001\u5e74\u9f84\u3001\u6027\u522b\u3001\u5c31\u8bca\u65e5\u671f\uff09<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;Map&lt;String,&nbsp;String&gt; extractPatientData(String&nbsp;ocrResult) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Map&lt;String,&nbsp;String&gt; data&nbsp;=&nbsp;new&nbsp;HashMap&lt;&gt;();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u6b63\u5219\u8868\u8fbe\u5f0f\u5339\u914d\uff08\u533b\u7597\u75c5\u5386\u683c\u5f0f\u76f8\u5bf9\u56fa\u5b9a\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"patientName\", matchRegex(ocrResult,&nbsp;\"\u59d3\u540d\uff1a([\\\\u4e00-\\\\u9fa5]+)\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"patientAge\", matchRegex(ocrResult,&nbsp;\"\u5e74\u9f84\uff1a(\\\\d+)\u5c81\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"patientGender\", matchRegex(ocrResult,&nbsp;\"\u6027\u522b\uff1a([\u7537\u5973])\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"visitDate\", matchRegex(ocrResult,&nbsp;\"\u5c31\u8bca\u65e5\u671f\uff1a(\\\\d{4}-\\\\d{2}-\\\\d{2})\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;data;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u63d0\u53d6\u5904\u65b9\u4e2d\u7684\u836f\u54c1\u4fe1\u606f\uff08\u836f\u54c1\u540d\u3001\u5242\u91cf\u3001\u7528\u6cd5\uff09<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;Map&lt;String,&nbsp;String&gt; extractPrescriptionData(String&nbsp;ocrResult) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Map&lt;String,&nbsp;String&gt; data&nbsp;=&nbsp;new&nbsp;HashMap&lt;&gt;();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"drugName\", matchRegex(ocrResult,&nbsp;\"\u836f\u54c1\uff1a([\\\\u4e00-\\\\u9fa5]+)\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"drugDosage\", matchRegex(ocrResult,&nbsp;\"\u5242\u91cf\uff1a([\\\\d\\\\.]+[mg|g|ml]+)\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"drugUsage\", matchRegex(ocrResult,&nbsp;\"\u7528\u6cd5\uff1a([\\\\u4e00-\\\\u9fa5\\\\d]+)\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;data;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u63d0\u53d6\u68c0\u67e5\u62a5\u544a\u4e2d\u7684\u5173\u952e\u7ed3\u679c\uff08\u68c0\u67e5\u9879\u76ee\u3001\u7ed3\u679c\u3001\u53c2\u8003\u503c\uff09<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;Map&lt;String,&nbsp;String&gt; extractReportData(String&nbsp;ocrResult) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Map&lt;String,&nbsp;String&gt; data&nbsp;=&nbsp;new&nbsp;HashMap&lt;&gt;();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"checkItem\", matchRegex(ocrResult,&nbsp;\"\u68c0\u67e5\u9879\u76ee\uff1a([\\\\u4e00-\\\\u9fa5]+)\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"checkResult\", matchRegex(ocrResult,&nbsp;\"\u7ed3\u679c\uff1a([\\\\d\\\\.\\\\u4e00-\\\\u9fa5]+)\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; data.put(\"referenceValue\", matchRegex(ocrResult,&nbsp;\"\u53c2\u8003\u503c\uff1a([\\\\d\\\\.\\\\-~\\\\u4e00-\\\\u9fa5]+)\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;data;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u6b63\u5219\u5339\u914d\u5de5\u5177\u65b9\u6cd5<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;String&nbsp;matchRegex(String&nbsp;content,&nbsp;String&nbsp;regex) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Pattern&nbsp;pattern&nbsp;=&nbsp;Pattern.compile(regex);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Matcher&nbsp;matcher&nbsp;=&nbsp;pattern.matcher(content);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;matcher.find()&nbsp;?&nbsp;matcher.group(1) :&nbsp;\"\u672a\u8bc6\u522b\";<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u533b\u7597\u672f\u8bed\u4fee\u6b63\uff08\u6839\u636e\u672f\u8bed\u5e93\u66ff\u6362\u9519\u8bef\u8bc6\u522b\u7ed3\u679c\uff09<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;Map&lt;String,&nbsp;String&gt; correctMedicalTerms(Map&lt;String,&nbsp;String&gt; data) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(Map.Entry&lt;String,&nbsp;String&gt; entry : data.entrySet()) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;value&nbsp;=&nbsp;entry.getValue();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(MEDICAL_TERM_MAP.containsKey(value)) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entry.setValue(MEDICAL_TERM_MAP.get(value));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;data;<\/code><code>&nbsp; &nbsp; }<\/code><code>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u63a7\u5236\u5c42\uff1aMedicalAssistantController<\/h3>\n\n\n\n<p>\u63d0\u4f9b RESTful API\uff0c\u652f\u6301\u524d\u7aef\u4e0a\u4f20\u533b\u7597\u6587\u6863\uff08\u56fe\u7247 \/ PDF\uff09\uff0c\u8c03\u7528\u9884\u5904\u7406\u4e0e OCR \u670d\u52a1\uff0c\u8fd4\u56de\u7ed3\u6784\u5316\u7ed3\u679c\uff0c\u540c\u65f6\u96c6\u6210\u7b80\u5355\u7684\u6743\u9650\u63a7\u5236\u3002https:\/\/wxa.wxs.qq.com\/tmpl\/oc\/base_tmpl.html<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>import&nbsp;com.alibaba.fastjson2.JSONObject;<\/code><code>import&nbsp;org.springframework.beans.factory.annotation.Autowired;<\/code><code>import&nbsp;org.springframework.security.access.prepost.PreAuthorize;<\/code><code>import&nbsp;org.springframework.web.bind.annotation.*;<\/code><code>import&nbsp;org.springframework.web.multipart.MultipartFile;<\/code><code>import&nbsp;java.io.File;<\/code><code>import&nbsp;java.util.Map;<\/code><code>import&nbsp;java.util.UUID;<\/code><code>@RestController<\/code><code>@RequestMapping(\"\/medical\/ocr\")<\/code><code>public&nbsp;class&nbsp;MedicalAssistantController&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;@Autowired<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;MedicalDocumentPreprocessService&nbsp;preprocessService;<\/code><code>&nbsp; &nbsp;&nbsp;@Autowired<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;MedicalOcrRecognitionService&nbsp;ocrRecognitionService;<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u6587\u6863\u4e0a\u4f20\u8def\u5f84\uff08\u914d\u7f6e\u5728application.yml\u4e2d\uff09<\/code><code>&nbsp; &nbsp;&nbsp;@Value(\"${medical.upload.path}\")<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;String&nbsp;uploadPath;<\/code><code>&nbsp; &nbsp;&nbsp;\/**<\/code><code>&nbsp; &nbsp; &nbsp;* \u533b\u7597\u6587\u6863\u4e0a\u4f20\u4e0e\u8bc6\u522b\u63a5\u53e3<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;file \u4e0a\u4f20\u7684\u6587\u6863\uff08\u56fe\u7247\/PDF\uff09<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;docType \u6587\u6863\u7c7b\u578b\uff1aPATIENT\/PRESCRIPTION\/REPORT<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@return&nbsp;\u7ed3\u6784\u5316\u8bc6\u522b\u7ed3\u679c\uff08JSON\u683c\u5f0f\uff09<\/code><code>&nbsp; &nbsp; &nbsp;*\/<\/code><code>&nbsp; &nbsp;&nbsp;@PostMapping(\"\/recognize\")<\/code><code>&nbsp; &nbsp;&nbsp;@PreAuthorize(\"hasRole('DOCTOR') or hasRole('NURSE')\")&nbsp;\/\/ \u4ec5\u533b\u62a4\u4eba\u5458\u53ef\u8c03\u7528<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;JSONObject&nbsp;recognizeMedicalDoc(<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;@RequestParam(\"file\") MultipartFile file,<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;@RequestParam(\"docType\")&nbsp;String&nbsp;docType) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;JSONObject&nbsp;result =&nbsp;new&nbsp;JSONObject();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u4fdd\u5b58\u4e0a\u4f20\u7684\u6587\u4ef6\uff08\u907f\u514d\u6587\u4ef6\u540d\u91cd\u590d\uff0c\u7528UUID\u547d\u540d\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;originalFilename = file.getOriginalFilename();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;fileSuffix = originalFilename.substring(originalFilename.lastIndexOf(\".\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;fileName =&nbsp;UUID.randomUUID().toString() + fileSuffix;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;filePath = uploadPath +&nbsp;File.separator&nbsp;+ fileName;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;File&nbsp;destFile =&nbsp;new&nbsp;File(filePath);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; file.transferTo(destFile);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u6587\u6863\u9884\u5904\u7406\uff08PDF\u8f6c\u56fe\u7247\u2192\u56fe\u50cf\u4f18\u5316\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;imagePath = filePath;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(fileSuffix.equalsIgnoreCase(\".pdf\")) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagePath = preprocessService.pdfToImage(filePath);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;processedImagePath = preprocessService.preprocessImage(imagePath);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. OCR\u8bc6\u522b\u4e0e\u7ed3\u6784\u5316<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Map&lt;String,&nbsp;String&gt; structuredData = ocrRecognitionService.recognizeAndStructure(processedImagePath, docType);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 4. \u7ec4\u88c5\u8fd4\u56de\u7ed3\u679c<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"code\",&nbsp;200);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"msg\",&nbsp;\"\u8bc6\u522b\u6210\u529f\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"data\", structuredData);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"processedImageUrl\",&nbsp;\"\/images\/\"&nbsp;+ processedImagePath.substring(processedImagePath.lastIndexOf(\"\/\") +&nbsp;1));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(Exception&nbsp;e) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"code\",&nbsp;500);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"msg\",&nbsp;\"\u8bc6\u522b\u5931\u8d25\uff1a\"&nbsp;+ e.getMessage());<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;result;<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;\/**<\/code><code>&nbsp; &nbsp; &nbsp;* \u8bc6\u522b\u7ed3\u679c\u4eba\u5de5\u4fee\u6b63\u63a5\u53e3\uff08\u652f\u6301\u533b\u62a4\u4eba\u5458\u4fee\u6b63\u9519\u8bef\u6570\u636e\uff09<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@param&nbsp;correctedData \u4fee\u6b63\u540e\u7684\u7ed3\u6784\u5316\u6570\u636e<\/code><code>&nbsp; &nbsp; &nbsp;*&nbsp;@return&nbsp;\u4fee\u6b63\u7ed3\u679c<\/code><code>&nbsp; &nbsp; &nbsp;*\/<\/code><code>&nbsp; &nbsp;&nbsp;@PostMapping(\"\/correct\")<\/code><code>&nbsp; &nbsp;&nbsp;@PreAuthorize(\"hasRole('DOCTOR')\")&nbsp;\/\/ \u4ec5\u533b\u751f\u53ef\u4fee\u6b63<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;JSONObject&nbsp;correctResult(@RequestBody&nbsp;Map&lt;String,&nbsp;String&gt; correctedData) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;JSONObject&nbsp;result =&nbsp;new&nbsp;JSONObject();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u6b64\u5904\u53ef\u6dfb\u52a0\u201c\u4fee\u6b63\u7ed3\u679c\u4fdd\u5b58\u5230\u6570\u636e\u5e93\u201d\u7684\u903b\u8f91\uff08\u7565\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"code\",&nbsp;200);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"msg\",&nbsp;\"\u4fee\u6b63\u6210\u529f\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"data\", correctedData);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(Exception&nbsp;e) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"code\",&nbsp;500);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(\"msg\",&nbsp;\"\u4fee\u6b63\u5931\u8d25\uff1a\"&nbsp;+ e.getMessage());<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;result;<\/code><code>&nbsp; &nbsp; }<\/code><code>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u7279\u6b8a\u573a\u666f\u5904\u7406\u5b9e\u6218<\/h2>\n\n\n\n<p>\u533b\u7597\u573a\u666f\u4e2d\u7684 \u201c\u7279\u6b8a\u6587\u6863\u201d \u662f\u7cfb\u7edf\u843d\u5730\u7684\u5173\u952e\u6311\u6218\uff0c\u9700\u9488\u5bf9\u6027\u4f18\u5316\uff0c\u4ee5\u4e0b\u4e3a\u4e24\u7c7b\u5178\u578b\u573a\u666f\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u624b\u5199\u5904\u65b9\u8bc6\u522b\u4f18\u5316<\/h3>\n\n\n\n<p>\u624b\u5199\u5904\u65b9\u56e0\u5b57\u4f53\u6f66\u8349\u3001\u7b14\u753b\u8fde\u7b14\uff0c\u8bc6\u522b\u51c6\u786e\u7387\u4f4e\uff0c\u89e3\u51b3\u65b9\u6848\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u81ea\u5b9a\u4e49\u5b57\u5e93\u8bad\u7ec3<\/strong>\u6536\u96c6\u533b\u9662\u5e38\u7528\u624b\u5199\u5904\u65b9\u6837\u672c\uff08\u7ea6 500 \u4efd\uff09\uff0c\u4f7f\u7528 Tesseract \u7684<code>tesstrain.sh<\/code>\u5de5\u5177\u8bad\u7ec3 \u201c\u533b\u7597\u624b\u5199\u4e13\u7528\u5b57\u5e93\u201d\uff0c\u5c06\u5b57\u5e93\u6587\u4ef6\u653e\u5165<code>tessdata<\/code>\u76ee\u5f55\uff0c\u8bc6\u522b\u65f6\u52a0\u8f7d\uff08\u4ee3\u7801\u4e2d\u5df2\u914d\u7f6e<code>chi_sim+medical_custom<\/code>\uff09\u3002<\/li>\n\n\n\n<li><strong>\u591a\u7ef4\u5ea6\u6821\u9a8c<\/strong>\u8bc6\u522b\u540e\u901a\u8fc7 \u201c\u836f\u54c1\u5242\u91cf\u5408\u7406\u6027\u6821\u9a8c\u201d\uff08\u5982 \u201c\u963f\u83ab\u897f\u6797\u201d \u6210\u4eba\u5242\u91cf\u901a\u5e38\u4e3a 0.5g \/ \u6b21\uff0c\u82e5\u8bc6\u522b\u4e3a 5g \u5219\u63d0\u793a\u5f02\u5e38\uff09\u3001\u201c\u533b\u751f\u7b7e\u540d\u5339\u914d\u201d\uff08\u5bf9\u63a5\u533b\u9662\u533b\u751f\u7b7e\u540d\u5e93\uff09\u8fdb\u4e00\u6b65\u964d\u4f4e\u9519\u8bef\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5e26\u8868\u683c\u7684\u68c0\u67e5\u62a5\u544a\u5904\u7406<\/h3>\n\n\n\n<p>\u68c0\u67e5\u62a5\u544a\u5e38\u5305\u542b\u8868\u683c\uff08\u5982\u8840\u5e38\u89c4\u62a5\u544a\uff09\uff0c\u8868\u683c\u7ebf\u4f1a\u5e72\u6270 OCR \u8bc6\u522b\uff0c\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8868\u683c\u7ebf\u53bb\u9664<\/strong>\u5728<code>preprocessImage<\/code>\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u8868\u683c\u7ebf\u53bb\u9664\u903b\u8f91\uff0c\u901a\u8fc7 \u201c\u8f6e\u5ed3\u68c0\u6d4b\u201d \u8bc6\u522b\u8868\u683c\u7ebf\uff08\u6a2a\u7eb5\u76f4\u7ebf\uff09\uff0c\u7528\u767d\u8272\u50cf\u7d20\u8986\u76d6\uff1a<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>\/\/ \u8868\u683c\u7ebf\u53bb\u9664\uff08\u65b0\u589e\u4ee3\u7801\uff09<\/code><code>Mat&nbsp;tableLineMask&nbsp;=&nbsp;new&nbsp;Mat();<\/code><code>Imgproc.threshold(dst, tableLineMask,&nbsp;200,&nbsp;255, Imgproc.THRESH_BINARY_INV);<\/code><code>Mat&nbsp;kernel&nbsp;=&nbsp;Imgproc.getStructuringElement(Imgproc.MORPH_RECT,&nbsp;new&nbsp;Size(3,&nbsp;3));<\/code><code>Imgproc.morphologyEx(tableLineMask, tableLineMask, Imgproc.MORPH_OPEN, kernel);<\/code><code>dst.setTo(new&nbsp;Scalar(255), tableLineMask);&nbsp;\/\/ \u767d\u8272\u8986\u76d6\u8868\u683c\u7ebf<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8868\u683c\u5185\u5bb9\u5bf9\u9f50<\/strong>\u8bc6\u522b\u540e\u901a\u8fc7 \u201c\u884c\u5206\u5272\u201d\u201c\u5217\u5206\u5272\u201d \u903b\u8f91\uff0c\u5c06\u8868\u683c\u6570\u636e\u6309\u884c \/ \u5217\u5bf9\u5e94\uff08\u5982 \u201c\u767d\u7ec6\u80de\u201d \u5bf9\u5e94 \u201c5.6\u00d710^9\/L\u201d\uff09\uff0c\u786e\u4fdd\u7ed3\u6784\u5316\u7ed3\u679c\u4e0e\u8868\u683c\u5e03\u5c40\u4e00\u81f4\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u7cfb\u7edf\u90e8\u7f72\u4e0e\u5b9e\u9645\u5e94\u7528<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u90e8\u7f72\u6ce8\u610f\u4e8b\u9879<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Tesseract \u5b57\u5e93\u90e8\u7f72<\/strong>\u5c06 \u201c\u4e2d\u6587\u57fa\u7840\u5b57\u5e93\uff08chi_sim.traineddata\uff09\u201d \u4e0e \u201c\u533b\u7597\u81ea\u5b9a\u4e49\u5b57\u5e93\uff08medical_custom.traineddata\uff09\u201d \u653e\u5165\u670d\u52a1\u5668\u7684<code>tessdata<\/code>\u76ee\u5f55\uff0c\u5728<code>application.yml<\/code>\u4e2d\u914d\u7f6e<code>\u00a0tesseract.tessdata.path: \/usr\/local\/tesseract\/tessdata<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u533b\u7597\u6570\u636e\u5b89\u5168<\/strong>\u901a\u8fc7 Spring Security \u914d\u7f6e HTTPS\uff0c\u6240\u6709\u4e0a\u4f20\u6587\u4ef6\u52a0\u5bc6\u5b58\u50a8\uff0c\u6570\u636e\u5e93\u4e2d\u60a3\u8005\u4fe1\u606f\u8131\u654f\uff08\u5982\u59d3\u540d\u663e\u793a\u4e3a \u201c\u5f20 * \u4e09\u201d\uff09\uff0c\u64cd\u4f5c\u65e5\u5fd7\u8bb0\u5f55\u533b\u62a4\u4eba\u5458\u7684\u6587\u6863\u8bbf\u95ee\u884c\u4e3a\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5b9e\u9645\u5e94\u7528\u6548\u679c<\/h3>\n\n\n\n<p>\u67d0\u793e\u533a\u533b\u9662\u8bd5\u70b9\u90e8\u7f72\u8be5\u7cfb\u7edf\u540e\uff0c\u6548\u679c\u663e\u8457\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6548\u7387\u63d0\u5347<\/strong>\u533b\u62a4\u4eba\u5458\u5904\u7406\u75c5\u5386\u7684\u65f6\u95f4\u4ece\u5e73\u5747 15 \u5206\u949f \/ \u4efd\u964d\u81f3 3 \u5206\u949f \/ \u4efd\uff0c\u65e5\u5747\u5904\u7406\u91cf\u4ece 50 \u4efd\u63d0\u5347\u81f3 200 \u4efd\u3002<\/li>\n\n\n\n<li><strong>\u51c6\u786e\u6027\u63d0\u5347<\/strong>\u6838\u5fc3\u533b\u7597\u5b57\u6bb5\u8bc6\u522b\u51c6\u786e\u7387\u4ece\u4eba\u5de5\u5f55\u5165\u7684 92% \u63d0\u5347\u81f3 97%\uff0c\u5904\u65b9\u9519\u8bef\u7387\u4e0b\u964d 60%\u3002<\/li>\n\n\n\n<li><strong>\u7528\u6237\u53cd\u9988<\/strong>85% \u7684\u533b\u62a4\u4eba\u5458\u8868\u793a \u201c\u7cfb\u7edf\u964d\u4f4e\u4e86\u6587\u6863\u5904\u7406\u8d1f\u62c5\uff0c\u80fd\u66f4\u4e13\u6ce8\u4e8e\u60a3\u8005\u8bca\u7597\u201d\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001\u603b\u7ed3\u4e0e\u6269\u5c55\u65b9\u5411<\/h2>\n\n\n\n<p>\u672c\u6587\u57fa\u4e8e SpringBoot3.x \u4e0e OCR \u6784\u5efa\u4e86\u4e00\u5957\u53ef\u843d\u5730\u7684\u533b\u7597\u8f85\u52a9\u7cfb\u7edf\uff0c\u4ece\u9700\u6c42\u5b9a\u4e49\u5230\u4ee3\u7801\u5b9e\u73b0\uff0c\u5b8c\u6574\u8986\u76d6\u4e86\u533b\u7597\u6587\u6863\u7684 \u201c\u4e0a\u4f20\u2192\u9884\u5904\u7406\u2192\u8bc6\u522b\u2192\u7ed3\u6784\u5316\u201d \u5168\u6d41\u7a0b\uff0c\u91cd\u70b9\u89e3\u51b3\u4e86\u533b\u7597\u573a\u666f\u4e2d\u7684\u7279\u6b8a\u6587\u6863\u5904\u7406\u4e0e\u6570\u636e\u5b89\u5168\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u672a\u6765\u53ef\u4ece\u4ee5\u4e0b\u65b9\u5411\u6269\u5c55\u7cfb\u7edf\u80fd\u529b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>AI \u8f85\u52a9\u8bca\u65ad<\/strong>\u7ed3\u5408 LLM\uff08\u5982\u533b\u7597\u4e13\u7528\u5927\u6a21\u578b\uff09\uff0c\u5c06\u7ed3\u6784\u5316\u7684\u68c0\u67e5\u62a5\u544a\u8f6c\u5316\u4e3a \u201c\u8bca\u65ad\u5efa\u8bae\u201d\uff08\u5982 \u201c\u767d\u7ec6\u80de\u5347\u9ad8\uff0c\u63d0\u793a\u7ec6\u83cc\u611f\u67d3\u53ef\u80fd\u201d\uff09\u3002<\/li>\n\n\n\n<li><strong>\u533b\u9662\u7cfb\u7edf\u5bf9\u63a5<\/strong>\u5bf9\u63a5\u533b\u9662 HIS\uff08\u533b\u9662\u4fe1\u606f\u7cfb\u7edf\uff09\u3001LIS\uff08\u68c0\u9a8c\u4fe1\u606f\u7cfb\u7edf\uff09\uff0c\u5b9e\u73b0\u8bc6\u522b\u7ed3\u679c\u81ea\u52a8\u5f55\u5165\u533b\u9662\u7cfb\u7edf\uff0c\u65e0\u9700\u4eba\u5de5\u4e8c\u6b21\u5f55\u5165\u3002<\/li>\n\n\n\n<li><strong>\u79fb\u52a8\u7aef\u9002\u914d<\/strong>\u5f00\u53d1\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\uff0c\u652f\u6301\u533b\u62a4\u4eba\u5458\u7528\u624b\u673a\u62cd\u6444\u75c5\u5386 \/ \u5904\u65b9\uff0c\u5b9e\u65f6\u4e0a\u4f20\u8bc6\u522b\uff0c\u6ee1\u8db3\u51fa\u8bca\u3001\u5c45\u5bb6\u4f1a\u8bca\u7b49\u573a\u666f\u9700\u6c42\u3002<\/li>\n<\/ul>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u5728\u533b\u7597\u884c\u4e1a\u6570\u5b57\u5316\u8f6c\u578b\u8fc7\u7a0b\u4e2d\uff0c\u201c\u6587\u6863\u5904\u7406\u6548\u7387\u201d \u4e0e \u201c\u6570\u636e\u51c6\u786e\u6027\u201d \u4e00\u76f4\u662f\u533b\u62a4\u4eba\u5458\u9762\u4e34\u7684\u6838\u5fc3\u75db\u70b9 \u2014\u2014 \u4ece\u7eb8\u8d28\u75c5\u5386\u7684\u624b\u5de5\u5f55\u5165\u3001\u68c0\u67e5\u62a5 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-6685","post","type-post","status-publish","format-standard","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929044956776.png","id":"image1"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2025-09-29","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":176,"next_post_id":6688,"next_post_title":"\u5f00\u6e90\u514d\u8d39\u3001\u7b80\u5355\u6613\u7528\u89c6\u9891\u8054\u52a8\u7269\u8054\u7f51\u5e73\u53f0\uff0c\u66f4\u9002\u5408\u4e2d\u5c0f\u4f01\u4e1a\u548c\u4e2a\u4eba\u5b66\u4e60\u4f7f\u7528","previous_post_id":6669,"previous_post_title":"\u4ece 0 \u5230 1\uff0c\u5b9e\u6218 SpringBoot \u6253\u9020\u8f7b\u91cf\u89c6\u9891\u63a8\u62c9\u6d41\u7cfb\u7edf","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=6685"}],"version-history":[{"count":1,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6685\/revisions"}],"predecessor-version":[{"id":6687,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6685\/revisions\/6687"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}