{"id":6736,"date":"2025-09-29T13:54:51","date_gmt":"2025-09-29T05:54:51","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6736"},"modified":"2025-09-29T13:54:59","modified_gmt":"2025-09-29T05:54:59","slug":"%e5%9f%ba%e4%ba%8e-java-%e4%b8%8e-yolov8-%e5%ae%9e%e7%8e%b0%e8%a1%a8%e6%a0%bc%e5%9b%be%e5%83%8f%e8%a1%8c%e5%88%97%e6%a3%80%e6%b5%8b%e7%9a%84%e5%ae%8c%e6%95%b4%e5%ae%9e%e8%b7%b5","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/java\/%e5%9f%ba%e4%ba%8e-java-%e4%b8%8e-yolov8-%e5%ae%9e%e7%8e%b0%e8%a1%a8%e6%a0%bc%e5%9b%be%e5%83%8f%e8%a1%8c%e5%88%97%e6%a3%80%e6%b5%8b%e7%9a%84%e5%ae%8c%e6%95%b4%e5%ae%9e%e8%b7%b5\/","title":{"rendered":"\u57fa\u4e8e Java \u4e0e YOLOv8 \u5b9e\u73b0\u8868\u683c\u56fe\u50cf\u884c\u5217\u68c0\u6d4b\u7684\u5b8c\u6574\u5b9e\u8df5"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u5f15\u8a00\uff1a\u8868\u683c\u68c0\u6d4b\u7684\u4ef7\u503c\u4e0e\u6280\u672f\u9009\u578b<\/h2>\n\n\n\n<p>\u5728\u6587\u6863\u6570\u5b57\u5316\u3001\u6570\u636e\u81ea\u52a8\u5316\u5f55\u5165\u7b49\u573a\u666f\u4e2d\uff0c\u8868\u683c\u4f5c\u4e3a\u4fe1\u606f\u627f\u8f7d\u7684\u91cd\u8981\u5f62\u5f0f\uff0c\u5176\u7ed3\u6784\uff08\u884c\u3001\u5217\uff09\u7684\u7cbe\u51c6\u68c0\u6d4b\u662f\u540e\u7eed\u8868\u683c\u8bc6\u522b\u3001\u6570\u636e\u63d0\u53d6\u7684\u6838\u5fc3\u524d\u63d0\u3002\u4f20\u7edf\u7684\u8868\u683c\u68c0\u6d4b\u65b9\u6cd5\uff08\u5982\u57fa\u4e8e\u89c4\u5219\u7684\u8fb9\u7f18\u68c0\u6d4b\uff09\u5bf9\u590d\u6742\u8868\u683c\uff08\u5982\u503e\u659c\u3001\u6a21\u7cca\u3001\u5408\u5e76\u5355\u5143\u683c\uff09\u9002\u5e94\u6027\u8f83\u5dee\uff0c\u800c\u57fa\u4e8e\u6df1\u5ea6\u5b66\u4e60\u7684\u76ee\u6807\u68c0\u6d4b\u6280\u672f\u80fd\u6709\u6548\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u3002<\/p>\n\n\n\n<p>YOLO\uff08You Only Look Once\uff09\u7cfb\u5217\u6a21\u578b\u4f5c\u4e3a\u5b9e\u65f6\u76ee\u6807\u68c0\u6d4b\u7684\u6807\u6746\uff0c\u5176\u6700\u65b0\u7248\u672c<strong>YOLOv8<\/strong>\u5728\u901f\u5ea6\u4e0e\u7cbe\u5ea6\u4e0a\u5747\u6709\u663e\u8457\u63d0\u5347\uff0c\u652f\u6301\u7075\u6d3b\u7684\u6a21\u578b\u5bfc\u51fa\u4e0e\u8de8\u5e73\u53f0\u90e8\u7f72\u3002\u800c Java \u4f5c\u4e3a\u4f01\u4e1a\u7ea7\u5e94\u7528\u7684\u4e3b\u6d41\u5f00\u53d1\u8bed\u8a00\uff0c\u5728\u7a33\u5b9a\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u4e0a\u5177\u5907\u5929\u7136\u4f18\u52bf\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u57fa\u4e8e Java \u7ed3\u5408 YOLOv8 \u7684 ONNX \u6a21\u578b\uff0c\u5b9e\u73b0\u8868\u683c\u56fe\u50cf\u4e2d\u884c\u4e0e\u5217\u7684\u9ad8\u6548\u68c0\u6d4b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u73af\u5883\u51c6\u5907\uff1a\u642d\u5efa\u5f00\u53d1\u4e0e\u8fd0\u884c\u73af\u5883<\/h2>\n\n\n\n<p>\u5728\u5f00\u59cb\u7f16\u7801\u524d\uff0c\u9700\u5b8c\u6210\u4f9d\u8d56\u914d\u7f6e\u3001\u6a21\u578b\u51c6\u5907\u7b49\u57fa\u7840\u5de5\u4f5c\uff0c\u786e\u4fdd\u540e\u7eed\u6d41\u7a0b\u987a\u7545\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.1 \u5f00\u53d1\u5de5\u5177\u4e0e\u57fa\u7840\u73af\u5883<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>JDK<\/strong>\uff1a\u63a8\u8350 JDK 11 \u53ca\u4ee5\u4e0a\uff08\u517c\u5bb9 ONNX Runtime \u4e0e OpenCV\uff09<\/li>\n\n\n\n<li><strong>IDE<\/strong>\uff1aIntelliJ IDEA\uff08\u6216 Eclipse\uff09<\/li>\n\n\n\n<li><strong>\u4f9d\u8d56\u7ba1\u7406<\/strong>\uff1aMaven\uff08\u7b80\u5316\u4f9d\u8d56\u5f15\u5165\u4e0e\u7248\u672c\u63a7\u5236\uff09<\/li>\n\n\n\n<li><strong>\u56fe\u50cf\u5904\u7406<\/strong>\uff1aOpenCV 4.7.0\uff08\u8d1f\u8d23\u56fe\u50cf\u8bfb\u53d6\u3001\u9884\u5904\u7406\uff09<\/li>\n\n\n\n<li><strong>\u6a21\u578b\u63a8\u7406<\/strong>\uff1aONNX Runtime 1.16.3\uff08\u52a0\u8f7d YOLOv8 ONNX \u6a21\u578b\u5e76\u6267\u884c\u63a8\u7406\uff09<\/li>\n\n\n\n<li><strong>JSON \u89e3\u6790<\/strong>\uff1aFastJSON2\uff08\u5904\u7406\u68c0\u6d4b\u7ed3\u679c\u7684\u5e8f\u5217\u5316\uff09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2.2 Maven \u4f9d\u8d56\u914d\u7f6e<\/h3>\n\n\n\n<p>\u89c1\u9879\u76ee\u4e2d\u7684pom.xml<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2.3 \u6a21\u578b\u4e0e\u6807\u7b7e\u6587\u4ef6\u51c6\u5907<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\uff081\uff09YOLOv8 ONNX \u6a21\u578b<\/h4>\n\n\n\n<p>\u9700\u5148\u8bad\u7ec3\u4e00\u4e2a\u7528\u4e8e \u201c\u8868\u683c\u884c\u5217\u68c0\u6d4b\u201d \u7684 YOLOv8 \u6a21\u578b\uff0c\u518d\u5bfc\u51fa\u4e3a ONNX \u683c\u5f0f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 Ultralytics \u5e93\u8bad\u7ec3 YOLOv8\uff1a\u6807\u6ce8\u8868\u683c\u56fe\u50cf\u4e2d\u7684 \u201c\u884c\uff08row\uff09\u201d \u548c \u201c\u5217\uff08column\uff09\u201d \u4f5c\u4e3a\u76ee\u6807\u7c7b\u522b\uff0c\u751f\u6210\u8bad\u7ec3\u6570\u636e\u96c6\u3002<\/li>\n\n\n\n<li>\u5bfc\u51fa ONNX \u6a21\u578b\uff1a\u901a\u8fc7 Ultralytics \u7684<code>export<\/code>\u65b9\u6cd5\uff0c\u6307\u5b9a<code>format=\"onnx\"<\/code>\uff0c\u793a\u4f8b\u4ee3\u7801\uff08Python\uff09\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>from&nbsp;ultralytics&nbsp;import&nbsp;YOLO<\/code><code># \u52a0\u8f7d\u8bad\u7ec3\u597d\u7684YOLOv8\u6a21\u578b<\/code><code>model = YOLO(\"runs\/detect\/train\/weights\/best.pt\")<\/code><code># \u5bfc\u51fa\u4e3aONNX\u683c\u5f0f\uff08\u8f93\u5165\u5c3a\u5bf8\u4e0e\u4ee3\u7801\u4e2d\u4fdd\u6301\u4e00\u81f4\uff0c\u5982640x640\uff09<\/code><code>model.export(format=\"onnx\", imgsz=640, nms=False) &nbsp;# nms=False\uff1a\u4ee3\u7801\u4e2d\u81ea\u884c\u5b9e\u73b0NMS<\/code><\/pre>\n\n\n\n<p>3.\u5c06\u5bfc\u51fa\u7684 ONNX \u6a21\u578b\uff08\u5982<code>table_det_yolov8.onnx<\/code>\uff09\u653e\u5165\u9879\u76ee<code>resources\/model<\/code>\u76ee\u5f55\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\uff082\uff09\u6807\u7b7e\u6587\u4ef6<\/h4>\n\n\n\n<p>\u521b\u5efa\u6807\u7b7e\u6587\u4ef6<code>table_labels.txt<\/code>\uff0c\u5b9a\u4e49\u68c0\u6d4b\u7c7b\u522b\uff08\u4e0e\u8bad\u7ec3\u65f6\u4e00\u81f4\uff09\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/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>row<\/code><code>column<\/code><\/pre>\n\n\n\n<p>\u5c06\u8be5\u6587\u4ef6\u653e\u5165\u9879\u76ee<code>resources\/labels<\/code>\u76ee\u5f55\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">(3\uff09\u914d\u7f6e\u6587\u4ef6<\/h4>\n\n\n\n<p>\u521b\u5efa<code>config.properties<\/code>\u914d\u7f6e\u6587\u4ef6\uff0c\u7edf\u4e00\u7ba1\u7406\u8def\u5f84\uff08\u907f\u514d\u786c\u7f16\u7801\uff09\uff1a<\/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># \u6a21\u578b\u8def\u5f84\uff08\u76f8\u5bf9\u4e8eresources\u76ee\u5f55\uff09<\/code><code>model_path=model\/table_det_yolov8.onnx<\/code><code># \u6807\u7b7e\u6587\u4ef6\u8def\u5f84\uff08\u76f8\u5bf9\u4e8eresources\u76ee\u5f55\uff09<\/code><code>table_det_labels_path=labels\/table_labels.txt<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u6838\u5fc3\u4ee3\u7801\u89e3\u6790\uff1a\u4ece\u6a21\u578b\u52a0\u8f7d\u5230\u7ed3\u679c\u8f93\u51fa<\/h2>\n\n\n\n<p>\u6838\u5fc3\u4ee3\u7801\u5206\u4e3a\u4e24\u4e2a\u7c7b\uff1a<code>ModelDet<\/code>\uff08\u6a21\u578b\u5c01\u88c5\u4e0e\u68c0\u6d4b\u903b\u8f91\uff09\u548c<code>MainTest<\/code>\uff08\u4e3b\u51fd\u6570\u8c03\u7528\u4e0e\u6d41\u7a0b\u63a7\u5236\uff09\u3002\u4ee5\u4e0b\u9010\u6a21\u5757\u89e3\u6790\u5173\u952e\u903b\u8f91\u3002\u5b8c\u6210\u9879\u76ee\uff1ahttps:\/\/github.com\/jiangnanboy\/table_row_column_detection<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.1 \u6838\u5fc3\u68c0\u6d4b\u7c7b\uff1aModelDet<\/h3>\n\n\n\n<p><code>ModelDet<\/code>\u662f\u6574\u4e2a\u68c0\u6d4b\u6d41\u7a0b\u7684\u6838\u5fc3\uff0c\u8d1f\u8d23\u6a21\u578b\u521d\u59cb\u5316\u3001\u56fe\u50cf\u9884\u5904\u7406\u3001\u63a8\u7406\u6267\u884c\u3001\u8f93\u51fa\u89e3\u6790\u7b49\u529f\u80fd\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3.1.1 \u7c7b\u7ed3\u6784\u4e0e\u6838\u5fc3\u5c5e\u6027<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>package&nbsp;sy;<\/code><code>import&nbsp;ai.onnxruntime.*;<\/code><code>import&nbsp;org.opencv.core.CvType;<\/code><code>import&nbsp;org.opencv.core.Mat;<\/code><code>import&nbsp;org.opencv.core.Size;<\/code><code>import&nbsp;org.opencv.imgproc.Imgproc;<\/code><code>import&nbsp;utils.CollectionUtil;<\/code><code>import&nbsp;java.io.IOException;<\/code><code>import&nbsp;java.nio.FloatBuffer;<\/code><code>import&nbsp;java.nio.file.Files;<\/code><code>import&nbsp;java.nio.file.Paths;<\/code><code>import&nbsp;java.util.*;<\/code><code>import&nbsp;java.util.stream.Collectors;<\/code><code>import&nbsp;java.util.stream.Stream;<\/code><code>public&nbsp;class&nbsp;ModelDet&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u68c0\u6d4b\u9608\u503c\uff1a\u7f6e\u4fe1\u5ea6\u9608\u503c\uff08\u8fc7\u6ee4\u4f4e\u7f6e\u4fe1\u5ea6\u7ed3\u679c\uff09\u3001IOU\u9608\u503c\uff08NMS\u7528\uff0c\u8fc7\u6ee4\u91cd\u590d\u6846\uff09<\/code><code>&nbsp; &nbsp;&nbsp;float&nbsp;confThreshold;<\/code><code>&nbsp; &nbsp;&nbsp;float&nbsp;iouThreshold;<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u6a21\u578b\u8f93\u5165\u76f8\u5173\uff1a\u8f93\u5165\u5c3a\u5bf8\u3001\u5f62\u72b6\u3001\u5143\u7d20\u6570\u91cf\u3001\u6570\u636e\u7c7b\u578b<\/code><code>&nbsp; &nbsp;&nbsp;long&nbsp;inputHeight;<\/code><code>&nbsp; &nbsp;&nbsp;long&nbsp;inputWidth;<\/code><code>&nbsp; &nbsp;&nbsp;long[] inputShape;<\/code><code>&nbsp; &nbsp;&nbsp;int&nbsp;numInputElements;<\/code><code>&nbsp; &nbsp; OnnxJavaType inputType;<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ ONNX Runtime\u76f8\u5173\uff1a\u73af\u5883\u3001\u4f1a\u8bdd\u3001\u8f93\u5165\u8f93\u51fa\u540d\u79f0<\/code><code>&nbsp; &nbsp; OrtEnvironment env;<\/code><code>&nbsp; &nbsp; OrtSession session;<\/code><code>&nbsp; &nbsp; String inputName;<\/code><code>&nbsp; &nbsp; String outputName;<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u539f\u56fe\u5c3a\u5bf8\uff08\u7528\u4e8e\u5c06\u6a21\u578b\u8f93\u51fa\u7684\u5750\u6807\u7f29\u653e\u56de\u539f\u56fe\uff09<\/code><code>&nbsp; &nbsp;&nbsp;long&nbsp;rawImgHeight;<\/code><code>&nbsp; &nbsp;&nbsp;long&nbsp;rawImgWidth;<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u6807\u7b7e\u5217\u8868\uff08\u884c\u3001\u5217\uff09<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;List&lt;String&gt; labelNames;<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u7701\u7565\u6784\u9020\u65b9\u6cd5\u4e0e\u5176\u4ed6\u65b9\u6cd5...<\/code><code>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3.1.2 \u6a21\u578b\u4e0e\u6807\u7b7e\u521d\u59cb\u5316<\/h4>\n\n\n\n<p>\u521d\u59cb\u5316 ONNX Runtime \u73af\u5883\u3001\u52a0\u8f7d\u6a21\u578b\uff0c\u5e76\u8bfb\u53d6\u6807\u7b7e\u6587\u4ef6\uff1a<\/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>\/\/ \u6784\u9020\u65b9\u6cd5\uff1a\u9ed8\u8ba4\u9608\u503c\uff08\u7f6e\u4fe1\u5ea60.3\uff0cIOU 0.5\uff09<\/code><code>public&nbsp;ModelDet(String path, String labelPath) throws OrtException {<\/code><code>&nbsp; &nbsp;&nbsp;this(path, labelPath,&nbsp;0.3f,&nbsp;0.5f);<\/code><code>}<\/code><code>\/\/ \u6784\u9020\u65b9\u6cd5\uff1a\u81ea\u5b9a\u4e49\u9608\u503c<\/code><code>public&nbsp;ModelDet(String path, String labelPath, float confThres, float iouThres) throws OrtException {<\/code><code>&nbsp; &nbsp;&nbsp;this.confThreshold = confThres;<\/code><code>&nbsp; &nbsp;&nbsp;this.iouThreshold = iouThres;<\/code><code>&nbsp; &nbsp; initializeModel(path);&nbsp;\/\/ \u521d\u59cb\u5316\u6a21\u578b<\/code><code>&nbsp; &nbsp; initializeLabel(labelPath);&nbsp;\/\/ \u521d\u59cb\u5316\u6807\u7b7e<\/code><code>}<\/code><code>\/\/ \u521d\u59cb\u5316ONNX\u6a21\u578b\uff08\u652f\u6301CPU\/GPU\uff09<\/code><code>private&nbsp;void initializeModel(String path) throws OrtException {<\/code><code>&nbsp; &nbsp; nu.pattern.OpenCV.loadLocally();&nbsp;\/\/ \u52a0\u8f7dOpenCV\u672c\u5730\u5e93<\/code><code>&nbsp; &nbsp;&nbsp;this.initializeModel(path, -1);&nbsp;\/\/ \u9ed8\u8ba4CPU\uff08-1\u8868\u793a\u4e0d\u4f7f\u7528GPU\uff09<\/code><code>}<\/code><code>\/\/ \u91cd\u8f7d\uff1a\u652f\u6301\u6307\u5b9aGPU\u8bbe\u5907ID<\/code><code>private&nbsp;void initializeModel(String path, int gpuDeviceId) throws OrtException {<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 1. \u521b\u5efaONNX\u73af\u5883<\/code><code>&nbsp; &nbsp;&nbsp;this.env = OrtEnvironment.getEnvironment();<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 2. \u914d\u7f6e\u4f1a\u8bdd\u9009\u9879\uff08\u5f00\u542f\u6240\u6709\u4f18\u5316\uff09<\/code><code>&nbsp; &nbsp;&nbsp;var&nbsp;sessionOptions = new OrtSession.SessionOptions();<\/code><code>&nbsp; &nbsp; sessionOptions.setOptimizationLevel(OrtSession.SessionOptions.OptLevel.ALL_OPT);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 3. \u914d\u7f6eCPU\/GPU<\/code><code>&nbsp; &nbsp;&nbsp;if&nbsp;(gpuDeviceId &gt;=&nbsp;0) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; sessionOptions.addCPU(false);&nbsp;\/\/ \u7981\u7528CPU<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; sessionOptions.addCUDA(gpuDeviceId);&nbsp;\/\/ \u542f\u7528\u6307\u5b9aGPU<\/code><code>&nbsp; &nbsp; }&nbsp;else&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; sessionOptions.addCPU(true);&nbsp;\/\/ \u542f\u7528CPU<\/code><code>&nbsp; &nbsp; }<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 4. \u52a0\u8f7d\u6a21\u578b\u5e76\u521b\u5efa\u4f1a\u8bdd<\/code><code>&nbsp; &nbsp;&nbsp;this.session =&nbsp;this.env.createSession(path, sessionOptions);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 5. \u83b7\u53d6\u6a21\u578b\u8f93\u5165\u4fe1\u606f\uff08\u8f93\u5165\u540d\u79f0\u3001\u5f62\u72b6\u3001\u6570\u636e\u7c7b\u578b\uff09<\/code><code>&nbsp; &nbsp; Map&lt;String, NodeInfo&gt; inputMetaMap =&nbsp;this.session.getInputInfo();<\/code><code>&nbsp; &nbsp;&nbsp;this.inputName =&nbsp;this.session.getInputNames().iterator().next();&nbsp;\/\/ \u8f93\u5165\u540d\u79f0\uff08YOLOv8\u901a\u5e38\u4e3a\"images\"\uff09<\/code><code>&nbsp; &nbsp; NodeInfo inputMeta = inputMetaMap.get(this.inputName);<\/code><code>&nbsp; &nbsp;&nbsp;this.inputType = ((TensorInfo) inputMeta.getInfo()).type;&nbsp;\/\/ \u8f93\u5165\u6570\u636e\u7c7b\u578b\uff08\u901a\u5e38\u4e3aFLOAT\uff09<\/code><code>&nbsp; &nbsp;&nbsp;this.inputShape = ((TensorInfo) inputMeta.getInfo()).getShape();&nbsp;\/\/ \u8f93\u5165\u5f62\u72b6\uff08\u5982[1,3,640,640]\uff09<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 6. \u8ba1\u7b97\u8f93\u5165\u5143\u7d20\u603b\u6570\uff08\u7528\u4e8e\u521d\u59cb\u5316\u6570\u636e\u7f13\u51b2\u533a\uff09<\/code><code>&nbsp; &nbsp;&nbsp;this.numInputElements = (int) (this.inputShape[1] *&nbsp;this.inputShape[2] *&nbsp;this.inputShape[3]);<\/code><code>&nbsp; &nbsp;&nbsp;this.inputHeight =&nbsp;this.inputShape[2];&nbsp;\/\/ \u6a21\u578b\u8f93\u5165\u9ad8\u5ea6\uff08\u5982640\uff09<\/code><code>&nbsp; &nbsp;&nbsp;this.inputWidth =&nbsp;this.inputShape[3];&nbsp;\/\/ \u6a21\u578b\u8f93\u5165\u5bbd\u5ea6\uff08\u5982640\uff09<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 7. \u83b7\u53d6\u6a21\u578b\u8f93\u51fa\u540d\u79f0\uff08YOLOv8\u901a\u5e38\u4e3a\"output0\"\uff09<\/code><code>&nbsp; &nbsp;&nbsp;this.outputName =&nbsp;this.session.getOutputNames().iterator().next();<\/code><code>}<\/code><code>\/\/ \u521d\u59cb\u5316\u6807\u7b7e\uff08\u8bfb\u53d6label\u6587\u4ef6\uff09<\/code><code>private&nbsp;void initializeLabel(String labelPath) {<\/code><code>&nbsp; &nbsp;&nbsp;try&nbsp;(Stream&lt;String&gt; lines = Files.lines(Paths.get(labelPath))) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u8bfb\u53d6\u6bcf\u884c\u6807\u7b7e\uff0c\u53bb\u9664\u7a7a\u683c\uff0c\u5b58\u5165\u5217\u8868<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; labelNames = lines.map(line -&gt; line.strip()).collect(Collectors.toList());<\/code><code>&nbsp; &nbsp; }&nbsp;catch&nbsp;(IOException e) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw&nbsp;new RuntimeException(\"\u6807\u7b7e\u6587\u4ef6\u52a0\u8f7d\u5931\u8d25\uff1a\"&nbsp;+ labelPath);<\/code><code>&nbsp; &nbsp; }<\/code><code>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3.1.3 \u56fe\u50cf\u9884\u5904\u7406\uff1a\u5c06\u539f\u56fe\u8f6c\u6362\u4e3a\u6a21\u578b\u8f93\u5165\u683c\u5f0f<\/h4>\n\n\n\n<p>YOLOv8 \u6a21\u578b\u5bf9\u8f93\u5165\u56fe\u50cf\u6709\u4e25\u683c\u8981\u6c42\uff0c\u9700\u7ecf\u8fc7<strong>\u901a\u9053\u8f6c\u6362\u3001\u5c3a\u5bf8\u7f29\u653e\u3001\u5f52\u4e00\u5316\u3001\u7ef4\u5ea6\u8f6c\u6362<\/strong>\u56db\u6b65\u9884\u5904\u7406\uff1a<\/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>\/\/ \u51c6\u5907\u6a21\u578b\u8f93\u5165\uff1a\u5c06OpenCV\u7684Mat\u56fe\u50cf\u8f6c\u6362\u4e3aONNX Tensor<\/code><code>private&nbsp;Map&lt;String, OnnxTensor&gt; prepareInput(Mat img) throws OrtException {<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 1. \u8bb0\u5f55\u539f\u56fe\u5c3a\u5bf8\uff08\u540e\u7eed\u7528\u4e8e\u7f29\u653e\u68c0\u6d4b\u6846\uff09<\/code><code>&nbsp; &nbsp;&nbsp;this.rawImgHeight = img.height();<\/code><code>&nbsp; &nbsp;&nbsp;this.rawImgWidth = img.width();<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 2. \u901a\u9053\u8f6c\u6362\uff1aBGR\uff08OpenCV\u9ed8\u8ba4\uff09\u2192 RGB\uff08YOLOv8\u8bad\u7ec3\u65f6\u4f7f\u7528\u7684\u683c\u5f0f\uff09<\/code><code>&nbsp; &nbsp; Mat inputImg = new Mat();<\/code><code>&nbsp; &nbsp; Imgproc.cvtColor(img, inputImg, Imgproc.COLOR_BGR2RGB);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 3. \u5c3a\u5bf8\u7f29\u653e\uff1a\u5c06\u56fe\u50cf\u7f29\u653e\u5230\u6a21\u578b\u8f93\u5165\u5c3a\u5bf8\uff08\u5982640x640\uff09<\/code><code>&nbsp; &nbsp; Imgproc.resize(inputImg, inputImg, new Size(this.inputWidth,&nbsp;this.inputHeight));<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 4. \u5f52\u4e00\u5316\uff1a\u50cf\u7d20\u503c\u4ece[0,255]\u2192[0,1]\uff08\u6a21\u578b\u8bad\u7ec3\u65f6\u7684\u9884\u5904\u7406\u903b\u8f91\uff09<\/code><code>&nbsp; &nbsp; inputImg.convertTo(inputImg, CvType.CV_32FC3,&nbsp;1.0&nbsp;\/&nbsp;255.0);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 5. \u7ef4\u5ea6\u8f6c\u6362\uff1aHWC\uff08\u9ad8\u5ea6\u3001\u5bbd\u5ea6\u3001\u901a\u9053\uff09\u2192 CHW\uff08\u901a\u9053\u3001\u9ad8\u5ea6\u3001\u5bbd\u5ea6\uff09<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ OpenCV\u8bfb\u53d6\u7684Mat\u683c\u5f0f\u4e3aHWC\uff0c\u800cONNX\u6a21\u578b\u8f93\u5165\u683c\u5f0f\u4e3aNCHW\uff08N\u4e3a\u6279\u91cf\u5927\u5c0f\uff0c\u8fd9\u91cc\u4e3a1\uff09<\/code><code>&nbsp; &nbsp; float[] whcData = new float[this.numInputElements];<\/code><code>&nbsp; &nbsp; inputImg.get(0,&nbsp;0, whcData);&nbsp;\/\/ \u5c06Mat\u6570\u636e\u8bfb\u53d6\u5230HWC\u6570\u7ec4<\/code><code>&nbsp; &nbsp; float[] chwData = ImageUtil.whc2cwh(whcData);&nbsp;\/\/ \u8f6c\u6362\u4e3aCHW\u683c\u5f0f\uff08\u5de5\u5177\u7c7b\u5b9e\u73b0\uff09<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 6. \u5c01\u88c5\u4e3aONNX Tensor\uff08\u7b26\u5408\u6a21\u578b\u8f93\u5165\u8981\u6c42\uff09<\/code><code>&nbsp; &nbsp; FloatBuffer inputBuffer = FloatBuffer.wrap(chwData);<\/code><code>&nbsp; &nbsp; OnnxTensor inputTensor = OnnxTensor.createTensor(this.env, inputBuffer,&nbsp;this.inputShape);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 7. \u6784\u5efa\u8f93\u5165\u6620\u5c04\uff08\u952e\u4e3a\u8f93\u5165\u540d\u79f0\uff0c\u503c\u4e3aTensor\uff09<\/code><code>&nbsp; &nbsp; Map&lt;String, OnnxTensor&gt; inputMap = CollectionUtil.newHashMap();<\/code><code>&nbsp; &nbsp; inputMap.put(this.inputName, inputTensor);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;inputMap;<\/code><code>}<\/code><\/pre>\n\n\n\n<p><strong>\u5de5\u5177\u7c7b\u8865\u5145\uff08ImageUtil.whc2cwh\uff09<\/strong>\uff1a<br>\u7ef4\u5ea6\u8f6c\u6362\u7684\u6838\u5fc3\u903b\u8f91\u662f\u5c06<code>[H, W, C]<\/code>\u7684\u6570\u7ec4\u91cd\u65b0\u6392\u5217\u4e3a<code>[C, H, W]<\/code>\uff0c\u793a\u4f8b\u5b9e\u73b0\uff1a<\/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>public&nbsp;class&nbsp;ImageUtil&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ HWC \u2192 CHW\uff1aheight x width x channel \u2192 channel x height x width<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;static&nbsp;float[]&nbsp;whc2cwh(float[] whcData)&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5047\u8bbe\u6a21\u578b\u8f93\u5165\u5c3a\u5bf8\u4e3a640x640\uff0c\u901a\u9053\u6570\u4e3a3\uff08\u9700\u6839\u636e\u5b9e\u9645inputShape\u8c03\u6574\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;inputHeight =&nbsp;640;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;inputWidth =&nbsp;640;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;channels =&nbsp;3;<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float[] chwData =&nbsp;new&nbsp;float[channels * inputHeight * inputWidth];<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;idx =&nbsp;0;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;c =&nbsp;0; c &lt; channels; c++) {&nbsp;\/\/ \u5148\u904d\u5386\u901a\u9053<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;h =&nbsp;0; h &lt; inputHeight; h++) {&nbsp;\/\/ \u518d\u904d\u5386\u9ad8\u5ea6<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;w =&nbsp;0; w &lt; inputWidth; w++) {&nbsp;\/\/ \u6700\u540e\u904d\u5386\u5bbd\u5ea6<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ HWC\u6570\u7ec4\u7d22\u5f15\uff1ah * inputWidth * channels + w * channels + c<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ CHW\u6570\u7ec4\u7d22\u5f15\uff1ac * inputHeight * inputWidth + h * inputWidth + w<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chwData[c * inputHeight * inputWidth + h * inputWidth + w]&nbsp;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = whcData[h * inputWidth * channels + w * channels + c];<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;chwData;<\/code><code>&nbsp; &nbsp; }<\/code><code>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3.1.4 \u6a21\u578b\u63a8\u7406\uff1a\u6267\u884c\u68c0\u6d4b\u5e76\u83b7\u53d6\u8f93\u51fa<\/h4>\n\n\n\n<p>\u63a8\u7406\u8fc7\u7a0b\u672c\u8d28\u662f\u5c06\u9884\u5904\u7406\u540e\u7684\u8f93\u5165\u4f20\u5165\u6a21\u578b\uff0c\u83b7\u53d6\u539f\u59cb\u8f93\u51fa\u5f20\u91cf\uff1a<\/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>\/\/ \u6a21\u578b\u63a8\u7406\uff1a\u8f93\u5165\u6620\u5c04 \u2192 \u539f\u59cb\u68c0\u6d4b\u7ed3\u679c<\/code><code>private&nbsp;float[][] inference(Map&lt;String, OnnxTensor&gt; inputMap)&nbsp;throws&nbsp;OrtException {<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u6267\u884c\u63a8\u7406\uff1asession.run()\u8fd4\u56de\u63a8\u7406\u7ed3\u679c\u96c6\u5408<\/code><code>&nbsp; &nbsp; OrtSession.Result&nbsp;result&nbsp;=&nbsp;this.session.run(inputMap);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u89e3\u6790\u8f93\u51fa\uff1aYOLOv8 ONNX\u8f93\u51fa\u683c\u5f0f\u4e3a[1, num_boxes, 4+num_classes]<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u8fd9\u91cc\u53d6\u7b2c\u4e00\u4e2a\u6279\u91cf\uff08[0]\uff09\uff0c\u5f97\u5230[num_boxes, 4+num_classes]\u7684\u4e8c\u7ef4\u6570\u7ec4<\/code><code>&nbsp; &nbsp;&nbsp;float[][][] outputTensor = (float[][][]) result.get(0).getValue();<\/code><code>&nbsp; &nbsp;&nbsp;float[][] predictions = outputTensor[0];<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;predictions;<\/code><code>}<\/code><\/pre>\n\n\n\n<p><strong>\u8f93\u51fa\u683c\u5f0f\u8bf4\u660e<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>predictions<\/code>\u662f<code>[num_boxes, 4+num_classes]<\/code>\u7684\u4e8c\u7ef4\u6570\u7ec4\uff0c\u5176\u4e2d\uff1a\n<ul class=\"wp-block-list\">\n<li><code>num_boxes<\/code>\uff1a\u6a21\u578b\u9884\u6d4b\u7684\u68c0\u6d4b\u6846\u603b\u6570\uff1b<\/li>\n\n\n\n<li><code>4<\/code>\uff1a\u68c0\u6d4b\u6846\u5750\u6807\uff08x, y, w, h\uff0c\u5bf9\u5e94\u6846\u7684\u4e2d\u5fc3\u5750\u6807\u548c\u5bbd\u9ad8\uff09\uff1b<\/li>\n\n\n\n<li><code>num_classes<\/code>\uff1a\u7c7b\u522b\u7f6e\u4fe1\u5ea6\uff08\u672c\u6587\u4e2d\u4e3a 2 \u7c7b\uff1arow \u548c column\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-embed\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/wxa.wxs.qq.com\/tmpl\/oc\/base_tmpl.html\n<\/div><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">3.1.5 \u8f93\u51fa\u5904\u7406\uff1a\u4ece\u539f\u59cb\u7ed3\u679c\u5230\u53ef\u8bfb\u68c0\u6d4b\u4fe1\u606f<\/h4>\n\n\n\n<p>\u539f\u59cb\u8f93\u51fa\u9700\u7ecf\u8fc7<strong>\u7c7b\u522b\u7b5b\u9009\u3001\u5750\u6807\u8f6c\u6362\u3001\u975e\u6781\u5927\u503c\u6291\u5236\uff08NMS\uff09<\/strong>&nbsp;\u4e09\u6b65\u5904\u7406\uff0c\u5f97\u5230\u6700\u7ec8\u7684\u68c0\u6d4b\u7ed3\u679c\uff1a<\/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>\/\/ \u5904\u7406\u8f93\u51fa\uff1a\u539f\u59cb\u9884\u6d4b\u7ed3\u679c \u2192 \u53ef\u8bfb\u68c0\u6d4b\u5217\u8868\uff08Detection\uff09<\/code><code>private&nbsp;List&lt;Detection&gt;&nbsp;processOutput(float[][] predictions)&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 1. \u8f6c\u7f6e\u77e9\u9635\uff1a[num_boxes, 4+num_classes] \u2192 [4+num_classes, num_boxes]<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u4fbf\u4e8e\u6309\u7c7b\u522b\u7ef4\u5ea6\u5904\u7406\u7f6e\u4fe1\u5ea6<\/code><code>&nbsp; &nbsp; predictions = transposeMatrix(predictions);<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 2. \u6309\u7c7b\u522b\u5206\u7ec4\u68c0\u6d4b\u6846\uff08key\uff1a\u7c7b\u522bID\uff0cvalue\uff1a\u8be5\u7c7b\u522b\u7684\u68c0\u6d4b\u6846\u5217\u8868\uff09<\/code><code>&nbsp; &nbsp; Map&lt;Integer, List&lt;float[]&gt;&gt; class2Bbox = CollectionUtil.newHashMap();<\/code><code>&nbsp; &nbsp;&nbsp;for&nbsp;(float[] bbox : predictions) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u63d0\u53d6\u7c7b\u522b\u7f6e\u4fe1\u5ea6\uff08\u8df3\u8fc7\u524d4\u4e2a\u5750\u6807\u503c\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float[] classProbs = Arrays.copyOfRange(bbox,&nbsp;4, bbox.length);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u627e\u5230\u7f6e\u4fe1\u5ea6\u6700\u9ad8\u7684\u7c7b\u522b\uff08\u5373\u5f53\u524d\u68c0\u6d4b\u6846\u7684\u7c7b\u522b\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;labelId = predMax(classProbs);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u8be5\u7c7b\u522b\u7684\u7f6e\u4fe1\u5ea6<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;confidence = classProbs[labelId];<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u8fc7\u6ee4\u4f4e\u7f6e\u4fe1\u5ea6\u7ed3\u679c\uff08\u4f4e\u4e8econfThreshold\u7684\u6846\u4e22\u5f03\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(confidence &lt;&nbsp;this.confThreshold) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5c06\u7f6e\u4fe1\u5ea6\u5b58\u5165\u68c0\u6d4b\u6846\u6570\u7ec4\uff08\u7b2c4\u4f4d\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; bbox[4] = confidence;<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5750\u6807\u7f29\u653e\uff1a\u5c06\u6a21\u578b\u8f93\u5165\u5c3a\u5bf8\uff08\u5982640x640\uff09\u7684\u5750\u6807 \u2192 \u539f\u56fe\u5c3a\u5bf8<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; rescaleBoxes(bbox);<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5750\u6807\u683c\u5f0f\u8f6c\u6362\uff1axywh\uff08\u4e2d\u5fc3+\u5bbd\u9ad8\uff09\u2192 xyxy\uff08\u5de6\u4e0a\u89d2+\u53f3\u4e0b\u89d2\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u4fbf\u4e8e\u540e\u7eed\u7ed8\u5236\u68c0\u6d4b\u6846<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; ImageUtil.xywh2xyxy(bbox);<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u8fc7\u6ee4\u65e0\u6548\u6846\uff08\u5de6\u4e0a\u89d2x \u2265 \u53f3\u4e0b\u89d2x \u6216 \u5de6\u4e0a\u89d2y \u2265 \u53f3\u4e0b\u89d2y\u7684\u6846\u4e22\u5f03\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(bbox[0] &gt;= bbox[2] || bbox[1] &gt;= bbox[3]) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;continue;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u6309\u7c7b\u522b\u5206\u7ec4\u5b58\u5165Map<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; class2Bbox.putIfAbsent(labelId, CollectionUtil.newArrayList());<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; class2Bbox.get(labelId).add(bbox);<\/code><code>&nbsp; &nbsp; }<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ 3. \u975e\u6781\u5927\u503c\u6291\u5236\uff08NMS\uff09\uff1a\u53bb\u9664\u540c\u4e00\u7c7b\u522b\u4e2d\u7684\u91cd\u590d\u68c0\u6d4b\u6846<\/code><code>&nbsp; &nbsp; List&lt;Detection&gt; detectionList = CollectionUtil.newArrayList();<\/code><code>&nbsp; &nbsp;&nbsp;for&nbsp;(Map.Entry&lt;Integer, List&lt;float[]&gt;&gt; entry : class2Bbox.entrySet()) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;labelId = entry.getKey();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; List&lt;float[]&gt; bboxList = entry.getValue();<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5bf9\u5f53\u524d\u7c7b\u522b\u6267\u884cNMS\uff08\u4fdd\u7559\u7f6e\u4fe1\u5ea6\u6700\u9ad8\u3001\u65e0\u91cd\u53e0\u7684\u6846\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; bboxList = ImageUtil.nonMaxSuppression(bboxList,&nbsp;this.iouThreshold);<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ \u5c01\u88c5\u4e3aDetection\u5bf9\u8c61\uff08\u5305\u542b\u6807\u7b7e\u540d\u3001\u7c7b\u522bID\u3001\u5750\u6807\u3001\u7f6e\u4fe1\u5ea6\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(float[] bbox : bboxList) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String labelName = labelNames.get(labelId);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float[] coordinates = Arrays.copyOfRange(bbox,&nbsp;0,&nbsp;4);&nbsp;\/\/ xyxy\u5750\u6807<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;confidence = bbox[4];<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detectionList.add(new&nbsp;Detection(labelName, labelId, coordinates, confidence));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; }<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;detectionList;<\/code><code>}<\/code><code>\/\/ \u8f85\u52a9\u65b9\u6cd51\uff1a\u77e9\u9635\u8f6c\u7f6e<\/code><code>private&nbsp;float[][] transposeMatrix(float[][] matrix) {<\/code><code>&nbsp; &nbsp;&nbsp;float[][] transposed =&nbsp;new&nbsp;float[matrix[0].length][matrix.length];<\/code><code>&nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;i =&nbsp;0; i &lt; matrix.length; i++) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;j =&nbsp;0; j &lt; matrix[0].length; j++) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; transposed[j][i] = matrix[i][j];<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;transposed;<\/code><code>}<\/code><code>\/\/ \u8f85\u52a9\u65b9\u6cd52\uff1a\u627e\u5230\u7f6e\u4fe1\u5ea6\u6700\u9ad8\u7684\u7c7b\u522bID<\/code><code>private&nbsp;int&nbsp;predMax(float[] probabilities)&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;float&nbsp;maxProb = Float.NEGATIVE_INFINITY;<\/code><code>&nbsp; &nbsp;&nbsp;int&nbsp;maxIndex =&nbsp;0;<\/code><code>&nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;i =&nbsp;0; i &lt; probabilities.length; i++) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(probabilities[i] &gt; maxProb) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxProb = probabilities[i];<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; maxIndex = i;<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp;&nbsp;return&nbsp;maxIndex;<\/code><code>}<\/code><code>\/\/ \u8f85\u52a9\u65b9\u6cd53\uff1a\u5c06\u6a21\u578b\u8f93\u5165\u5c3a\u5bf8\u7684\u5750\u6807\u7f29\u653e\u56de\u539f\u56fe\u5c3a\u5bf8<\/code><code>public&nbsp;void&nbsp;rescaleBoxes(float[] bbox)&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u7f29\u653ex\u5750\u6807\uff08\u4e2d\u5fc3x\u3001\u5bbd\uff09<\/code><code>&nbsp; &nbsp; bbox[0] = bbox[0] \/&nbsp;this.inputWidth *&nbsp;this.rawImgWidth;<\/code><code>&nbsp; &nbsp; bbox[2] = bbox[2] \/&nbsp;this.inputWidth *&nbsp;this.rawImgWidth;<\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u7f29\u653ey\u5750\u6807\uff08\u4e2d\u5fc3y\u3001\u9ad8\uff09<\/code><code>&nbsp; &nbsp; bbox[1] = bbox[1] \/&nbsp;this.inputHeight *&nbsp;this.rawImgHeight;<\/code><code>&nbsp; &nbsp; bbox[3] = bbox[3] \/&nbsp;this.inputHeight *&nbsp;this.rawImgHeight;<\/code><code>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.2 \u4e3b\u51fd\u6570\u8c03\u7528\uff1aMainTest<\/h3>\n\n\n\n<p><code>MainTest<\/code>\u8d1f\u8d23\u8bfb\u53d6\u914d\u7f6e\u3001\u52a0\u8f7d\u6a21\u578b\u3001\u8c03\u7528\u68c0\u6d4b\u3001\u5c55\u793a\u7ed3\u679c\uff08\u7ed8\u5236\u68c0\u6d4b\u6846\u3001\u6253\u5370 JSON\uff09\uff1a<\/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>package sy;<\/code><code>import&nbsp;ai.onnxruntime.OrtException;<\/code><code>import&nbsp;com.alibaba.fastjson2.JSON;<\/code><code>import&nbsp;org.opencv.core.Mat;<\/code><code>import&nbsp;org.opencv.imgcodecs.Imgcodecs;<\/code><code>import&nbsp;utils.PropertiesReader;<\/code><code>import&nbsp;java.util.List;<\/code><code>public&nbsp;class&nbsp;MainTest&nbsp;{<\/code><code>&nbsp; &nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String... args) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;try&nbsp;{<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 1. \u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\uff08\u6a21\u578b\u3001\u6807\u7b7e\u8def\u5f84\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;modelPath =&nbsp;getResourcePath(PropertiesReader.get(\"model_path\"));<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;labelPath =&nbsp;getResourcePath(PropertiesReader.get(\"table_det_labels_path\"));<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 2. \u6d4b\u8bd5\u56fe\u50cf\u8def\u5f84\uff08\u9700\u66ff\u6362\u4e3a\u4f60\u7684\u56fe\u50cf\u8def\u5f84\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;imgPath =&nbsp;\"D:\\\\project\\\\table_detection\\\\img\\\\test_table.jpg\";<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;outputImgPath =&nbsp;\"D:\\\\project\\\\table_detection\\\\img\\\\prediction.jpg\";<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 3. \u52a0\u8f7d\u6a21\u578b\uff08\u9ed8\u8ba4\u7f6e\u4fe1\u5ea60.3\uff0cIOU 0.5\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;ModelDet&nbsp;modelDet =&nbsp;new&nbsp;ModelDet(modelPath, labelPath);<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 4. \u8bfb\u53d6\u56fe\u50cf\uff08OpenCV\u7684imread\u65b9\u6cd5\uff09<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Mat&nbsp;img =&nbsp;Imgcodecs.imread(imgPath);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(img.dataAddr() ==&nbsp;0) {&nbsp;\/\/ \u68c0\u67e5\u56fe\u50cf\u662f\u5426\u6210\u529f\u8bfb\u53d6<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.err.println(\"\u56fe\u50cf\u8bfb\u53d6\u5931\u8d25\uff1a\"&nbsp;+ imgPath);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.exit(1);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 5. \u6267\u884c\u68c0\u6d4b<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;List&lt;Detection&gt; detectionList = modelDet.detectObjects(img);<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 6. \u7ed3\u679c\u5c55\u793a\uff1a\u7ed8\u5236\u68c0\u6d4b\u6846\u5230\u56fe\u50cf<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;ImageUtil.drawPredictions(img, detectionList);<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\/\/ 7. \u7ed3\u679c\u8f93\u51fa\uff1a\u4fdd\u5b58\u56fe\u50cf+\u6253\u5370JSON<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;Imgcodecs.imwrite(outputImgPath, img);<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.out.println(\"\u68c0\u6d4b\u7ed3\u679c\uff08JSON\uff09\uff1a\");<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.out.println(JSON.toJSONString(detectionList,&nbsp;true));&nbsp;\/\/ \u683c\u5f0f\u5316\u8f93\u51fa<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.out.println(\"\u68c0\u6d4b\u5b8c\u6210\uff01\u7ed3\u679c\u56fe\u50cf\u5df2\u4fdd\u5b58\u81f3\uff1a\"&nbsp;+ outputImgPath);<\/code><code><br><\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;catch&nbsp;(OrtException&nbsp;e) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.printStackTrace();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.err.println(\"\u6a21\u578b\u63a8\u7406\u5931\u8d25\uff1a\"&nbsp;+ e.getMessage());<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp; }<\/code><code>&nbsp; &nbsp; }<\/code><code><br><\/code><code>&nbsp; &nbsp;&nbsp;\/\/ \u8f85\u52a9\u65b9\u6cd5\uff1a\u83b7\u53d6\u8d44\u6e90\u6587\u4ef6\u7684\u7edd\u5bf9\u8def\u5f84\uff08\u5904\u7406getResource\u7684\u659c\u6760\u95ee\u9898\uff09<\/code><code>&nbsp; &nbsp;&nbsp;private&nbsp;static&nbsp;String&nbsp;getResourcePath(String&nbsp;relativePath) {<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;String&nbsp;path =&nbsp;MainTest.class.getClassLoader().getResource(relativePath).getPath();<\/code><code>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;path.replaceFirst(\"\/\",&nbsp;\"\");&nbsp;\/\/ \u53bb\u9664\u8def\u5f84\u5f00\u5934\u7684\u659c\u6760\uff08\u5982\"\/D:...\"\u2192\"D:...\"\uff09<\/code><code>&nbsp; &nbsp; }<\/code><code>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u8fd0\u884c\u6548\u679c\u5c55\u793a<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"365\" height=\"144\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6737 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg 365w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334-300x118.jpg 300w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"365\" height=\"144\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg\" alt=\"\" class=\"wp-image-6737\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg 365w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334-300x118.jpg 300w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><\/noscript><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"365\" height=\"144\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124.jpg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6738 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124.jpg 365w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124-300x118.jpg 300w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"365\" height=\"144\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124.jpg\" alt=\"\" class=\"wp-image-6738\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124.jpg 365w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124-300x118.jpg 300w\" sizes=\"auto, (max-width: 365px) 100vw, 365px\" \/><\/noscript><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u603b\u7ed3<\/h2>\n\n\n\n<p>\u672c\u6587\u8be6\u7ec6\u8bb2\u89e3\u4e86\u57fa\u4e8e Java \u4e0e YOLOv8 \u5b9e\u73b0\u8868\u683c\u884c\u5217\u68c0\u6d4b\u7684\u5b8c\u6574\u6d41\u7a0b\uff0c\u4ece\u73af\u5883\u642d\u5efa\u3001\u4ee3\u7801\u89e3\u6790\u5230\u8fd0\u884c\u6548\u679c\u5c55\u793a\uff0c\u8986\u76d6\u4e86\u6a21\u578b\u52a0\u8f7d\u3001\u56fe\u50cf\u9884\u5904\u7406\u3001\u63a8\u7406\u6267\u884c\u3001\u7ed3\u679c\u5904\u7406\u7b49\u6838\u5fc3\u73af\u8282\u3002\u8be5\u65b9\u6848\u57fa\u4e8e YOLOv8 \u7684\u9ad8\u901f\u5ea6\u4e0e\u9ad8\u7cbe\u5ea6\uff0c\u7ed3\u5408 Java \u7684\u4f01\u4e1a\u7ea7\u4f18\u52bf\uff0c\u53ef\u7075\u6d3b\u96c6\u6210\u5230\u6587\u6863\u5904\u7406\u3001\u6570\u636e\u5f55\u5165\u7b49\u5b9e\u9645\u5e94\u7528\u4e2d\u3002<\/p>\n\n\n\n<p>\u8bfb\u8005\u53ef\u6839\u636e\u81ea\u8eab\u9700\u6c42\u8c03\u6574\u9608\u503c\u3001\u4f18\u5316\u6a21\u578b\u6216\u6269\u5c55\u529f\u80fd\uff0c\u8fdb\u4e00\u6b65\u63d0\u5347\u68c0\u6d4b\u6027\u80fd\u4e0e\u9002\u7528\u573a\u666f\u3002\u5e0c\u671b\u672c\u6587\u80fd\u4e3a\u4ece\u4e8b\u8868\u683c\u8bc6\u522b\u3001\u8ba1\u7b97\u673a\u89c6\u89c9\u76f8\u5173\u5f00\u53d1\u7684\u8bfb\u8005\u63d0\u4f9b\u6709\u4ef7\u503c\u7684\u53c2\u8003\u3002<\/p>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5f15\u8a00\uff1a\u8868\u683c\u68c0\u6d4b\u7684\u4ef7\u503c\u4e0e\u6280\u672f\u9009\u578b \u5728\u6587\u6863\u6570\u5b57\u5316\u3001\u6570\u636e\u81ea\u52a8\u5316\u5f55\u5165\u7b49\u573a\u666f\u4e2d\uff0c\u8868\u683c\u4f5c\u4e3a\u4fe1\u606f\u627f\u8f7d\u7684\u91cd\u8981\u5f62\u5f0f\uff0c\u5176\u7ed3\u6784\uff08\u884c\u3001\u5217\uff09\u7684\u7cbe\u51c6\u68c0\u6d4b\u662f &#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":[2,7,46],"tags":[],"class_list":["post-6736","post","type-post","status-publish","format-standard","hentry","category-java","category-spring-boot","category-yolo"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055351334.jpg","id":"image1"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124.jpg","id":"image2"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929055354124.jpg","id":"image3"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Java","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":280,"next_post_id":6750,"next_post_title":"YOLO\u5165\u95e8\u6559\u7a0b\uff08\u756a\u5916\uff09\uff1a\u4e00\u6587\u641e\u5b9aPyTorch","previous_post_id":6725,"previous_post_title":"SpringBoot\u4e0eVector Search\u6574\u5408\uff0c\u5b9e\u73b0\u77ed\u89c6\u9891\u5185\u5bb9\u5b9e\u65f6\u63a8\u8350\u7cfb\u7edf","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6736","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=6736"}],"version-history":[{"count":1,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6736\/revisions"}],"predecessor-version":[{"id":6739,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6736\/revisions\/6739"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}