{"id":6714,"date":"2025-09-29T13:38:46","date_gmt":"2025-09-29T05:38:46","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6714"},"modified":"2025-09-29T13:38:55","modified_gmt":"2025-09-29T05:38:55","slug":"%e4%bb%8e%e9%9b%b6%e6%89%93%e9%80%a0%e9%ab%98%e6%80%a7%e8%83%bd%e4%ba%ba%e4%bd%93%e5%a7%bf%e6%80%81%e6%a3%80%e6%b5%8b%e7%b3%bb%e7%bb%9f%ef%bc%9ayolov8-pose-onnx-runtime-%e5%ae%9e%e6%88%98%e6%8c%87","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/yolo\/%e4%bb%8e%e9%9b%b6%e6%89%93%e9%80%a0%e9%ab%98%e6%80%a7%e8%83%bd%e4%ba%ba%e4%bd%93%e5%a7%bf%e6%80%81%e6%a3%80%e6%b5%8b%e7%b3%bb%e7%bb%9f%ef%bc%9ayolov8-pose-onnx-runtime-%e5%ae%9e%e6%88%98%e6%8c%87\/","title":{"rendered":"\u4ece\u96f6\u6253\u9020\u9ad8\u6027\u80fd\u4eba\u4f53\u59ff\u6001\u68c0\u6d4b\u7cfb\u7edf\uff1aYOLOv8-Pose + ONNX Runtime \u5b9e\u6218\u6307\u5357"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u5728\u8fd9\u4e2aAI\u89c6\u89c9\u6280\u672f\u5feb\u901f\u53d1\u5c55\u7684\u65f6\u4ee3\uff0c\u4eba\u4f53\u59ff\u6001\u68c0\u6d4b\u5df2\u7ecf\u6210\u4e3a\u4f53\u611f\u6e38\u620f\u3001\u5065\u8eab\u6307\u5bfc\u3001\u5b89\u9632\u76d1\u63a7\u7b49\u4f17\u591a\u9886\u57df\u7684\u6838\u5fc3\u6280\u672f\u3002\u672c\u6587\u5c06\u5e26\u4f60\u6df1\u5165\u4e86\u89e3\u5982\u4f55\u4f7f\u7528YOLOv8-Pose\u3001ONNX Runtime\u548cOpenCV\u6784\u5efa\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u59ff\u6001\u68c0\u6d4b\u7cfb\u7edf\uff0c\u4ece\u539f\u7406\u5230\u5b9e\u73b0\uff0c\u4ece\u4f18\u5316\u5230\u90e8\u7f72\uff0c\u5168\u65b9\u4f4d\u89e3\u6790\u8fd9\u4e00\u524d\u6cbf\u6280\u672f\u3002<\/p>\n<\/blockquote>\n\n\n\n<p>\u672c\u9879\u76ee\u5df2\u7ecf\u4e0a\u4f20\u5230GitHub,\u590d\u5236https:\/\/github.com\/Bayesianovich\/yolov8-pose-ort\u5230\u6d4f\u89c8\u5668\u5373\u53ef\u8bbf\u95ee\uff0c\u6b22\u8fcestar\u2b50\u2b50<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"588\" height=\"1024\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-588x1024.jpg\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6715 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-588x1024.jpg 588w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-172x300.jpg 172w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg 740w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"588\" height=\"1024\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-588x1024.jpg\" alt=\"\" class=\"wp-image-6715\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-588x1024.jpg 588w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-172x300.jpg 172w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg 740w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><\/noscript><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\ud83d\ude80 \u4e3a\u4ec0\u4e48\u9009\u62e9\u8fd9\u5957\u6280\u672f\u6808\uff1f<\/strong><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5176\u5b9e\u6362\u6210yolov11\u7684onnx\u4e5f\u80fd\u8dd1\u3002<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>YOLOv8-Pose\uff1a\u59ff\u6001\u4f30\u8ba1\u68c0\u6d4b\u7684\u7ecf\u5178\u6a21\u578b<\/strong><\/h3>\n\n\n\n<p>\u8fd8\u8bb0\u5f97\u65e9\u671f\u7684\u59ff\u6001\u68c0\u6d4b\u9700\u8981\u5148\u68c0\u6d4b\u4eba\u4f53\uff0c\u518d\u5b9a\u4f4d\u5173\u952e\u70b9\u7684\u590d\u6742\u6d41\u7a0b\u5417\uff1fYOLOv8-Pose\u5f7b\u5e95\u6539\u53d8\u4e86\u8fd9\u4e00\u5207\u3002\u5b83\u5c06\u76ee\u6807\u68c0\u6d4b\u548c\u5173\u952e\u70b9\u68c0\u6d4b\u5408\u5e76\u5728\u5355\u4e00\u7f51\u7edc\u4e2d\uff0c\u4e0d\u4ec5\u7b80\u5316\u4e86\u6d41\u7a0b\uff0c\u66f4\u5728\u901f\u5ea6\u548c\u7cbe\u5ea6\u4e0a\u5b9e\u73b0\u4e86\u8d28\u7684\u98de\u8dc3\u3002<\/p>\n\n\n\n<p><strong>\u5173\u952e\u4f18\u52bf\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e00\u7f51\u7edc\u53cc\u4efb\u52a1<\/strong>\uff1a\u540c\u65f6\u5b8c\u6210\u4eba\u4f53\u68c0\u6d4b\u548c17\u4e2aCOCO\u6807\u51c6\u5173\u952e\u70b9\u5b9a\u4f4d<\/li>\n\n\n\n<li><strong>\u7cbe\u5ea6\u4fdd\u8bc1<\/strong>\uff1a\u5728\u4fdd\u6301\u9ad8\u901f\u5ea6\u7684\u540c\u65f6\uff0c\u68c0\u6d4b\u7cbe\u5ea6\u8fbe\u5230\u4e1a\u754c\u9886\u5148\u6c34\u5e73<\/li>\n<\/ul>\n\n\n\n<p><strong>\u6a21\u578b\u8f93\u51fa\u89e3\u6790\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u8f93\u51fa\u7ef4\u5ea6\uff1a&#91;1, 56, 8400] \u6216 &#91;1, 8400, 56]<br>\u251c\u2500\u2500 \u524d4\u4f4d\uff1a\u8fb9\u754c\u6846 &#91;center_x, center_y, width, height]<br>\u251c\u2500\u2500 \u7b2c5\u4f4d\uff1a\u7f6e\u4fe1\u5ea6\u5206\u6570 &nbsp;<br>\u2514\u2500\u2500 \u540e51\u4f4d\uff1a17\u4e2a\u5173\u952e\u70b9 &#91;x1,y1,v1, x2,y2,v2, ..., x17,y17,v17]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>ONNX Runtime\uff1a\u8de8\u5e73\u53f0\u63a8\u7406\u7684\u5b8c\u7f8e\u9009\u62e9<\/strong><\/h3>\n\n\n\n<p>\u5728\u9009\u62e9\u63a8\u7406\u5f15\u64ce\u65f6\uff0c\u6211\u4eec\u9762\u4e34\u7740\u6027\u80fd\u3001\u517c\u5bb9\u6027\u548c\u90e8\u7f72\u4fbf\u5229\u6027\u7684\u4e09\u91cd\u8003\u9a8c\u3002ONNX Runtime\u4ee5\u5176\u4f18\u5f02\u7684\u8868\u73b0\u6210\u4e3a\u4e86\u6700\u4f73\u9009\u62e9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8de8\u5e73\u53f0\u65e0\u5fe7<\/strong>\uff1a\u4e00\u6b21\u5f00\u53d1\uff0cWindows\u3001Linux\u5168\u8986\u76d6<\/li>\n\n\n\n<li><strong>\u786c\u4ef6\u52a0\u901f<\/strong>\uff1aCPU\u3001GPU\u3001NPU\u7edf\u4e00\u63a5\u53e3\uff0c\u8f7b\u677e\u5207\u6362<\/li>\n\n\n\n<li><strong>\u751f\u4ea7\u5c31\u7eea<\/strong>\uff1a\u5185\u7f6e\u7684\u56fe\u4f18\u5316\u548c\u5185\u5b58\u7ba1\u7406\uff0c\u4e3a\u751f\u4ea7\u73af\u5883\u91cf\u8eab\u5b9a\u5236<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\ud83d\udee0\ufe0f ONNX Runtime\u90e8\u7f72\u59ff\u6001\u68c0\u6d4b\uff1a\u5b9e\u9645\u9879\u76ee\u5b9e\u73b0\u8be6\u89e3<\/strong><\/h2>\n\n\n\n<p>\u5728\u6211\u4eec\u7684\u9879\u76ee\u4e2d\uff0cONNX Runtime\u7684\u90e8\u7f72\u91c7\u7528\u4e86\u7b80\u6d01\u9ad8\u6548\u7684\u8bbe\u8ba1\u7b56\u7565\uff0c\u4e13\u6ce8\u4e8e\u6027\u80fd\u548c\u6613\u7528\u6027\u3002\u8ba9\u6211\u4eec\u6df1\u5165\u4e86\u89e3\u5b9e\u9645\u7684\u90e8\u7f72\u5b9e\u73b0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u9879\u76ee\u90e8\u7f72\u67b6\u6784<\/strong><\/h3>\n\n\n\n<p>\u6211\u4eec\u7684\u90e8\u7f72\u67b6\u6784\u5f3a\u8c03\u7b80\u6d01\u6027\u548c\u9ad8\u6548\u6027\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 &nbsp; &nbsp;\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 &nbsp; &nbsp;\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br>\u2502 &nbsp;YOLOv8n-Pose &nbsp; \u2502 &nbsp; &nbsp;\u2502 &nbsp;ONNX Runtime &nbsp; \u2502 &nbsp; &nbsp;\u2502 &nbsp;\u68c0\u6d4b\u5668\u7c7b &nbsp; &nbsp; &nbsp; \u2502<br>\u2502 &nbsp; (.onnx) &nbsp; &nbsp; &nbsp; \u2502\u2500\u2500\u2500\u25b6\u2502 &nbsp; CPU\u63a8\u7406 &nbsp; &nbsp; &nbsp; \u2502\u2500\u2500\u2500\u25b6\u2502 (\u5355\u4e00\u804c\u8d23) &nbsp; &nbsp; &nbsp;\u2502<br>\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 &nbsp; &nbsp;\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 &nbsp; &nbsp;\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u2502<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u2502 \u4f18\u5316\u914d\u7f6e: &nbsp; &nbsp; &nbsp; \u2502<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u2502 - \u5355\u7ebf\u7a0b\u63a8\u7406 &nbsp; &nbsp; \u2502<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u2502 - \u6269\u5c55\u56fe\u4f18\u5316 &nbsp; &nbsp; \u2502<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u2502 - Arena\u5185\u5b58 &nbsp; &nbsp; \u2502<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u68c0\u6d4b\u5668\u7c7b\u8bbe\u8ba1\uff1a\u4e13\u6ce8\u6838\u5fc3\u529f\u80fd<\/strong><\/h3>\n\n\n\n<p>\u6211\u4eec\u7684<code>YOLOv8PoseDetector<\/code>\u7c7b\u8bbe\u8ba1\u7b80\u6d01\u800c\u5f3a\u5927\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class&nbsp;YOLOv8PoseDetector&nbsp;{<br>private:<br>&nbsp; &nbsp;&nbsp;<em>\/\/ ONNX Runtime\u6838\u5fc3\u7ec4\u4ef6<\/em><br>&nbsp; &nbsp; Ort::Env env;<br>&nbsp; &nbsp; Ort::SessionOptions session_options;<br>&nbsp; &nbsp;&nbsp;std::unique_ptr&lt;Ort::Session&gt; session;<br>&nbsp; &nbsp; Ort::AllocatorWithDefaultOptions allocator;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6a21\u578b\u5143\u6570\u636e<\/em><br>&nbsp; &nbsp;&nbsp;std::vector&lt;constchar*&gt; input_names;<br>&nbsp; &nbsp;&nbsp;std::vector&lt;constchar*&gt; output_names;<br>&nbsp; &nbsp;&nbsp;std::vector&lt;std::int64_t&gt; input_dims;<br>&nbsp; &nbsp;&nbsp;std::vector&lt;std::int64_t&gt; output_dims;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u53ef\u89c6\u5316\u7ec4\u4ef6<\/em><br>&nbsp; &nbsp;&nbsp;std::vector&lt;std::string&gt; class_names;<br>&nbsp; &nbsp;&nbsp;std::vector&lt;cv::Scalar&gt; colors_table;<br>&nbsp; &nbsp;&nbsp;<br>public:<br>&nbsp; &nbsp; YOLOv8PoseDetector() : env(ORT_LOGGING_LEVEL_WARNING,&nbsp;\"YOLOv8-Pose\") {<br>&nbsp; &nbsp; &nbsp; &nbsp; initializeColors(); &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ \u521d\u59cb\u531617\u8272\u5f69\u8272\u8868<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; class_names = readClassNames(); &nbsp;<em>\/\/ \u52a0\u8f7d\u7c7b\u522b\u540d\u79f0<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; initializeSession(); &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u521d\u59cb\u5316ONNX Runtime\u4f1a\u8bdd<\/em><br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6790\u6784\u51fd\u6570\u786e\u4fdd\u5185\u5b58\u6b63\u786e\u91ca\u653e<\/em><br>&nbsp; &nbsp; ~YOLOv8PoseDetector() {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(auto* name : input_names) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;free(const_cast&lt;char*&gt;(name));<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(auto* name : output_names) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;free(const_cast&lt;char*&gt;(name));<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>};<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. \u4f1a\u8bdd\u521d\u59cb\u5316\uff1a\u4f18\u5316\u7684\u914d\u7f6e\u7b56\u7565<\/strong><\/h3>\n\n\n\n<p>\u6211\u4eec\u91c7\u7528\u4e86\u7ecf\u8fc7\u9a8c\u8bc1\u7684\u6700\u4f18\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;initializeSession()&nbsp;{<br>&nbsp; &nbsp;&nbsp;try&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6838\u5fc3\u914d\u7f6e\uff1a\u5e73\u8861\u6027\u80fd\u548c\u7a33\u5b9a\u6027<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; session_options.SetIntraOpNumThreads(1); &nbsp;<em>\/\/ \u5355\u7ebf\u7a0b\u907f\u514d\u4e0a\u4e0b\u6587\u5207\u6362\uff0c\u53ea\u6709\u56fe\u7247\u548c\u89c6\u9891\u8fdb\u884c\u6d4b\u8bd5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_EXTENDED);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6a21\u578b\u52a0\u8f7d\uff1aWindows\u8def\u5f84\u5904\u7406<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::wstring&nbsp;model_path_w(MODEL_PATH.begin(), MODEL_PATH.end());<br>&nbsp; &nbsp; &nbsp; &nbsp; session =&nbsp;std::make_unique&lt;Ort::Session&gt;(env, model_path_w.c_str(), session_options);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d6\u6a21\u578b\u4fe1\u606f<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; getModelInfo();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;\"YOLOv8 Pose model loaded successfully!\"&nbsp;&lt;&lt;&nbsp;std::endl;<br>&nbsp; &nbsp; }&nbsp;catch&nbsp;(conststd::exception&amp; e) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::cerr&nbsp;&lt;&lt;&nbsp;\"Error initializing ONNX session: \"&nbsp;&lt;&lt; e.what() &lt;&lt;&nbsp;std::endl;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;throw;<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p><strong>\u914d\u7f6e\u8981\u70b9\u89e3\u6790\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5355\u7ebf\u7a0b\u63a8\u7406<\/strong>\uff1a\u907f\u514d\u7ebf\u7a0b\u5207\u6362\u5f00\u9500<\/li>\n\n\n\n<li><strong>\u6269\u5c55\u56fe\u4f18\u5316<\/strong>\uff1a\u5e73\u8861\u7f16\u8bd1\u65f6\u95f4\u548c\u8fd0\u884c\u6027\u80fd<\/li>\n\n\n\n<li><strong>\u5f02\u5e38\u5904\u7406<\/strong>\uff1a\u786e\u4fdd\u521d\u59cb\u5316\u5931\u8d25\u65f6\u7a0b\u5e8f\u5b89\u5168\u9000\u51fa<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u6a21\u578b\u4fe1\u606f\u63d0\u53d6\uff1a\u52a8\u6001\u9002\u914d\u673a\u5236<\/strong><\/h3>\n\n\n\n<p>\u81ea\u52a8\u63d0\u53d6\u5e76\u9a8c\u8bc1\u6a21\u578b\u4fe1\u606f\uff0c\u652f\u6301\u4e0d\u540cYOLOv8\u53d8\u4f53\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;getModelInfo()&nbsp;{<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d6\u8f93\u5165\u4fe1\u606f<\/em><br>&nbsp; &nbsp;&nbsp;size_t&nbsp;num_input_nodes = session-&gt;GetInputCount();<br>&nbsp; &nbsp; input_names.resize(num_input_nodes);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;for&nbsp;(size_t&nbsp;i =&nbsp;0; i &lt; num_input_nodes; i++) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;auto&nbsp;input_name = session-&gt;GetInputNameAllocated(i, allocator);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::string&nbsp;name_str(input_name.get());<br>&nbsp; &nbsp; &nbsp; &nbsp; input_names&#91;i] = strdup(name_str.c_str()); &nbsp;<em>\/\/ \u521b\u5efa\u6301\u4e45\u5316\u526f\u672c<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; Ort::TypeInfo input_type_info = session-&gt;GetInputTypeInfo(i);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;auto&nbsp;input_tensor_info = input_type_info.GetTensorTypeAndShapeInfo();<br>&nbsp; &nbsp; &nbsp; &nbsp; input_dims = input_tensor_info.GetShape();<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d6\u8f93\u51fa\u4fe1\u606f<\/em><br>&nbsp; &nbsp;&nbsp;size_t&nbsp;num_output_nodes = session-&gt;GetOutputCount();<br>&nbsp; &nbsp; output_names.resize(num_output_nodes);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;for&nbsp;(size_t&nbsp;i =&nbsp;0; i &lt; num_output_nodes; i++) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;auto&nbsp;output_name = session-&gt;GetOutputNameAllocated(i, allocator);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::string&nbsp;name_str(output_name.get());<br>&nbsp; &nbsp; &nbsp; &nbsp; output_names&#91;i] = strdup(name_str.c_str());<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; Ort::TypeInfo output_type_info = session-&gt;GetOutputTypeInfo(i);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;auto&nbsp;output_tensor_info = output_type_info.GetTensorTypeAndShapeInfo();<br>&nbsp; &nbsp; &nbsp; &nbsp; output_dims = output_tensor_info.GetShape();<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;std::cout&nbsp;&lt;&lt;&nbsp;\"Model info - Input: \"&nbsp;&lt;&lt; input_names&#91;0]&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;&lt;&nbsp;\", Output: \"&nbsp;&lt;&lt; output_names&#91;0] &lt;&lt;&nbsp;std::endl;<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. \u63a8\u7406\u6267\u884c\uff1a\u9ad8\u6548\u7684\u6570\u636e\u6d41\u5904\u7406<\/strong><\/h3>\n\n\n\n<p>\u6838\u5fc3\u63a8\u7406\u6d41\u7a0b\u4e13\u6ce8\u4e8e\u6027\u80fd\u548c\u51c6\u786e\u6027\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cv::Mat&nbsp;detectPose(const&nbsp;cv::Mat&amp; frame)&nbsp;{<br>&nbsp; &nbsp; cv::Mat result_frame = frame.clone();<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;try&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa41\uff1a\u9884\u5904\u7406 - Letterbox\u7b97\u6cd5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Mat blob;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;x_factor, y_factor;<br>&nbsp; &nbsp; &nbsp; &nbsp; preprocessImage(frame, blob, x_factor, y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa42\uff1a\u521b\u5efa\u8f93\u5165\u5f20\u91cf - \u96f6\u62f7\u8d1d\u4f18\u5316<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;int64_t&gt; input_shape = {1,&nbsp;3, INPUT_SIZE, INPUT_SIZE};<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;auto&nbsp;memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);<br>&nbsp; &nbsp; &nbsp; &nbsp; Ort::Value input_tensor = Ort::Value::CreateTensor&lt;float&gt;(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memory_info,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (float*)blob.data, &nbsp; &nbsp; &nbsp;<em>\/\/ \u76f4\u63a5\u4f7f\u7528OpenCV Mat\u6570\u636e<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; blob.total(),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input_shape.data(),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input_shape.size()<br>&nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa43\uff1a\u6267\u884c\u63a8\u7406<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;auto&nbsp;output_tensors = session-&gt;Run(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ort::RunOptions{nullptr},&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input_names.data(),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &amp;input_tensor,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; input_names.size(),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output_names.data(),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output_names.size()<br>&nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa44\uff1a\u540e\u5904\u7406<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float* pdata = output_tensors&#91;0].GetTensorMutableData&lt;float&gt;();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;out_feat =&nbsp;static_cast&lt;int&gt;(output_dims&#91;2]); &nbsp;<em>\/\/ 56\u7279\u5f81<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;out_box =&nbsp;static_cast&lt;int&gt;(output_dims&#91;1]); &nbsp;&nbsp;<em>\/\/ 8400\u68c0\u6d4b\u6846<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;cv::Rect&gt; boxes;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;float&gt; confidences;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;cv::Mat&gt; keypoints_data;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; postprocessResults(pdata, out_feat, out_box, x_factor, y_factor,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boxes, confidences, keypoints_data, frame.cols, frame.rows);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa45\uff1aNMS\u53bb\u91cd<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;int&gt; indices;<br>&nbsp; &nbsp; &nbsp; &nbsp; cv::dnn::NMSBoxes(boxes, confidences, CONFIDENCE_THRESHOLD, NMS_THRESHOLD, indices);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa46\uff1a\u53ef\u89c6\u5316\u7ed3\u679c<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; renderResults(result_frame, boxes, confidences, keypoints_data, indices, x_factor, y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; }&nbsp;catch&nbsp;(conststd::exception&amp; e) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::cerr&nbsp;&lt;&lt;&nbsp;\"Error during pose detection: \"&nbsp;&lt;&lt; e.what() &lt;&lt;&nbsp;std::endl;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;return&nbsp;result_frame;<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. \u540e\u5904\u7406\u5b9e\u73b0<\/strong><\/h3>\n\n\n\n<p>\u6211\u4eec\u7684\u540e\u5904\u7406\u4e13\u95e8\u9488\u5bf956\u7279\u5f81\u8f93\u51fa\u4f18\u5316\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;postprocessResults(const&nbsp;float* pdata,&nbsp;int&nbsp;out_feat,&nbsp;int&nbsp;out_box,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;float&nbsp;x_factor,&nbsp;float&nbsp;y_factor,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;cv::Rect&gt;&amp; boxes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;float&gt;&amp; confidences,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;cv::Mat&gt;&amp; keypoints)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; cv::Mat detection_output = cv::Mat(out_box, out_feat, CV_32F, (float*)pdata);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u81ea\u52a8\u683c\u5f0f\u9002\u914d\uff1a\u5904\u7406&#91;56,8400]\u548c&#91;8400,56]\u4e24\u79cd\u683c\u5f0f<\/em><br>&nbsp; &nbsp;&nbsp;if&nbsp;(out_box ==&nbsp;56) {<br>&nbsp; &nbsp; &nbsp; &nbsp; detection_output = detection_output.t();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::swap(out_box, out_feat);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u904d\u5386\u6240\u6709\u68c0\u6d4b\u7ed3\u679c<\/em><br>&nbsp; &nbsp;&nbsp;for(int&nbsp;i =&nbsp;0; i &lt; detection_output.rows; ++i) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;conf = detection_output.at&lt;float&gt;(i,&nbsp;4);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if(conf &gt;= CONFIDENCE_THRESHOLD) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d6\u8fb9\u754c\u6846\uff08\u4e2d\u5fc3\u70b9\u683c\u5f0f\u8f6c\u5de6\u4e0a\u89d2\u683c\u5f0f\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;cx = detection_output.at&lt;float&gt;(i,&nbsp;0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;cy = detection_output.at&lt;float&gt;(i,&nbsp;1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;bw = detection_output.at&lt;float&gt;(i,&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;bh = detection_output.at&lt;float&gt;(i,&nbsp;3);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5750\u6807\u8fd8\u539f\u5230\u539f\u56fe\u5c3a\u5bf8<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;left =&nbsp;static_cast&lt;int&gt;((cx -&nbsp;0.5&nbsp;* bw) * x_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;top =&nbsp;static_cast&lt;int&gt;((cy -&nbsp;0.5&nbsp;* bh) * y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;width =&nbsp;static_cast&lt;int&gt;(bw * x_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;height =&nbsp;static_cast&lt;int&gt;(bh * y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boxes.emplace_back(left, top, width, height);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; confidences.push_back(conf);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d6\u5173\u952e\u70b9\u6570\u636e\uff08\u56fa\u5b9a51\u4e2a\u503c\uff1a17\u4e2a\u5173\u952e\u70b9\u00d73\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cv::Mat keypoint_data = detection_output.row(i).colRange(5,&nbsp;56).clone();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; keypoints.push_back(keypoint_data);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. \u53ef\u89c6\u5316\u6e32\u67d3\uff1a\u5173\u952e\u70b9\u548c\u9aa8\u67b6\u7ed8\u5236<\/strong><\/h3>\n\n\n\n<p>\u5b9e\u9645\u7684\u53ef\u89c6\u5316\u5b9e\u73b0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;renderResults(cv::Mat&amp; result_frame,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;cv::Rect&gt;&amp; boxes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;float&gt;&amp; confidences,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;cv::Mat&gt;&amp; keypoints_data,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;int&gt;&amp; indices,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;x_factor,&nbsp;float&nbsp;y_factor)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;i : indices) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u7ed8\u5236\u8fb9\u754c\u6846<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cv::rectangle(result_frame, boxes&#91;i], cv::Scalar(0,&nbsp;255,&nbsp;0),&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u7ed8\u5236\u7f6e\u4fe1\u5ea6<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::string&nbsp;label =&nbsp;\"Person: \"&nbsp;+&nbsp;std::to_string(confidences&#91;i]).substr(0,&nbsp;4);<br>&nbsp; &nbsp; &nbsp; &nbsp; cv::putText(result_frame, label,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::Point(boxes&#91;i].x, boxes&#91;i].y -&nbsp;10),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::FONT_HERSHEY_SIMPLEX,&nbsp;0.5,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::Scalar(0,&nbsp;255,&nbsp;0),&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5904\u7406\u5173\u952e\u70b9\u6570\u636e<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Mat keypoints_raw = keypoints_data&#91;i];<br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Mat keypoints = keypoints_raw.reshape(1,&nbsp;17); &nbsp;<em>\/\/ \u91cd\u5851\u4e3a17x3<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;cv::Mat&nbsp;scaled_keypoints(17,&nbsp;3, CV_32F);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5173\u952e\u70b9\u5750\u6807\u53d8\u6362\u5230\u539f\u56fe\u5c3a\u5bf8<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int&nbsp;j =&nbsp;0; j &lt;&nbsp;17; ++j) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scaled_keypoints.at&lt;float&gt;(j,&nbsp;0) = keypoints.at&lt;float&gt;(j,&nbsp;0) * x_factor;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scaled_keypoints.at&lt;float&gt;(j,&nbsp;1) = keypoints.at&lt;float&gt;(j,&nbsp;1) * y_factor;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scaled_keypoints.at&lt;float&gt;(j,&nbsp;2) = keypoints.at&lt;float&gt;(j,&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u7ed8\u5236\u59ff\u6001\u8fde\u63a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; drawPoseConnections(result_frame, scaled_keypoints, colors_table);<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. \u5b9e\u9645\u914d\u7f6e\u53c2\u6570<\/strong><\/h3>\n\n\n\n<p>\u9879\u76ee\u4e2d\u4f7f\u7528\u7684\u5177\u4f53\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ \u914d\u7f6e\u53c2\u6570\uff08\u5728src\/yolov8_ort_pose.cpp\u4e2d\u5b9a\u4e49\uff09<\/em><br>const&nbsp;std::string&nbsp;MODEL_PATH =&nbsp;\"G:\\\\yolov8-ort-pose\\\\yolov8n-pose.onnx\";<br>const&nbsp;std::string&nbsp;IMAGE_PATH =&nbsp;\"G:\\\\yolov8-ort-pose\\\\dance.png\";<br>const&nbsp;float&nbsp;CONFIDENCE_THRESHOLD =&nbsp;0.5f; &nbsp;<em>\/\/ \u7f6e\u4fe1\u5ea6\u9608\u503c<\/em><br>const&nbsp;float&nbsp;NMS_THRESHOLD =&nbsp;0.45f; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ NMS\u9608\u503c<\/em><br>const&nbsp;int&nbsp;INPUT_SIZE =&nbsp;640; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u56fa\u5b9a\u8f93\u5165\u5c3a\u5bf8<\/em><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>8. \u5e94\u7528\u63a5\u53e3\uff1a\u56fe\u50cf\u548c\u89c6\u9891\u5904\u7406<\/strong><\/h3>\n\n\n\n<p>\u9879\u76ee\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u4f7f\u7528\u63a5\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ \u5904\u7406\u5355\u5f20\u56fe\u50cf<\/em><br>void&nbsp;processImage(const&nbsp;std::string&amp; input_path,&nbsp;const&nbsp;std::string&amp; output_path);<br><br><em>\/\/ \u5904\u7406\u89c6\u9891\u6587\u4ef6<\/em><br>void&nbsp;processVideo(const&nbsp;std::string&amp; input_path,&nbsp;const&nbsp;std::string&amp; output_path);<br><br><em>\/\/ \u4e3b\u51fd\u6570\u4f7f\u7528\u793a\u4f8b<\/em><br>int&nbsp;main(int&nbsp;argc,&nbsp;char* argv&#91;])&nbsp;{<br>&nbsp; &nbsp; YOLOv8PoseDetector detector;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;if&nbsp;(argc ==&nbsp;1) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u9ed8\u8ba4\u6d4b\u8bd5\u6a21\u5f0f<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; detector.processImage(IMAGE_PATH,&nbsp;\"output\/result.jpg\");<br>&nbsp; &nbsp; }&nbsp;elseif&nbsp;(argc ==&nbsp;3) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::string&nbsp;mode = argv&#91;1];<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::string&nbsp;input_path = argv&#91;2];<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(mode ==&nbsp;\"-i\") {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detector.processImage(input_path,&nbsp;\"output\/result.jpg\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;elseif&nbsp;(mode ==&nbsp;\"-v\") {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; detector.processVideo(input_path,&nbsp;\"output\/result.mp4\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;return0;<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u9879\u76ee\u7279\u70b9\u603b\u7ed3<\/strong><\/h3>\n\n\n\n<p>\u6211\u4eec\u7684ONNX Runtime\u90e8\u7f72\u5b9e\u73b0\u5177\u6709\u4ee5\u4e0b\u7279\u70b9\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7b80\u6d01\u9ad8\u6548<\/strong>\uff1a\u4e13\u6ce8\u6838\u5fc3\u529f\u80fd\uff0c\u53bb\u9664\u5197\u4f59\u7ec4\u4ef6<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u5b89\u5168<\/strong>\uff1a\u6b63\u786e\u7684\u8d44\u6e90\u7ba1\u7406\u548c\u5f02\u5e38\u5904\u7406<\/li>\n\n\n\n<li><strong>\u96f6\u62f7\u8d1d<\/strong>\uff1a\u76f4\u63a5\u4f7f\u7528OpenCV Mat\u6570\u636e\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u5185\u5b58\u62f7\u8d1d<\/li>\n\n\n\n<li><strong>\u81ea\u52a8\u9002\u914d<\/strong>\uff1a\u667a\u80fd\u5904\u7406\u4e0d\u540c\u7684\u6a21\u578b\u8f93\u51fa\u683c\u5f0f<\/li>\n\n\n\n<li><strong>\u6613\u4e8e\u4f7f\u7528<\/strong>\uff1a\u7b80\u5355\u7684\u547d\u4ee4\u884c\u63a5\u53e3\uff0c\u652f\u6301\u56fe\u50cf\u548c\u89c6\u9891\u5904\u7406<\/li>\n<\/ol>\n\n\n\n<p>\u8fd9\u79cd\u5b9e\u73b0\u65b9\u5f0f\u5728\u4fdd\u8bc1\u6027\u80fd\u7684\u540c\u65f6\uff0c\u7ef4\u6301\u4e86\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u7ef4\u62a4\u6027\uff0c\u662f\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u7684\u7406\u60f3\u9009\u62e9\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\ud83d\udd27 \u6838\u5fc3\u6280\u672f\u5b9e\u73b0\u6df1\u5ea6\u89e3\u6790<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. \u56fe\u50cf\u9884\u5904\u7406\uff1aLetterbox<\/strong><\/h3>\n\n\n\n<p>\u4f20\u7edf\u7684\u56fe\u50cf\u7f29\u653e\u4f1a\u5bfc\u81f4\u4eba\u4f53\u6bd4\u4f8b\u5931\u8c03\uff0c\u5f71\u54cd\u68c0\u6d4b\u7cbe\u5ea6\u3002\u6211\u4eec\u91c7\u7528\u7684Letterbox\u7b97\u6cd5\u5de7\u5999\u5730\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;preprocessImage(const&nbsp;cv::Mat&amp; frame, cv::Mat&amp; blob,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&amp; x_factor,&nbsp;float&amp; y_factor)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u8ba1\u7b97\u6700\u4f18\u7f29\u653e\u6bd4\u4f8b\uff0c\u4fdd\u6301\u5bbd\u9ad8\u6bd4<\/em><br>&nbsp; &nbsp;&nbsp;float&nbsp;scale =&nbsp;std::min(static_cast&lt;float&gt;(INPUT_SIZE) \/ frame.cols,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;static_cast&lt;float&gt;(INPUT_SIZE) \/ frame.rows);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u7b49\u6bd4\u4f8b\u7f29\u653e<\/em><br>&nbsp; &nbsp;&nbsp;int&nbsp;new_width =&nbsp;static_cast&lt;int&gt;(frame.cols * scale);<br>&nbsp; &nbsp;&nbsp;int&nbsp;new_height =&nbsp;static_cast&lt;int&gt;(frame.rows * scale);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; cv::Mat scaled_image;<br>&nbsp; &nbsp; cv::resize(frame, scaled_image, cv::Size(new_width, new_height));<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u521b\u5efa640x640\u6807\u51c6\u753b\u5e03\uff0c\u5de6\u4e0a\u89d2\u5bf9\u9f50<\/em><br>&nbsp; &nbsp; cv::Mat resized_image = cv::Mat::zeros(cv::Size(INPUT_SIZE, INPUT_SIZE), CV_8UC3);<br>&nbsp; &nbsp;&nbsp;cv::Rect&nbsp;roi(0,&nbsp;0, new_width, new_height);<br>&nbsp; &nbsp; scaled_image.copyTo(resized_image(roi));<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u8bb0\u5f55\u7f29\u653e\u56e0\u5b50\u7528\u4e8e\u540e\u7eed\u5750\u6807\u8fd8\u539f<\/em><br>&nbsp; &nbsp; x_factor =&nbsp;1.0f&nbsp;\/ scale;<br>&nbsp; &nbsp; y_factor =&nbsp;1.0f&nbsp;\/ scale;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u8f6c\u6362\u4e3a\u6a21\u578b\u8f93\u5165\u683c\u5f0f<\/em><br>&nbsp; &nbsp; blob = cv::dnn::blobFromImage(resized_image,&nbsp;1.0\/255.0,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cv::Size(INPUT_SIZE, INPUT_SIZE),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cv::Scalar(),&nbsp;true,&nbsp;false);<br>}<\/code><\/pre>\n\n\n\n<p><strong>\u6838\u5fc3\u601d\u60f3\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4fdd\u6301\u539f\u56fe\u5bbd\u9ad8\u6bd4\uff0c\u907f\u514d\u4eba\u4f53\u53d8\u5f62<\/li>\n\n\n\n<li>\u4f7f\u7528\u9ed1\u8272\u586b\u5145\uff0c\u6a21\u62df\u771f\u5b9e\u573a\u666f\u8fb9\u7f18<\/li>\n\n\n\n<li>\u5de6\u4e0a\u89d2\u5bf9\u9f50\uff0c\u7b80\u5316\u5750\u6807\u8f6c\u6362\u903b\u8f91<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. ONNX Runtime\u9ad8\u6027\u80fd\u63a8\u7406\u914d\u7f6e<\/strong><\/h3>\n\n\n\n<p>\u63a8\u7406\u5f15\u64ce\u7684\u914d\u7f6e\u76f4\u63a5\u5f71\u54cd\u7cfb\u7edf\u6027\u80fd\u3002\u7531\u4e8e\u6ca1\u6709\u52a0\u8f7d\u591a\u5f20\u56fe\u7247\u548c\u591a\u4e2a\u89c6\u9891\uff0c\u6700\u4f18\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ \u73af\u5883\u521d\u59cb\u5316<\/em><br>Ort::Env&nbsp;env(ORT_LOGGING_LEVEL_WARNING,&nbsp;\"YOLOv8-Pose\");<br><br><em>\/\/ \u6027\u80fd\u8c03\u4f18\u914d\u7f6e<\/em><br>Ort::SessionOptions session_options;<br>session_options.SetIntraOpNumThreads(1); &nbsp;<em>\/\/ \u6839\u636eCPU\u6838\u6570\u8c03\u6574<\/em><br>session_options.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_EXTENDED);<br><br><em>\/\/ \u521b\u5efa\u63a8\u7406\u4f1a\u8bdd<\/em><br>std::wstring&nbsp;model_path_w(MODEL_PATH.begin(), MODEL_PATH.end());<br>session =&nbsp;std::make_unique&lt;Ort::Session&gt;(env, model_path_w.c_str(), session_options);<\/code><\/pre>\n\n\n\n<p><strong>\u6027\u80fd\u4f18\u5316\u8981\u70b9\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7ebf\u7a0b\u914d\u7f6e<\/strong>\uff1a\u5355\u7ebf\u7a0b\u63a8\u7406\u907f\u514d\u4e0a\u4e0b\u6587\u5207\u6362\u5f00\u9500<\/li>\n\n\n\n<li><strong>\u56fe\u4f18\u5316<\/strong>\uff1aEXTENDED\u7ea7\u522b\u5e73\u8861\u4f18\u5316\u6548\u679c\u548c\u7f16\u8bd1\u65f6\u95f4<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u7ba1\u7406<\/strong>\uff1aArena\u5206\u914d\u5668\u51cf\u5c11\u5185\u5b58\u788e\u7247<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. \u56fe\u50cf\u540e\u5904\u7406\uff1a\u4ece\u539f\u59cb\u8f93\u51fa\u5230\u7cbe\u786e\u7ed3\u679c<\/strong><\/h3>\n\n\n\n<p>\u6a21\u578b\u7684\u539f\u59cb\u8f93\u51fa\u9700\u8981\u7ecf\u8fc7\u7cbe\u5fc3\u8bbe\u8ba1\u7684\u540e\u5904\u7406\u6d41\u7a0b\u624d\u80fd\u5f97\u5230\u53ef\u7528\u7684\u68c0\u6d4b\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;postprocessResults(const&nbsp;float* pdata,&nbsp;int&nbsp;out_feat,&nbsp;int&nbsp;out_box,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;float&nbsp;x_factor,&nbsp;float&nbsp;y_factor,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;cv::Rect&gt;&amp; boxes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;float&gt;&amp; confidences,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;cv::Mat&gt;&amp; keypoints)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; cv::Mat detection_output = cv::Mat(out_box, out_feat, CV_32F, (float*)pdata);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u81ea\u52a8\u683c\u5f0f\u9002\u914d - \u5904\u7406\u4e0d\u540c\u7684\u6a21\u578b\u8f93\u51fa\u683c\u5f0f<\/em><br>&nbsp; &nbsp;&nbsp;if&nbsp;(out_box ==&nbsp;56) {<br>&nbsp; &nbsp; &nbsp; &nbsp; detection_output = detection_output.t();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::swap(out_box, out_feat);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u904d\u5386\u6240\u6709\u68c0\u6d4b\u7ed3\u679c<\/em><br>&nbsp; &nbsp;&nbsp;for(int&nbsp;i =&nbsp;0; i &lt; detection_output.rows; ++i) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;conf = detection_output.at&lt;float&gt;(i,&nbsp;4);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if(conf &gt;= CONFIDENCE_THRESHOLD) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d6\u8fb9\u754c\u6846\uff08\u4e2d\u5fc3\u70b9\u683c\u5f0f\u8f6c\u5de6\u4e0a\u89d2\u683c\u5f0f\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;cx = detection_output.at&lt;float&gt;(i,&nbsp;0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;cy = detection_output.at&lt;float&gt;(i,&nbsp;1);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;bw = detection_output.at&lt;float&gt;(i,&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;bh = detection_output.at&lt;float&gt;(i,&nbsp;3);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5750\u6807\u8fd8\u539f\u5230\u539f\u56fe\u5c3a\u5bf8<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;left =&nbsp;static_cast&lt;int&gt;((cx -&nbsp;0.5&nbsp;* bw) * x_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;top =&nbsp;static_cast&lt;int&gt;((cy -&nbsp;0.5&nbsp;* bh) * y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;width =&nbsp;static_cast&lt;int&gt;(bw * x_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;height =&nbsp;static_cast&lt;int&gt;(bh * y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boxes.emplace_back(left, top, width, height);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; confidences.push_back(conf);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d6\u5173\u952e\u70b9\u6570\u636e\uff0851\u4e2a\u503c\uff1a17\u4e2a\u5173\u952e\u70b9\u00d73\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cv::Mat keypoint_data = detection_output.row(i).colRange(5,&nbsp;56).clone();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; keypoints.push_back(keypoint_data);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p><strong>\u8bbe\u8ba1\u4eae\u70b9\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u81ea\u52a8\u683c\u5f0f\u9002\u914d<\/strong>\uff1a\u667a\u80fd\u5904\u7406\u4e0d\u540c\u6a21\u578b\u7684\u8f93\u51fa\u683c\u5f0f<\/li>\n\n\n\n<li><strong>\u65e9\u671f\u7b5b\u9009<\/strong>\uff1a\u7f6e\u4fe1\u5ea6\u9884\u7b5b\u9009\u51cf\u5c11\u65e0\u6548\u8ba1\u7b97<\/li>\n\n\n\n<li><strong>\u5750\u6807\u7cbe\u786e\u8fd8\u539f<\/strong>\uff1a\u8003\u8651\u9884\u5904\u7406\u7f29\u653e\u56e0\u5b50\u7684\u7cbe\u786e\u5750\u6807\u8f6c\u6362<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. \u89e3\u5256\u5b66\u51c6\u786e\u7684\u53ef\u89c6\u5316\u6e32\u67d3<\/strong><\/h3>\n\n\n\n<p>\u6700\u540e\u4e00\u6b65\u662f\u5c06\u68c0\u6d4b\u7ed3\u679c\u4ee5\u76f4\u89c2\u7684\u65b9\u5f0f\u5c55\u73b0\u51fa\u6765\u3002\u6211\u4eec\u57fa\u4e8e\u4eba\u4f53\u89e3\u5256\u5b66\u7ed3\u6784\u8bbe\u8ba1\u4e86\u79d1\u5b66\u7684\u53ef\u89c6\u5316\u65b9\u6848\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;drawPoseConnections(cv::Mat&amp; frame,&nbsp;const&nbsp;cv::Mat&amp; keypoints,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;cv::Scalar&gt;&amp; colors_tables)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u57fa\u4e8e\u4eba\u4f53\u89e3\u5256\u5b66\u7684\u9aa8\u67b6\u8fde\u63a5\u5b9a\u4e49<\/em><br>&nbsp; &nbsp;&nbsp;std::vector&lt;std::pair&lt;int,&nbsp;int&gt;&gt; connections_pairs = {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u9762\u90e8\u8fde\u63a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {0,&nbsp;1}, {0,&nbsp;2}, {1,&nbsp;3}, {2,&nbsp;4},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u8eaf\u5e72\u8fde\u63a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {5,&nbsp;6}, {5,&nbsp;11}, {6,&nbsp;12}, {11,&nbsp;12},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u81c2\u8fde\u63a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {5,&nbsp;7}, {7,&nbsp;9},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u53f3\u81c2\u8fde\u63a5 &nbsp;<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {6,&nbsp;8}, {8,&nbsp;10},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u817f\u8fde\u63a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {11,&nbsp;13}, {13,&nbsp;15},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u53f3\u817f\u8fde\u63a5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {12,&nbsp;14}, {14,&nbsp;16}<br>&nbsp; &nbsp; };<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;constfloat&nbsp;visibility_threshold =&nbsp;0.3f;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u5148\u7ed8\u5236\u9aa8\u67b6\u8fde\u63a5\uff0c\u518d\u7ed8\u5236\u5173\u952e\u70b9<\/em><br>&nbsp; &nbsp;&nbsp;for&nbsp;(constauto&amp; connection : connections_pairs) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;pt1_idx = connection.first;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;pt2_idx = connection.second;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;vis1 = keypoints.at&lt;float&gt;(pt1_idx,&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;vis2 = keypoints.at&lt;float&gt;(pt2_idx,&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(vis1 &gt; visibility_threshold &amp;&amp; vis2 &gt; visibility_threshold) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;cv::Point&nbsp;pt1(keypoints.at&lt;float&gt;(pt1_idx,&nbsp;0), keypoints.at&lt;float&gt;(pt1_idx,&nbsp;1));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;cv::Point&nbsp;pt2(keypoints.at&lt;float&gt;(pt2_idx,&nbsp;0), keypoints.at&lt;float&gt;(pt2_idx,&nbsp;1));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cv::line(frame, pt1, pt2, colors_tables&#91;connection.first % colors_tables.size()],&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;2, cv::LINE_AA);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\ud83c\udfa8 Pose\u524d\u540e\u5904\u7406\u6280\u672f\u6df1\u5ea6\u89e3\u6790<\/strong><\/h2>\n\n\n\n<p>\u59ff\u6001\u68c0\u6d4b\u7684\u7cbe\u9ad3\u5728\u4e8e\u524d\u540e\u5904\u7406\u7684\u7cbe\u7ec6\u5316\u8bbe\u8ba1\u3002\u8ba9\u6211\u4eec\u6df1\u5165\u89e3\u6790\u6bcf\u4e2a\u73af\u8282\u7684\u6280\u672f\u7ec6\u8282\u548c\u8bbe\u8ba1\u601d\u8def\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\ud83d\udcd0 \u524d\u5904\u7406\uff1a\u4ece\u539f\u59cb\u56fe\u50cf\u5230\u6a21\u578b\u8f93\u5165<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. \u56fe\u50cf\u9884\u5904\u7406\u7ba1\u9053\u8bbe\u8ba1<\/strong><\/h4>\n\n\n\n<p>\u6211\u4eec\u7684\u9884\u5904\u7406\u6d41\u7a0b\u4e13\u95e8\u9488\u5bf9\u4eba\u4f53\u59ff\u6001\u68c0\u6d4b\u4f18\u5316\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;preprocessImage(const&nbsp;cv::Mat&amp; frame, cv::Mat&amp; blob,&nbsp;float&amp; x_factor,&nbsp;float&amp; y_factor)&nbsp;{<br>&nbsp; &nbsp;&nbsp;int&nbsp;original_width = frame.cols;<br>&nbsp; &nbsp;&nbsp;int&nbsp;original_height = frame.rows;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa41\uff1a\u8ba1\u7b97\u4fdd\u6301\u5bbd\u9ad8\u6bd4\u7684\u6700\u4f73\u7f29\u653e\u56e0\u5b50<\/em><br>&nbsp; &nbsp;&nbsp;float&nbsp;scale =&nbsp;std::min(static_cast&lt;float&gt;(INPUT_SIZE) \/ original_width,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;static_cast&lt;float&gt;(INPUT_SIZE) \/ original_height);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa42\uff1a\u8ba1\u7b97\u7f29\u653e\u540e\u7684\u5b9e\u9645\u5c3a\u5bf8<\/em><br>&nbsp; &nbsp;&nbsp;int&nbsp;new_width =&nbsp;static_cast&lt;int&gt;(original_width * scale);<br>&nbsp; &nbsp;&nbsp;int&nbsp;new_height =&nbsp;static_cast&lt;int&gt;(original_height * scale);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa43\uff1a\u9ad8\u8d28\u91cf\u56fe\u50cf\u7f29\u653e<\/em><br>&nbsp; &nbsp; cv::Mat scaled_image;<br>&nbsp; &nbsp; cv::resize(frame, scaled_image, cv::Size(new_width, new_height),&nbsp;0,&nbsp;0, cv::INTER_LINEAR);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa44\uff1a\u521b\u5efa\u6807\u51c6\u5316\u753b\u5e03\uff08\u5de6\u4e0a\u89d2\u5bf9\u9f50\u7b56\u7565\uff09<\/em><br>&nbsp; &nbsp; cv::Mat resized_image = cv::Mat::zeros(cv::Size(INPUT_SIZE, INPUT_SIZE), CV_8UC3);<br>&nbsp; &nbsp;&nbsp;cv::Rect&nbsp;roi(0,&nbsp;0, new_width, new_height);<br>&nbsp; &nbsp; scaled_image.copyTo(resized_image(roi));<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa45\uff1a\u8bb0\u5f55\u5750\u6807\u8fd8\u539f\u53c2\u6570<\/em><br>&nbsp; &nbsp; x_factor =&nbsp;1.0f&nbsp;\/ scale;<br>&nbsp; &nbsp; y_factor =&nbsp;1.0f&nbsp;\/ scale;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6b65\u9aa46\uff1a\u8f6c\u6362\u4e3a\u795e\u7ecf\u7f51\u7edc\u8f93\u5165\u683c\u5f0f<\/em><br>&nbsp; &nbsp; blob = cv::dnn::blobFromImage(<br>&nbsp; &nbsp; &nbsp; &nbsp; resized_image, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ \u8f93\u5165\u56fe\u50cf<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;1.0&nbsp;\/&nbsp;255.0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u50cf\u7d20\u5f52\u4e00\u5316\uff1a&#91;0,255] -&gt; &#91;0,1]<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Size(INPUT_SIZE, INPUT_SIZE),&nbsp;<em>\/\/ \u76ee\u6807\u5c3a\u5bf8<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Scalar(), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ \u4e0d\u8fdb\u884c\u5747\u503c\u51cf\u6cd5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;true, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ swapRB: BGR-&gt;RGB<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;false&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u4e0d\u8fdb\u884c\u4e2d\u5fc3\u88c1\u526a<\/em><br>&nbsp; &nbsp; );<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Letterbox\u7b97\u6cd5\u7684\u8bbe\u8ba1\u54f2\u5b66<\/strong><\/h4>\n\n\n\n<p><strong>\u4e3a\u4ec0\u4e48\u9009\u62e9\u5de6\u4e0a\u89d2\u5bf9\u9f50\uff1f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u539f\u56fe(1920x1080) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Letterbox\u5904\u7406\u540e(640x640)<br>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 &nbsp; &nbsp; &nbsp;\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br>\u2502 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u2502 &nbsp; &nbsp; &nbsp;\u2502 \u7f29\u653e\u56fe\u50cf &nbsp;\u2502 &nbsp;\u9ed1\u8272 &nbsp; \u2502<br>\u2502 &nbsp; &nbsp;\u4eba\u4f53\u56fe\u50cf &nbsp; &nbsp; &nbsp;\u2502 \u2500\u2500\u25b6 &nbsp;\u2502 640x360 &nbsp;\u2502 &nbsp;\u586b\u5145 &nbsp; \u2502<br>\u2502 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u2502 &nbsp; &nbsp; &nbsp;\u2502 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u2502 &nbsp;\u533a\u57df &nbsp; \u2502<br>\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 &nbsp; &nbsp; &nbsp;\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u5de6\u4e0a\u89d2\u5bf9\u9f50 &nbsp; \u7b80\u5316\u5750\u6807\u8f6c\u6362<\/code><\/pre>\n\n\n\n<p><strong>\u6280\u672f\u4f18\u52bf\u5206\u6790\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5750\u6807\u8f6c\u6362\u7b80\u5316<\/strong>\uff1a\u65e0\u9700\u8ba1\u7b97\u586b\u5145\u504f\u79fb\u91cf<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u5e03\u5c40\u4f18\u5316<\/strong>\uff1a\u8fde\u7eed\u7684\u5185\u5b58\u8bbf\u95ee\u6a21\u5f0f<\/li>\n\n\n\n<li><strong>\u8ba1\u7b97\u6548\u7387\u63d0\u5347<\/strong>\uff1a\u51cf\u5c11\u5750\u6807\u53d8\u6362\u7684\u590d\u6742\u5ea6<\/li>\n\n\n\n<li><strong>\u8fb9\u754c\u5904\u7406\u53cb\u597d<\/strong>\uff1a\u4eba\u4f53\u901a\u5e38\u51fa\u73b0\u5728\u56fe\u50cf\u4e0a\u65b9<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. \u6570\u636e\u683c\u5f0f\u8f6c\u6362\u8be6\u89e3<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ OpenCV Mat\u683c\u5f0f\u8f6c\u6362\u4e3aONNX Runtime Tensor<\/em><br>std::vector&lt;int64_t&gt; input_shape = {1,&nbsp;3, INPUT_SIZE, INPUT_SIZE};<br>auto&nbsp;memory_info = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);<br><br>Ort::Value input_tensor = Ort::Value::CreateTensor&lt;float&gt;(<br>&nbsp; &nbsp; memory_info,<br>&nbsp; &nbsp; (float*)blob.data, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ \u96f6\u62f7\u8d1d\u6570\u636e\u4f20\u8f93<\/em><br>&nbsp; &nbsp; blob.total(), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ 1*3*640*640 = 1,228,800\u4e2afloat<\/em><br>&nbsp; &nbsp; input_shape.data(),<br>&nbsp; &nbsp; input_shape.size()<br>);<\/code><\/pre>\n\n\n\n<p><strong>\u5185\u5b58\u5e03\u5c40\u8f6c\u6362\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>OpenCV Mat (HWC): &#91;Height]&#91;Width]&#91;Channels]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\u2193 cv::dnn::blobFromImage<br>ONNX Tensor (NCHW): &#91;Batch]&#91;Channels]&#91;Height]&#91;Width]<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\ud83d\udd04 \u540e\u5904\u7406\uff1a\u4ece\u6a21\u578b\u8f93\u51fa\u5230\u53ef\u89c6\u5316\u7ed3\u679c<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. YOLOv8-Pose\u8f93\u51fa\u89e3\u6790<\/strong><\/h4>\n\n\n\n<p><strong>\u6a21\u578b\u8f93\u51fa\u683c\u5f0f\u6df1\u5ea6\u5206\u6790\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ YOLOv8-Pose\u8f93\u51fa\u5f20\u91cf\u7ed3\u6784<\/em><br>\u8f93\u51fa\u5f62\u72b6: &#91;1,&nbsp;56,&nbsp;8400] \u6216 &#91;1,&nbsp;8400,&nbsp;56]<br>\u2502<br>\u251c\u2500\u2500 \u7ef4\u5ea60:&nbsp;Batch&nbsp;Size&nbsp;(\u56fa\u5b9a\u4e3a1)<br>\u251c\u2500\u2500 \u7ef4\u5ea61\/2: \u7279\u5f81\u7ef4\u5ea6(56)&nbsp;\u548c \u68c0\u6d4b\u6846\u6570\u91cf(8400)<br>\u2502<br>\u7279\u5f8156\u7ef4\u8be6\u7ec6\u7ed3\u6784:<br>\u251c\u2500\u2500 &#91;0-3]: \u8fb9\u754c\u6846\u5750\u6807 &#91;center_x, center_y, width, height]<br>\u251c\u2500\u2500 &#91;4]: &nbsp; \u4eba\u4f53\u68c0\u6d4b\u7f6e\u4fe1\u5ea6 &#91;0-1]<br>\u2514\u2500\u2500 &#91;5-55]: 17\u4e2aCOCO\u5173\u952e\u70b9 &#91;x1,y1,v1, x2,y2,v2, ..., x17,y17,v17]<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \u5176\u4e2d vi \u4e3a\u53ef\u89c1\u6027\u5206\u6570 &#91;0-1]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. \u8f93\u51fa\u683c\u5f0f\u9002\u914d<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;postprocessResults(const&nbsp;float* pdata,&nbsp;int&nbsp;out_feat,&nbsp;int&nbsp;out_box,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;float&nbsp;x_factor,&nbsp;float&nbsp;y_factor,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;cv::Rect&gt;&amp; boxes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;float&gt;&amp; confidences,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;cv::Mat&gt;&amp; keypoints,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int&nbsp;original_width,&nbsp;int&nbsp;original_height)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u521b\u5efa\u8f93\u51fa\u77e9\u9635\u5305\u88c5\u5668<\/em><br>&nbsp; &nbsp; cv::Mat detection_output = cv::Mat(out_box, out_feat, CV_32F, (float*)pdata);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u81ea\u52a8\u683c\u5f0f\u68c0\u6d4b\u4e0e\u8f6c\u6362<\/em><br>&nbsp; &nbsp;&nbsp;if&nbsp;(out_box ==&nbsp;56) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u68c0\u6d4b\u5230\u8f6c\u7f6e\u683c\u5f0f &#91;56, 8400] -&gt; &#91;8400, 56]<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; detection_output = detection_output.t();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::swap(out_box, out_feat);<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6279\u91cf\u5904\u7406\u68c0\u6d4b\u7ed3\u679c<\/em><br>&nbsp; &nbsp; processDetections(detection_output, x_factor, y_factor,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;boxes, confidences, keypoints,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;original_width, original_height);<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. \u68c0\u6d4b\u7ed3\u679c\u5904\u7406<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;processDetections(const&nbsp;cv::Mat&amp; detection_output,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;x_factor,&nbsp;float&nbsp;y_factor,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;cv::Rect&gt;&amp; boxes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;float&gt;&amp; confidences,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;cv::Mat&gt;&amp; keypoints,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;original_width,&nbsp;int&nbsp;original_height)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u9884\u5206\u914d\u5bb9\u5668\u5bb9\u91cf\uff0c\u63d0\u5347\u6027\u80fd<\/em><br>&nbsp; &nbsp; boxes.reserve(100);<br>&nbsp; &nbsp; confidences.reserve(100);<br>&nbsp; &nbsp; keypoints.reserve(100);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;for(int&nbsp;i =&nbsp;0; i &lt; detection_output.rows; ++i) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;confidence = detection_output.at&lt;float&gt;(i,&nbsp;4);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u65e9\u671f\u7f6e\u4fe1\u5ea6\u7b5b\u9009<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if(confidence &lt; CONFIDENCE_THRESHOLD)&nbsp;continue;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u8fb9\u754c\u6846\u5750\u6807\u63d0\u53d6\u4e0e\u8f6c\u6362<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;cx = detection_output.at&lt;float&gt;(i,&nbsp;0);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;cy = detection_output.at&lt;float&gt;(i,&nbsp;1);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;bw = detection_output.at&lt;float&gt;(i,&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;bh = detection_output.at&lt;float&gt;(i,&nbsp;3);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u4e2d\u5fc3\u70b9\u683c\u5f0f -&gt; \u5de6\u4e0a\u89d2\u683c\u5f0f + \u5750\u6807\u8fd8\u539f<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;left =&nbsp;static_cast&lt;int&gt;((cx -&nbsp;0.5f&nbsp;* bw) * x_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;top =&nbsp;static_cast&lt;int&gt;((cy -&nbsp;0.5f&nbsp;* bh) * y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;width =&nbsp;static_cast&lt;int&gt;(bw * x_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;height =&nbsp;static_cast&lt;int&gt;(bh * y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u8fb9\u754c\u68c0\u67e5\u4e0e\u4fee\u6b63<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; left =&nbsp;std::max(0,&nbsp;std::min(left, original_width -&nbsp;1));<br>&nbsp; &nbsp; &nbsp; &nbsp; top =&nbsp;std::max(0,&nbsp;std::min(top, original_height -&nbsp;1));<br>&nbsp; &nbsp; &nbsp; &nbsp; width =&nbsp;std::min(width, original_width - left);<br>&nbsp; &nbsp; &nbsp; &nbsp; height =&nbsp;std::min(height, original_height - top);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; boxes.emplace_back(left, top, width, height);<br>&nbsp; &nbsp; &nbsp; &nbsp; confidences.push_back(confidence);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5173\u952e\u70b9\u6570\u636e\u63d0\u53d6<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; extractKeypoints(detection_output, i, keypoints);<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. \u5173\u952e\u70b9\u6570\u636e\u5904\u7406\u4e0e\u9a8c\u8bc1<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;extractKeypoints(const&nbsp;cv::Mat&amp; detection_output,&nbsp;int&nbsp;detection_idx,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;std::vector&lt;cv::Mat&gt;&amp; keypoints)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u63d0\u53d651\u4e2a\u5173\u952e\u70b9\u503c (17\u4e2a\u5173\u952e\u70b9 \u00d7 3\u4e2a\u5c5e\u6027)<\/em><br>&nbsp; &nbsp; cv::Mat keypoint_data = detection_output.row(detection_idx).colRange(5,&nbsp;56).clone();<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u53ef\u9009\uff1a\u5173\u952e\u70b9\u8d28\u91cf\u9a8c\u8bc1<\/em><br>&nbsp; &nbsp; validateKeypointQuality(keypoint_data);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; keypoints.push_back(keypoint_data);<br>}<br><br>void&nbsp;validateKeypointQuality(cv::Mat&amp; keypoint_data)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u91cd\u5851\u4e3a\u4fbf\u4e8e\u5904\u7406\u7684\u683c\u5f0f &#91;17, 3]<\/em><br>&nbsp; &nbsp; cv::Mat reshaped = keypoint_data.reshape(1,&nbsp;17);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;for(int&nbsp;i =&nbsp;0; i &lt;&nbsp;17; ++i) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;x = reshaped.at&lt;float&gt;(i,&nbsp;0);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;y = reshaped.at&lt;float&gt;(i,&nbsp;1);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;visibility = reshaped.at&lt;float&gt;(i,&nbsp;2);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5750\u6807\u5408\u7406\u6027\u68c0\u67e5<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if(x &lt;&nbsp;0&nbsp;|| x &gt; INPUT_SIZE || y &lt;&nbsp;0&nbsp;|| y &gt; INPUT_SIZE) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; reshaped.at&lt;float&gt;(i,&nbsp;2) =&nbsp;0.0f; &nbsp;<em>\/\/ \u6807\u8bb0\u4e3a\u4e0d\u53ef\u89c1<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u53ef\u89c1\u6027\u503c\u89c4\u8303\u5316<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; visibility =&nbsp;std::max(0.0f,&nbsp;std::min(1.0f, visibility));<br>&nbsp; &nbsp; &nbsp; &nbsp; reshaped.at&lt;float&gt;(i,&nbsp;2) = visibility;<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. NMS\u975e\u6781\u5927\u503c\u6291\u5236<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ \u9ad8\u6548NMS\u5904\u7406<\/em><br>std::vector&lt;int&gt;&nbsp;performNMS(const&nbsp;std::vector&lt;cv::Rect&gt;&amp; boxes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const&nbsp;std::vector&lt;float&gt;&amp; confidences)&nbsp;{<br>&nbsp; &nbsp;&nbsp;std::vector&lt;int&gt; indices;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ OpenCV\u4f18\u5316\u7684NMS\u5b9e\u73b0<\/em><br>&nbsp; &nbsp; cv::dnn::NMSBoxes(<br>&nbsp; &nbsp; &nbsp; &nbsp; boxes, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ \u8fb9\u754c\u6846\u5217\u8868<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; confidences, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u7f6e\u4fe1\u5ea6\u5217\u8868<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; CONFIDENCE_THRESHOLD, &nbsp; &nbsp;<em>\/\/ \u7f6e\u4fe1\u5ea6\u9608\u503c (0.5)<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; NMS_THRESHOLD, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ IoU\u9608\u503c (0.45)<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; indices, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ \u8f93\u51fa\uff1a\u4fdd\u7559\u7684\u7d22\u5f15<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;1.0f, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ eta\u53c2\u6570\uff08\u81ea\u9002\u5e94\u9608\u503c\uff09<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<em>\/\/ top_k\uff080=\u4e0d\u9650\u5236\uff09<\/em><br>&nbsp; &nbsp; );<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;return&nbsp;indices;<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. \u5750\u6807\u53d8\u6362\u4e0e\u53ef\u89c6\u5316<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;renderPoseResults(cv::Mat&amp; result_frame,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;cv::Rect&gt;&amp; boxes,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;float&gt;&amp; confidences,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;cv::Mat&gt;&amp; keypoints_data,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;const&nbsp;std::vector&lt;int&gt;&amp; indices,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;x_factor,&nbsp;float&nbsp;y_factor)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;for(int&nbsp;idx : indices) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u7ed8\u5236\u68c0\u6d4b\u6846<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; drawBoundingBox(result_frame, boxes&#91;idx], confidences&#91;idx]);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5904\u7406\u5173\u952e\u70b9\u53ef\u89c6\u5316<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Mat keypoints_raw = keypoints_data&#91;idx];<br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Mat keypoints = keypoints_raw.reshape(1,&nbsp;17); &nbsp;<em>\/\/ &#91;17, 3]<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5750\u6807\u53d8\u6362<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Mat scaled_keypoints = transformKeypoints(keypoints, x_factor, y_factor);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u7ed8\u5236\u59ff\u6001\u9aa8\u67b6<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; drawPoseSkeleton(result_frame, scaled_keypoints);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u7ed8\u5236\u5173\u952e\u70b9<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; drawKeypoints(result_frame, scaled_keypoints);<br>&nbsp; &nbsp; }<br>}<br><br>cv::Mat&nbsp;transformKeypoints(const&nbsp;cv::Mat&amp; keypoints,&nbsp;float&nbsp;x_factor,&nbsp;float&nbsp;y_factor)&nbsp;{<br>&nbsp; &nbsp;&nbsp;cv::Mat&nbsp;scaled_keypoints(17,&nbsp;3, CV_32F);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;for(int&nbsp;j =&nbsp;0; j &lt;&nbsp;17; ++j) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5750\u6807\u53d8\u6362\uff1a\u6a21\u578b\u7a7a\u95f4 -&gt; \u539f\u56fe\u7a7a\u95f4<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; scaled_keypoints.at&lt;float&gt;(j,&nbsp;0) = keypoints.at&lt;float&gt;(j,&nbsp;0) * x_factor;<br>&nbsp; &nbsp; &nbsp; &nbsp; scaled_keypoints.at&lt;float&gt;(j,&nbsp;1) = keypoints.at&lt;float&gt;(j,&nbsp;1) * y_factor;<br>&nbsp; &nbsp; &nbsp; &nbsp; scaled_keypoints.at&lt;float&gt;(j,&nbsp;2) = keypoints.at&lt;float&gt;(j,&nbsp;2); &nbsp;<em>\/\/ \u53ef\u89c1\u6027\u4e0d\u53d8<\/em><br>&nbsp; &nbsp; }<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;return&nbsp;scaled_keypoints;<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\ud83c\udfaf COCO-17\u5173\u952e\u70b9\u6807\u51c6\u4e0e\u53ef\u89c6\u5316\u7b56\u7565<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. \u5173\u952e\u70b9\u8bed\u4e49\u5b9a\u4e49<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>enum&nbsp;COCOKeypoints {<br>&nbsp; &nbsp; NOSE =&nbsp;0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u9f3b\u5b50 - \u9762\u90e8\u4e2d\u5fc3\u53c2\u8003\u70b9<\/em><br>&nbsp; &nbsp; LEFT_EYE =&nbsp;1, &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u773c - \u89c6\u7ebf\u65b9\u5411\u5224\u65ad<\/em><br>&nbsp; &nbsp; RIGHT_EYE =&nbsp;2, &nbsp; &nbsp; &nbsp;<em>\/\/ \u53f3\u773c - \u89c6\u7ebf\u65b9\u5411\u5224\u65ad<\/em><br>&nbsp; &nbsp; LEFT_EAR =&nbsp;3, &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u8033 - \u5934\u90e8\u59ff\u6001<\/em><br>&nbsp; &nbsp; RIGHT_EAR =&nbsp;4, &nbsp; &nbsp; &nbsp;<em>\/\/ \u53f3\u8033 - \u5934\u90e8\u59ff\u6001<\/em><br>&nbsp; &nbsp; LEFT_SHOULDER =&nbsp;5, &nbsp;<em>\/\/ \u5de6\u80a9 - \u4e0a\u80a2\u8d77\u70b9<\/em><br>&nbsp; &nbsp; RIGHT_SHOULDER =&nbsp;6,&nbsp;<em>\/\/ \u53f3\u80a9 - \u4e0a\u80a2\u8d77\u70b9<\/em><br>&nbsp; &nbsp; LEFT_ELBOW =&nbsp;7, &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u8098 - \u5173\u8282\u70b9<\/em><br>&nbsp; &nbsp; RIGHT_ELBOW =&nbsp;8, &nbsp; &nbsp;<em>\/\/ \u53f3\u8098 - \u5173\u8282\u70b9<\/em><br>&nbsp; &nbsp; LEFT_WRIST =&nbsp;9, &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u8155 - \u624b\u90e8\u8d77\u70b9<\/em><br>&nbsp; &nbsp; RIGHT_WRIST =&nbsp;10, &nbsp;&nbsp;<em>\/\/ \u53f3\u8155 - \u624b\u90e8\u8d77\u70b9<\/em><br>&nbsp; &nbsp; LEFT_HIP =&nbsp;11, &nbsp; &nbsp; &nbsp;<em>\/\/ \u5de6\u9acb - \u4e0b\u80a2\u8d77\u70b9<\/em><br>&nbsp; &nbsp; RIGHT_HIP =&nbsp;12, &nbsp; &nbsp;&nbsp;<em>\/\/ \u53f3\u9acb - \u4e0b\u80a2\u8d77\u70b9<\/em><br>&nbsp; &nbsp; LEFT_KNEE =&nbsp;13, &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u819d - \u5173\u8282\u70b9<\/em><br>&nbsp; &nbsp; RIGHT_KNEE =&nbsp;14, &nbsp; &nbsp;<em>\/\/ \u53f3\u819d - \u5173\u8282\u70b9<\/em><br>&nbsp; &nbsp; LEFT_ANKLE =&nbsp;15, &nbsp; &nbsp;<em>\/\/ \u5de6\u8e1d - \u811a\u90e8\u8d77\u70b9<\/em><br>&nbsp; &nbsp; RIGHT_ANKLE =&nbsp;16&nbsp; &nbsp;&nbsp;<em>\/\/ \u53f3\u8e1d - \u811a\u90e8\u8d77\u70b9<\/em><br>};<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. \u89e3\u5256\u5b66\u9aa8\u67b6\u8fde\u63a5\u62d3\u6251<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;drawPoseSkeleton(cv::Mat&amp; frame,&nbsp;const&nbsp;cv::Mat&amp; keypoints)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u5206\u7ec4\u8fde\u63a5\uff1a\u6309\u8eab\u4f53\u90e8\u4f4d\u7ec4\u7ec7<\/em><br>&nbsp; &nbsp;&nbsp;struct&nbsp;BodyPart&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;std::vector&lt;std::pair&lt;int,&nbsp;int&gt;&gt; connections;<br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Scalar color;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;int&nbsp;thickness;<br>&nbsp; &nbsp; };<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;std::vector&lt;BodyPart&gt; body_parts = {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5934\u90e8\u533a\u57df<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {{{NOSE, LEFT_EYE}, {NOSE, RIGHT_EYE}, {LEFT_EYE, LEFT_EAR}, {RIGHT_EYE, RIGHT_EAR}},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::Scalar(255,&nbsp;0,&nbsp;0),&nbsp;2},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u8eaf\u5e72\u6838\u5fc3<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {{{LEFT_SHOULDER, RIGHT_SHOULDER}, {LEFT_SHOULDER, LEFT_HIP},&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {RIGHT_SHOULDER, RIGHT_HIP}, {LEFT_HIP, RIGHT_HIP}},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::Scalar(0,&nbsp;255,&nbsp;0),&nbsp;3},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u5de6\u4fa7\u80a2\u4f53<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {{{LEFT_SHOULDER, LEFT_ELBOW}, {LEFT_ELBOW, LEFT_WRIST},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {LEFT_HIP, LEFT_KNEE}, {LEFT_KNEE, LEFT_ANKLE}},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::Scalar(0,&nbsp;0,&nbsp;255),&nbsp;2},<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u53f3\u4fa7\u80a2\u4f53<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp; {{{RIGHT_SHOULDER, RIGHT_ELBOW}, {RIGHT_ELBOW, RIGHT_WRIST},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {RIGHT_HIP, RIGHT_KNEE}, {RIGHT_KNEE, RIGHT_ANKLE}},<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::Scalar(255,&nbsp;255,&nbsp;0),&nbsp;2}<br>&nbsp; &nbsp; };<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;constfloat&nbsp;visibility_threshold =&nbsp;0.3f;<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;<em>\/\/ \u6309\u90e8\u4f4d\u5206\u7ec4\u7ed8\u5236<\/em><br>&nbsp; &nbsp;&nbsp;for(constauto&amp; part : body_parts) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for(constauto&amp; connection : part.connections) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; drawConnection(frame, keypoints, connection.first, connection.second,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;part.color, part.thickness, visibility_threshold);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. \u81ea\u9002\u5e94\u53ef\u89c6\u5316\u4f18\u5316<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>void&nbsp;drawConnection(cv::Mat&amp; frame,&nbsp;const&nbsp;cv::Mat&amp; keypoints,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int&nbsp;pt1_idx,&nbsp;int&nbsp;pt2_idx,&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cv::Scalar color,&nbsp;int&nbsp;thickness,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;float&nbsp;visibility_threshold)&nbsp;{<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;float&nbsp;vis1 = keypoints.at&lt;float&gt;(pt1_idx,&nbsp;2);<br>&nbsp; &nbsp;&nbsp;float&nbsp;vis2 = keypoints.at&lt;float&gt;(pt2_idx,&nbsp;2);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;&nbsp;if(vis1 &gt; visibility_threshold &amp;&amp; vis2 &gt; visibility_threshold) {<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;cv::Point&nbsp;pt1(static_cast&lt;int&gt;(keypoints.at&lt;float&gt;(pt1_idx,&nbsp;0)),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;static_cast&lt;int&gt;(keypoints.at&lt;float&gt;(pt1_idx,&nbsp;1)));<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;cv::Point&nbsp;pt2(static_cast&lt;int&gt;(keypoints.at&lt;float&gt;(pt2_idx,&nbsp;0)),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;static_cast&lt;int&gt;(keypoints.at&lt;float&gt;(pt2_idx,&nbsp;1)));<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<em>\/\/ \u57fa\u4e8e\u53ef\u89c1\u6027\u8c03\u6574\u989c\u8272\u5f3a\u5ea6<\/em><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;float&nbsp;avg_visibility = (vis1 + vis2) \/&nbsp;2.0f;<br>&nbsp; &nbsp; &nbsp; &nbsp; cv::Scalar adjusted_color = color * avg_visibility;<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; cv::line(frame, pt1, pt2, adjusted_color, thickness, cv::LINE_AA);<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u5957\u7cbe\u5fc3\u8bbe\u8ba1\u7684\u524d\u540e\u5904\u7406\u7cfb\u7edf\uff0c\u6211\u4eec\u5b9e\u73b0\u4e86\u4ece\u539f\u59cb\u56fe\u50cf\u5230\u7cbe\u786e\u59ff\u6001\u53ef\u89c6\u5316\u7684\u5b8c\u6574\u6d41\u7a0b\uff0c\u6bcf\u4e2a\u73af\u8282\u90fd\u7ecf\u8fc7\u6027\u80fd\u548c\u51c6\u786e\u6027\u7684\u53cc\u91cd\u4f18\u5316\u3002<\/p>\n\n\n\n<p><em>\u5982\u679c\u4f60\u89c9\u5f97\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce\u5206\u4eab\u7ed9\u66f4\u591a\u7684\u670b\u53cb\u3002\u6709\u4efb\u4f55\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u8ba8\u8bba\uff01<\/em><\/p>\n\n\n\n<p><strong>\u76f8\u5173\u94fe\u63a5\uff1a<\/strong><\/p>\n\n\n\n<p><em>[<\/em>YOLOv8\u5b98\u65b9\u6587\u6863<em>](<\/em><em>https:\/\/docs.ultralytics.com\/<\/em><em>)<\/em><\/p>\n\n\n\n<p><em>[<\/em>ONNX Runtime\u6587\u6863<em>](<\/em><em>https:\/\/onnxruntime.ai\/<\/em><em>)<\/em><\/p>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u5728\u8fd9\u4e2aAI\u89c6\u89c9\u6280\u672f\u5feb\u901f\u53d1\u5c55\u7684\u65f6\u4ee3\uff0c\u4eba\u4f53\u59ff\u6001\u68c0\u6d4b\u5df2\u7ecf\u6210\u4e3a\u4f53\u611f\u6e38\u620f\u3001\u5065\u8eab\u6307\u5bfc\u3001\u5b89\u9632\u76d1\u63a7\u7b49\u4f17\u591a\u9886\u57df\u7684\u6838\u5fc3\u6280\u672f\u3002\u672c\u6587\u5c06\u5e26\u4f60\u6df1\u5165\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 &#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":[46],"tags":[],"class_list":["post-6714","post","type-post","status-publish","format-standard","hentry","category-yolo"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786.jpg","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-588x1024.jpg","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053841786-588x1024.jpg","id":"image1"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"YOLO","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":394,"next_post_id":6736,"next_post_title":"\u57fa\u4e8e Java \u4e0e YOLOv8 \u5b9e\u73b0\u8868\u683c\u56fe\u50cf\u884c\u5217\u68c0\u6d4b\u7684\u5b8c\u6574\u5b9e\u8df5","previous_post_id":6673,"previous_post_title":"yolo\u7b97\u6cd5\u8fdb\u884c\u8fd0\u52a8\u76d1\u6d4b","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6714","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=6714"}],"version-history":[{"count":1,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6714\/revisions"}],"predecessor-version":[{"id":6716,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6714\/revisions\/6716"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}