{"id":952,"date":"2026-07-11T16:33:16","date_gmt":"2026-07-11T16:33:16","guid":{"rendered":"https:\/\/boochlin.com\/?p=952"},"modified":"2026-09-19T19:17:44","modified_gmt":"2026-09-19T19:17:44","slug":"android-%e7%88%9b%e8%a3%9d%e7%bd%ae%e6%83%b3%e8%b7%91%e4%ba%ba%e8%87%89%e8%be%a8%e8%ad%988-yuv_420_888-%e9%82%84%e8%83%bd%e6%80%8e%e6%a8%a3%e5%8a%a0%e9%80%9f-qfastcv","status":"publish","type":"post","link":"https:\/\/boochlin.com\/?p=952","title":{"rendered":"Android \u721b\u88dd\u7f6e\u60f3\u8dd1\u4eba\u81c9\u8fa8\u8b588 \u2013 YUV_420_888 \u9084\u80fd\u600e\u6a23\u52a0\u901f\uff1aQFastCV"},"content":{"rendered":"<p>\u524d\u5e7e\u7bc7\u6211\u5011\u5728\u8ddf LMKD \u640f\u9b25\u3001\u8ddf ART GC \u7b97\u5e33\u3001\u5728 Linux \u6838\u5fc3\u88e1\u65a4\u65a4\u8a08\u8f03\u6bcf\u4e00\u500b Page\u3002<\/p>\n<p>\u4eca\u5929\u63db\u500b\u5168\u65b0\u6230\u5834\uff1a\u5728\u5f71\u50cf\u8cc7\u6599\u9001\u9032 AI \u6a21\u578b\u4e4b\u524d\uff0c\u5c07\u76f8\u6a5f\u786c\u9ad4\u5410\u51fa\u4f86\u7684 <code>YUV_420_888<\/code> \u8f49\u63db\u70ba\u6a21\u578b\u6240\u9700\u7684\u683c\u5f0f\u3002\u9019\u662f\u6574\u500b\u5f71\u50cf\u6d41\u6c34\u7dda\u4e2d\u6700\u5bb9\u6613\u88ab\u83dc\u9ce5\u5ffd\u8996\u3001\u537b\u80fd\u62fc\u51fa\u5341\u500d\u52a0\u901f\u7a7a\u9593\u7684\u5175\u5bb6\u5fc5\u722d\u4e4b\u5730\u3002<\/p>\n<p>\u5728\u6211\u5011\u9019\u53f0 4 \u6838\u5fc3 1.3GHz \u5f31\u96de CPU \u7684\u7834\u677f\u5b50\u4e0a\uff0c\u5149\u662f\u505a\u4e00\u6b21 YUV \u683c\u5f0f\u8f49\u63db\u8207\u53bb Padding\uff0c\u7d14 Java \u5beb\u6cd5\u5c31\u786c\u751f\u751f\u5403\u6389\u4e86\u5c07\u8fd1 15ms\u3002<\/p>\n<p>30fps \u7684\u5f71\u50cf\u4e32\u6d41\uff0c\u7559\u7d66\u6bcf\u4e00\u5e40\u7684\u7e3d\u6642\u9593\u9810\u7b97\u53ea\u6709 33.3ms\u3002\u4e00\u500b\u5c0f\u5c0f\u7684\u683c\u5f0f\u8f49\u63db\u5403\u6389 15ms\uff0c\u76f8\u7576\u65bc\u76f4\u63a5\u63ee\u970d\u6389\u534a\u5e40\u7684\u7b97\u529b\u9810\u7b97\u3002<\/p>\n<p>\u76f4\u5230\u6211\u6df1\u5165\u7ffb\u958b\u76f8\u6a5f\u786c\u9ad4\u70ba\u4ec0\u9ebc\u8981\u5410\u51fa\u9019\u7a2e\u602a\u7570\u683c\u5f0f\uff0c\u624d\u767c\u73fe\u9019\u4e0d\u662f Android \u7684\u934b\uff0c\u800c\u662f\u5e7e\u5341\u5e74\u524d\u77fd\u6676\u7247\u8a2d\u8a08\u5e2b\u7559\u4e0b\u7684\u6b77\u53f2\u696d\u969c\u3002<\/p>\n<hr>\n<h2>\u4eba\u773c\u5c0d\u984f\u8272\u662f\u778e\u5b50\uff1aYUV420 \u7684\u751f\u7406\u5b78\u751c\u871c\u9ede<\/h2>\n<p><code>YUV_420_888<\/code> \u9019\u500b\u683c\u5f0f\u7684\u8a95\u751f\uff0c\u6839\u6e90\u5728\u65bc\u4eba\u985e\u773c\u775b\u6f14\u5316\u4e0a\u7684\u5148\u5929\u7f3a\u9677\u3002<\/p>\n<p>\u4eba\u773c\u4e2d\u8ca0\u8cac\u611f\u77e5\u4eae\u5ea6\u7684\u8996\u687f\u7d30\u80de\u9ad8\u9054 1.2 \u5104\u500b\uff0c\u800c\u8ca0\u8cac\u611f\u77e5\u984f\u8272\u7684\u8996\u9310\u7d30\u80de\u53ea\u6709\u53ef\u6190\u7684 600 \u842c\u500b\u3002\u4eba\u985e\u5927\u8166\u5c0d\u300c\u660e\u6697\u908a\u754c\u300d\u6975\u5ea6\u654f\u611f\uff0c\u4f46\u5c0d\u300c\u8272\u5f69\u7d30\u7bc0\u300d\u6839\u672c\u662f\u500b\u534a\u778e\u5b50\u3002<\/p>\n<p>\u5de5\u7a0b\u5e2b\u6293\u4f4f\u9019\u500b\u751f\u7406\u6f0f\u6d1e\u767c\u660e\u4e86 YUV\uff1a<\/p>\n<ul>\n<li><strong>Y\uff08Luma \u4eae\u5ea6\uff09<\/strong>\uff1a\u6bcf\u500b\u50cf\u7d20\u90fd\u5b8c\u6574\u4fdd\u7559\uff0c\u4e00\u500b\u90fd\u4e0d\u80fd\u5c11\u3002<\/li>\n<li><strong>U\u3001V\uff08Chroma \u8272\u5ea6\uff09<\/strong>\uff1a\u4eba\u773c\u770b\u4e0d\u51fa\u7d30\u7bc0\uff0c\u90a3\u5c31\u8b93 2&#215;2 \u7684\u56db\u500b\u50cf\u7d20\u5171\u7528\u4e00\u7d44 U \u548c V\u3002<\/li>\n<\/ul>\n<p>\u5c0f\u5b78\u7b97\u8853\u5c0d\u6bd4\uff1a<\/p>\n<blockquote>\n<p>RGB \u683c\u5f0f\uff1a4 \u500b\u50cf\u7d20 = 4 x 3 = 12 bytes<br \/>\nYUV420 \u683c\u5f0f\uff1a4 \u500b\u50cf\u7d20 = 4 (Y) + 1 (U) + 1 (V) = 6 bytes<br \/>\n\u983b\u5bec\u7bc0\u7701\uff1a(12 &#8211; 6) \/ 12 = 50%<\/p>\n<\/blockquote>\n<p>\u8a18\u61b6\u9ad4\u983b\u5bec\u8207\u8cc7\u6599\u50b3\u8f38\u91cf\u76f4\u63a5\u8170\u65ac\uff0c\u800c\u8089\u773c\u5e7e\u4e4e\u770b\u4e0d\u51fa\u4efb\u4f55\u756b\u8cea\u5dee\u7570\u3002\u9019\u5c31\u662f\u70ba\u4ec0\u9ebc\u5168\u4e16\u754c\u6240\u6709\u76f8\u6a5f\u611f\u6e2c\u5668\u8207\u8996\u8a0a\u6676\u7247\uff0c\u9810\u8a2d\u5168\u90e8\u4f7f\u7528 YUV420\u3002<\/p>\n<hr>\n<h2>UV \u70ba\u4ec0\u9ebc\u662f\u4ea4\u932f\u5b58\u7684\uff1f\uff08Semi-Planar NV21 \u7684\u786c\u9ad4\u6b77\u53f2\uff09<\/h2>\n<p>\u7576\u4f60\u5f9e Android Camera2 \u53d6\u5f97 YUV \u8cc7\u6599\u6642\uff0cUV \u8a18\u61b6\u9ad4\u4f48\u5c40\u9577\u6210\u9019\u6a23\uff1a<\/p>\n<pre><code class=\"hljs language-plaintext\">Y \u5e73\u9762:  [Y0 Y1 Y2 Y3 Y4 Y5 ...]\nUV \u5e73\u9762: [U0 V0 U1 V1 U2 V2 ...]  &lt;-- U \u548c V \u4ea4\u932f\u64e0\u5728\u4e00\u8d77<\/code><\/pre>\n<p>U \u548c V \u4ea4\u932f\u5b58\u653e\u5728\u540c\u4e00\u500b Buffer \u4e2d\uff0c\u9019\u53eb <strong>Semi-Planar\uff08NV21 \/ NV12\uff09<\/strong>\u3002<\/p>\n<p>\u70ba\u4ec0\u9ebc\u4e0d\u4e7e\u8106\u628a U \u548c V \u5b8c\u5168\u5206\u958b\u5b58\u653e\u6210\u7368\u7acb\u7684\u5169\u500b\u5e73\u9762\uff08Planar \u683c\u5f0f\uff0c\u5982 I420\uff09\uff1f<strong>\u56e0\u70ba\u76f8\u6a5f ISP \u786c\u9ad4\u5de5\u7a0b\u5e2b\u8981\u7701\u6676\u7247\u6210\u672c\u3002<\/strong><\/p>\n<p>\u76f8\u6a5f\u5167\u90e8\u7684 ISP\uff08\u5f71\u50cf\u8a0a\u865f\u8655\u7406\u5668\uff09\u900f\u904e DMA \u5f15\u64ce\u5c07\u50cf\u7d20\u642c\u79fb\u5230\u8a18\u61b6\u9ad4\uff0c\u5176\u904b\u4f5c\u65b9\u5f0f\u50cf\u6383\u63cf\u6a5f\u4e00\u6a23\u5f9e\u7b2c 0 \u884c\u9010\u884c\u6383\u5230\u6700\u5f8c\u4e00\u884c\u3002\u7576 ISP \u6383\u5b8c\u6bcf\u5169\u884c Y \u6642\uff0c\u5c0d\u61c9\u7684\u4e00\u7d44 U \u548c V \u525b\u597d\u8a08\u7b97\u5b8c\u6210\uff1a<\/p>\n<ul>\n<li><strong>\u9078 Semi-Planar<\/strong>\uff1aU \u548c V \u7b97\u51fa\u4f86\u5c31\u76f4\u63a5\u4ea4\u932f\u5beb\u5165\u8a18\u61b6\u9ad4\uff0c\u96fb\u8def\u8a2d\u8a08\u6700\u7c21\u55ae\u3001\u6676\u7247\u9762\u7a4d\u6700\u5c0f\u3001\u6210\u672c\u6700\u4f4e\u3002<\/li>\n<li><strong>\u9078 Planar<\/strong>\uff1a\u5fc5\u9808\u5728\u6676\u7247\u5167\u589e\u52a0\u984d\u5916\u7684 SRAM \u5feb\u53d6\uff0c\u628a U \u5168\u90e8\u66ab\u5b58\u8d77\u4f86\uff0c\u7b49\u6574\u5f35\u5716\u7684 Y \u5beb\u5b8c\u5f8c\u518d\u5206\u6279\u5beb\u5165 U \u8207 V\u3002\u9019\u9700\u8981\u66f4\u8907\u96dc\u7684\u786c\u9ad4\u6392\u7a0b\u5668\uff0c\u6676\u7247\u6210\u672c\u76f4\u7dda\u4e0a\u5347\u3002<\/li>\n<\/ul>\n<p>\u5e7e\u5341\u5e74\u524d\u5de5\u7a0b\u5e2b\u5728\u6210\u672c\u58d3\u529b\u4e0b\u7684\u59a5\u5354\uff0c\u5c31\u9019\u6a23\u8b8a\u6210\u4e86\u6211\u5011\u4eca\u5929\u5fc5\u9808\u9762\u5c0d\u7684\u6a19\u6e96\u3002<\/p>\n<hr>\n<h2>\u70ba\u4ec0\u9ebc\u6bcf\u884c\u672b\u5c3e\u6709\u591a\u9918\u7684\u5783\u573e\uff1f\uff08Row Stride \u7684 64-byte \u5c0d\u9f4a\uff09<\/h2>\n<p>\u5728\u6211\u5011\u7684\u9580\u7981\u6a5f\u4e2d\uff0c\u7576 RGB \u76f8\u6a5f\u5207\u63db\u5230 800&#215;600 \u89e3\u6790\u5ea6\u6642\uff0c\u4f60\u6703\u767c\u73fe\u4e00\u500b\u8a6d\u7570\u73fe\u8c61\uff1a\u6bcf\u884c\u6709\u6548\u50cf\u7d20\u660e\u660e\u53ea\u6709 800 bytes\uff0c\u4f46\u5e95\u5c64 Buffer \u7684\u6bcf\u884c\u8de8\u5ea6\uff08Row Stride\uff09\u537b\u662f <strong>832 bytes<\/strong>\u3002<\/p>\n<p>\u591a\u51fa\u4f86\u7684 32 bytes \u5168\u662f\u7121\u610f\u7fa9\u7684 Padding \u5783\u573e\uff1a<\/p>\n<pre><code class=\"hljs language-plaintext\">\u884c 0: [800 bytes \u6709\u6548 Y \u8cc7\u6599] [32 bytes \u5783\u573e Padding]\n\u884c 1: [800 bytes \u6709\u6548 Y \u8cc7\u6599] [32 bytes \u5783\u573e Padding]\n... \u5171 600 \u884c<\/code><\/pre>\n<p>\u9019\u662f\u56e0\u70ba\u9ad8\u901a SoC \u7684 CPU \u8207\u8a18\u61b6\u9ad4\u532f\u6d41\u6392\uff08System Bus\uff09\u4ee5 64 bytes \u70ba\u4e00\u500b\u50b3\u8f38\u5340\u584a\uff08Burst Transfer\uff09\uff0c\u4e14\u8981\u6c42\u6bcf\u6b21 DMA \u50b3\u8f38\u7684\u8d77\u59cb\u4f4d\u5740\u5fc5\u9808\u662f 64 \u7684\u6574\u6578\u500d\u3002<\/p>\n<p>800 \u4e0d\u662f 64 \u7684\u500d\u6578\uff08800 \/ 64 = 12.5\uff09\u3002\u70ba\u4e86\u8b93 DMA \u50b3\u8f38\u6548\u7387\u9054\u5230\u786c\u9ad4\u6700\u9ad8\u5cf0\u503c\uff0cISP \u6703\u81ea\u52d5\u5728\u6bcf\u884c\u672b\u5c3e\u88dc\u9f4a 32 bytes \u5783\u573e\uff0c\u6e4a\u6210 832\uff08832 \/ 64 = 13\uff0c\u5b8c\u7f8e\u6574\u9664\uff09\u3002<\/p>\n<p>\u786c\u9ad4\u723d\u4e86\uff0c\u4ee3\u50f9\u662f\u8edf\u9ad4\u5de5\u7a0b\u5e2b\u5fc5\u9808\u5728\u8cc7\u6599\u9935\u9032 AI \u6a21\u578b\u524d\uff0c\u624b\u52d5\u628a\u6bcf\u884c\u672b\u5c3e\u7684 32 bytes \u5783\u573e\u6311\u51fa\u4f86\u6254\u6389\u3002<\/p>\n<hr>\n<h2>\u539f\u672c\u600e\u9ebc\u505a\u7684\uff1a\u7d14 Java \u82e6\u5de5\uff0824 \u842c\u6b21\u908a\u754c\u6aa2\u67e5\uff09<\/h2>\n<p>\u5728\u5c0e\u5165\u786c\u9ad4\u52a0\u901f\u524d\uff0c\u6211\u5011\u5728 <code>CameraRgbHelper.java<\/code> \u4e2d\u7684\u5099\u7528\u8def\u5f91\u5beb\u4e86\u6a19\u6e96\u7684 Java \u8f49\u63db\u8ff4\u5708\uff1a<\/p>\n<pre><code class=\"hljs language-java\"><span class=\"hljs-comment\">\/\/ CameraRgbHelper.java<\/span>\n<span class=\"hljs-keyword\">private<\/span> <span class=\"hljs-type\">void<\/span> <span class=\"hljs-title function_\">yuv420888toNV21<\/span><span class=\"hljs-params\">(Image image, <span class=\"hljs-type\">byte<\/span>[] nv21)<\/span> {\n    <span class=\"hljs-comment\">\/\/ ... \u8655\u7406 Y \u5e73\u9762 Padding ...<\/span>\n\n    <span class=\"hljs-comment\">\/\/ \u8655\u7406 UV \u4ea4\u932f\u63d0\u53d6<\/span>\n    <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-type\">int<\/span> <span class=\"hljs-variable\">row<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">0<\/span>; row &lt; height \/ <span class=\"hljs-number\">2<\/span>; row++) {\n        <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-type\">int<\/span> <span class=\"hljs-variable\">col<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">0<\/span>; col &lt; width \/ <span class=\"hljs-number\">2<\/span>; col++) {\n            <span class=\"hljs-type\">int<\/span> <span class=\"hljs-variable\">vuPos<\/span> <span class=\"hljs-operator\">=<\/span> col * pixelStride + row * rowStride;\n            nv21[pos++] = vBuffer.get(vuPos); <span class=\"hljs-comment\">\/\/ \u64bf\u4e00\u500b V<\/span>\n            nv21[pos++] = uBuffer.get(vuPos); <span class=\"hljs-comment\">\/\/ \u64bf\u4e00\u500b U<\/span>\n        }\n    }\n}<\/code><\/pre>\n<p>\u5728 800&#215;600 \u89e3\u6790\u5ea6\u4e0b\uff0cUV \u5e73\u9762\u7684\u5c3a\u5bf8\u662f 400&#215;300\uff1a<\/p>\n<ul>\n<li>\u96d9\u91cd\u8ff4\u5708\u7e3d\u5171\u8981\u57f7\u884c 400 x 300 = 120,000 \u6b21\u3002<\/li>\n<li>\u7e3d\u8a08\u57f7\u884c <strong>24 \u842c\u6b21\u9663\u5217\u5b58\u53d6\u8207 <code>ByteBuffer.get()<\/code><\/strong>\u3002<\/li>\n<\/ul>\n<p>Java \u865b\u64ec\u6a5f\u5728\u6bcf\u6b21\u547c\u53eb <code>get()<\/code> \u6642\uff0c\u5e95\u5c64\u90fd\u6703\u5f37\u5236\u505a\u4e00\u6b21\u8a18\u61b6\u9ad4\u908a\u754c\u6aa2\u67e5\uff08Bounds Checking\uff09\u3002\u5728 1.3GHz \u7684\u5f31 CPU \u4e0a\uff0c\u9019 24 \u842c\u6b21\u5b89\u5168\u78ba\u8a8d\u76f4\u63a5\u5403\u6389\u4e86 <strong>5 ~ 15ms<\/strong>\uff01\u5728 30fps\uff08\u6bcf\u5e40\u50c5 33.3ms\uff09\u7684\u6d41\u6c34\u7dda\u4e2d\uff0c\u5149\u683c\u5f0f\u8f49\u63db\u5c31\u5403\u6389\u5c07\u8fd1\u4e00\u534a\u7684\u7b97\u529b\u9810\u7b97\u3002<\/p>\n<hr>\n<h2>\u63db\u6210 QFastCV\uff1a\u4e00\u884c\u641e\u5b9a\uff08&lt; 1ms\uff09<\/h2>\n<p>\u70ba\u4e86\u89e3\u6c7a\u9019\u500b\u74f6\u9838\uff0c\u6211\u5011\u5728\u76f8\u6a5f\u6d41\u6c34\u7dda\u4e2d\u639b\u8f09\u9ad8\u901a\u539f\u751f <strong>QFastCV<\/strong> \u5eab\uff1a<\/p>\n<pre><code class=\"hljs language-java\"><span class=\"hljs-comment\">\/\/ CameraRgbHelper.java<\/span>\n<span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-literal\">true<\/span> == useFastCv) {\n    <span class=\"hljs-comment\">\/\/ \u547c\u53eb\u9ad8\u901a Native \u51fd\u5f0f\u5eab\uff1a\u76f4\u63a5\u50b3\u5165 DirectByteBuffer\uff0c\u5be6\u73fe\u771f\u6b63\u7269\u7406\u96f6\u8907\u88fd\uff01<\/span>\n    result = QFastCV.yuv420SPToYuv420PZeroCopy(\n        image.getPlanes()[<span class=\"hljs-number\">0<\/span>].getBuffer(), <span class=\"hljs-comment\">\/\/ DirectByteBuffer<\/span>\n        image.getPlanes()[<span class=\"hljs-number\">1<\/span>].getBuffer(),\n        CAM_RGB_WIDTH, CAM_RGB_HEIGHT,\n        image.getPlanes()[<span class=\"hljs-number\">0<\/span>].getRowStride(), <span class=\"hljs-comment\">\/\/ \u81ea\u52d5\u8655\u7406 Row Stride Padding<\/span>\n        image.getPlanes()[<span class=\"hljs-number\">1<\/span>].getRowStride(),\n        dstDirectBufY, dstDirectBufU, dstDirectBufV\n    );\n}<\/code><\/pre>\n<h3>\u7d42\u6975\u69a8\u6c41\uff1a\u70ba\u4ec0\u9ebc\u4e0d\u8981\u7528 byte[] \u4e2d\u8f49\uff1f<\/h3>\n<p>\u5f88\u591a\u5de5\u7a0b\u5e2b\u5beb JNI\uff0c\u76f4\u89ba\u6703\u5728 Java \u7aef\u5148\u7528 <code>byteBuffer.get(bufferY)<\/code> \u628a\u8cc7\u6599\u8907\u88fd\u9032 Java \u7684 <code>byte[]<\/code> \u9435\u7897\uff0c\u518d\u628a\u9663\u5217\u50b3\u9032 C++\u3002<\/p>\n<p>\u4f46\u5728\u6bcf\u79d2 30 \u5e40\u9ad8\u983b\u4e0b\uff0c\u9019\u5728 Java Heap \u8207 Native \u9593\u591a\u505a\u4e86\u4e00\u6b21\u6574\u5305 <code>memcpy<\/code>\uff08\u6bcf\u79d2\u7121\u8b02\u6d88\u8017 20MB\/s \u8a18\u61b6\u9ad4\u983b\u5bec\uff09\u3002<\/p>\n<p>Camera2 \u7684 <code>Image.Plane.getBuffer()<\/code> \u672c\u8eab\u5c31\u662f <strong><code>DirectByteBuffer<\/code><\/strong>\uff0c\u5176\u5e95\u5c64\u662f\u76f8\u6a5f ISP \u786c\u9ad4 DMA \u76f4\u63a5\u5beb\u5165\u7684 ION \u5806\u5916\u8a18\u61b6\u9ad4\u3002\u6700\u9802\u7d1a\u7684\u5beb\u6cd5\u662f<strong>\u9023 Java byte \u9663\u5217\u90fd\u4e0d\u501f<\/strong>\uff0c\u76f4\u63a5\u5728 JNI C++ \u5c64\u76f4\u53d6\u786c\u9ad4\u7269\u7406\u6307\u6a19\uff1a<\/p>\n<pre><code class=\"hljs language-cpp\"><span class=\"hljs-comment\">\/\/ QFastCV_JNI.cpp\uff1a\u771f\u6b63\u7684\u7269\u7406\u96f6\u8907\u88fd<\/span>\n<span class=\"hljs-function\">JNIEXPORT jboolean JNICALL\n<span class=\"hljs-title\">Java_com_edge_ai_vision_QFastCV_yuv420SPToYuv420PZeroCopy<\/span><span class=\"hljs-params\">(\n    JNIEnv *env, jclass clazz,\n    jobject directBufY, jobject directBufUV,\n    jint width, jint height,\n    jint srcStrideY, jint srcStrideUV,\n    jobject dstBufY, jobject dstBufU, jobject dstBufV)<\/span> <\/span>{\n\n    <span class=\"hljs-comment\">\/\/ \u76f4\u53d6\u76f8\u6a5f\u786c\u9ad4 DMA \u6620\u5c04\u7684\u865b\u64ec\u4f4d\u5740\uff0c0 \u8907\u88fd\u958b\u92b7\uff01<\/span>\n    <span class=\"hljs-type\">uint8_t<\/span>* pSrcY  = (<span class=\"hljs-type\">uint8_t<\/span>*) env-&gt;<span class=\"hljs-built_in\">GetDirectBufferAddress<\/span>(directBufY);\n    <span class=\"hljs-type\">uint8_t<\/span>* pSrcUV = (<span class=\"hljs-type\">uint8_t<\/span>*) env-&gt;<span class=\"hljs-built_in\">GetDirectBufferAddress<\/span>(directBufUV);\n    <span class=\"hljs-type\">uint8_t<\/span>* pDstY  = (<span class=\"hljs-type\">uint8_t<\/span>*) env-&gt;<span class=\"hljs-built_in\">GetDirectBufferAddress<\/span>(dstBufY);\n    <span class=\"hljs-type\">uint8_t<\/span>* pDstU  = (<span class=\"hljs-type\">uint8_t<\/span>*) env-&gt;<span class=\"hljs-built_in\">GetDirectBufferAddress<\/span>(dstBufU);\n    <span class=\"hljs-type\">uint8_t<\/span>* pDstV  = (<span class=\"hljs-type\">uint8_t<\/span>*) env-&gt;<span class=\"hljs-built_in\">GetDirectBufferAddress<\/span>(dstBufV);\n\n    <span class=\"hljs-keyword\">if<\/span> (!pSrcY || !pSrcUV || !pDstY || !pDstU || !pDstV) <span class=\"hljs-keyword\">return<\/span> JNI_FALSE;\n\n    <span class=\"hljs-comment\">\/\/ \u76f4\u63a5\u547c\u53eb\u9ad8\u901a FastCV \u539f\u751f NEON \u5411\u91cf\u6307\u4ee4\u62c6\u5206 UV \u8207\u53bb Padding<\/span>\n    <span class=\"hljs-built_in\">fcvColorYUV420u8ToYUV420Planaru8<\/span>(\n        pSrcY, pSrcUV, width, height,\n        srcStrideY, srcStrideUV,\n        pDstY, pDstU, pDstV, <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">0<\/span>, <span class=\"hljs-number\">0<\/span>\n    );\n    <span class=\"hljs-keyword\">return<\/span> JNI_TRUE;\n}<\/code><\/pre>\n<p>\u8f49\u63db\u8017\u6642\u76f4\u63a5\u5f9e\u539f\u672c Java \u8ff4\u5708\u7684 15ms \u66b4\u8dcc\u5230 <strong>&lt; 0.8ms<\/strong>\uff01<\/p>\n<hr>\n<h2>QFastCV \u6191\u4ec0\u9ebc\u9019\u9ebc\u5feb\uff1f\uff08ARM NEON \u5411\u91cf\u6307\u4ee4\u89e3\u5bc6\uff09<\/h2>\n<p>\u70ba\u4ec0\u9ebc C++ \u547c\u53eb QFastCV \u80fd\u7522\u751f\u8d85\u904e 15 \u500d\u7684\u6548\u80fd\u5dee\u8ddd\uff1f\u6838\u5fc3\u79d8\u5bc6\u5728\u65bc ARM NEON SIMD\uff08\u55ae\u6307\u4ee4\u591a\u8cc7\u6599\u6d41\uff09\u7684\u5c08\u5c6c\u786c\u9ad4\u6307\u4ee4\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u96f6 JVM \u908a\u754c\u6aa2\u67e5<\/strong>\uff1a<br \/>\nC++ \u76f4\u63a5\u64cd\u4f5c\u8a18\u61b6\u9ad4\u539f\u751f\u6307\u6a19\uff0c\u90a3 24 \u842c\u6b21 Java \u865b\u64ec\u6a5f\u7684\u5b89\u5168\u908a\u754c\u6aa2\u67e5\u76f4\u63a5\u6b78\u96f6\u3002<\/p>\n<\/li>\n<li>\n<p><strong>ARM NEON <code>VLD2<\/code> \u5c08\u5c6c\u5411\u91cf\u6307\u4ee4<\/strong>\uff1a<br \/>\nARM \u67b6\u69cb\u5c08\u9580\u70ba\u62c6\u89e3\u4ea4\u932f\u8cc7\u6599\u8a2d\u8a08\u4e86 <strong><code>VLD2<\/code>\uff08Vector Load 2-element structure\uff09<\/strong> \u6307\u4ee4\u3002<br \/>\n\u50b3\u7d71 CPU \u8b80\u53d6 <code>U0 V0 U1 V1 ...<\/code> \u9700\u8981\u9032\u884c 16 \u6b21\u8b80\u53d6\u8207\u4f4d\u79fb\u64cd\u4f5c\uff1b\u800c NEON \u6307\u4ee4 <code>vld2.8 {d0, d1}, [r0]!<\/code> \u53ef\u4ee5\u5728 <strong>1 \u500b\u6642\u8108\u9031\u671f\u5167<\/strong>\uff0c\u76f4\u63a5\u5c07\u8a18\u61b6\u9ad4\u4e2d\u9023\u7e8c\u7684 16 bytes \u62c6\u89e3\u6210\u7368\u7acb\u7684 8 \u500b U \u66ab\u5b58\u5668\uff08d0\uff09\u8207 8 \u500b V \u66ab\u5b58\u5668\uff08d1\uff09\u3002Java \u8981\u8dd1 16 \u6b21\u8ff4\u5708\u7684\u4e8b\uff0cNEON \u9760\u786c\u9ad4\u96fb\u8def\u4e00\u500b\u6307\u4ee4\u641e\u5b9a\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u8a18\u61b6\u9ad4\u9023\u7e8c\u5beb\u5165\uff08Cache Line Friendly\uff09<\/strong>\uff1a<br \/>\n\u62c6\u89e3\u5f8c\u7684 U \u8207 V \u900f\u904e <code>VST1<\/code> \u5411\u91cf\u6307\u4ee4\u9023\u7e8c\u5beb\u5165\u7368\u7acb\u7684 Planar \u7de9\u885d\u5340\uff0c\u5b8c\u7f8e\u5951\u5408 CPU L1\/L2 \u5feb\u53d6\u884c\uff0c\u6700\u5927\u5316\u8a18\u61b6\u9ad4\u5beb\u5165\u541e\u5410\u91cf\u3002<\/p>\n<\/li>\n<\/ol>\n<hr>\n<h2>\u4e09\u8def\u76f8\u6a5f\u8cc7\u6599\u6d41\uff0c\u8ab0\u771f\u6b63\u53d7\u76ca\uff1f<\/h2>\n<p>\u9019\u5957 QFastCV \u52a0\u901f\u53ea\u5c0d RGB \u76f8\u6a5f\u751f\u6548\uff0c\u56e0\u70ba\u53ea\u6709\u5b83\u727d\u6d89\u5230\u8907\u96dc\u7684\u8272\u5f69\u7a7a\u9593\u8f49\u63db\uff1a<\/p>\n<ul>\n<li><strong>RGB \u93e1\u982d\uff08800&#215;600 \/ 640&#215;480 YUV_420_888\uff09<\/strong>\uff1a<br \/>\n\u6700\u5927\u53d7\u76ca\u8005\u3002\u5fb9\u5e95\u89e3\u6c7a Semi-Planar \u62c6\u5206\u8207 Row Stride \u53bb Padding \u7684\u8a08\u7b97\u74f6\u9838\uff0c\u55ae\u5e40\u8017\u6642\u7bc0\u7701 14ms\u3002<\/li>\n<li><strong>Sony IMX516 ToF \u6df1\u5ea6\u93e1\u982d\uff08640&#215;1920 RAW12\uff09<\/strong>\uff1a<br \/>\n\u7121\u95dc\u3002ToF \u8f38\u51fa\u7684\u662f\u7d14 3D \u6df1\u5ea6\u539f\u59cb Raw \u8a0a\u865f\uff0c\u6c92\u6709\u984f\u8272\u8207 UV \u5206\u91cf\uff0c\u76f4\u63a5\u4ee5 <code>byteBuffer.get(buffer)<\/code> \u6574\u5305\u642c\u5165\u8a18\u61b6\u9ad4\u3002<\/li>\n<li><strong>IR \u7d05\u5916\u93e1\u982d\uff08640&#215;480 \u7070\u968e\uff09<\/strong>\uff1a<br \/>\n\u7121\u95dc\u3002IR \u5f71\u50cf\u662f\u7531 ToF Raw \u8a0a\u865f\u7d93 SDK \u89e3\u7b97\u51fa\u7684\u55ae\u901a\u9053 8-bit \u7070\u968e\u5716\uff0c\u6bcf\u500b\u50cf\u7d20\u50c5\u4f54 1 byte\uff0c\u5b8c\u5168\u6c92\u6709 UV \u4ea4\u932f\u554f\u984c\u3002<\/li>\n<\/ul>\n<hr>\n<h2>\u50cf\u7d20\u91cd\u6392\u7b97\u529b\u6975\u9650\u8207\u6536\u5de5<\/h2>\n<p><code>YUV_420_888<\/code>\u3001<code>Semi-Planar<\/code>\u3001<code>Row Stride<\/code>\u2014\u2014\u9019\u4e09\u500b\u6982\u5ff5\u90fd\u662f\u5e7e\u5341\u5e74\u524d\u6676\u7247\u8a2d\u8a08\u5e2b\u5728\u6709\u9650\u7684\u77fd\u6676\u5713\u9762\u7a4d\u8207\u8a18\u61b6\u9ad4\u983b\u5bec\u58d3\u529b\u4e0b\uff0c\u505a\u51fa\u7684\u6700\u52d9\u5be6\u786c\u9ad4\u59a5\u5354\u3002<\/p>\n<p>\u4f60\u4e0d\u7406\u89e3\u5e95\u5c64\u786c\u9ad4\u539f\u7406\uff0c\u5c31\u770b\u4e0d\u61c2\u70ba\u4ec0\u9ebc\u4e00\u500b\u770b\u4f3c\u7c21\u55ae\u7684\u300c\u683c\u5f0f\u8f49\u63db\u300d\u80fd\u5403\u6389 15ms\u3002\u641e\u61c2\u6574\u689d\u56e0\u679c\u93c8\u4e4b\u5f8c\uff0c\u624d\u80fd\u7cbe\u6e96\u4e0b\u5200\u2014\u2014\u7528\u9ad8\u901a QFastCV \u8207 ARM NEON \u5411\u91cf\u6307\u4ee4\uff0c\u5728 1 \u500b\u6642\u8108\u9031\u671f\u5167\u505a\u6389 Java \u8981\u8dd1 16 \u6b21\u8ff4\u5708\u7684\u4e8b\u3002<\/p>\n<p>\u5728\u4f4e\u968e\u908a\u7de3\u88dd\u7f6e\u4e0a\uff0c\u6bcf\u4e00\u500b\u4f60\u4ee5\u70ba\u300c\u61c9\u8a72\u5f88\u5feb\u300d\u7684\u7d30\u7bc0\uff0c\u90fd\u53ef\u80fd\u85cf\u8457\u62d6\u57ae\u6574\u500b\u7cfb\u7d71\u7684\u6697\u7bad\u3002<\/p>\n<p>\u4e0b\u4e00\u7bc7\uff0c\u6211\u5011\u804a\u804a\u4eba\u81c9\u8fa8\u8b58\u6700\u6838\u5fc3\u7684\u6578\u5b78\u6230\u5834\uff1a<strong>5000 \u4eba 1:N \u7279\u5fb5\u6bd4\u5c0d\uff0c\u5982\u4f55\u7528 ARM Compute Library (ACL) \u628a\u6bd4\u5c0d\u6642\u9593\u5f9e 320ms \u66b4\u964d\u5230 3ms\uff01<\/strong><\/p>\n<p>\u611f\u8b1d\u89c0\u770b\uff0c\u6536\u5de5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u5e7e\u7bc7\u6211\u5011\u5728\u8ddf GC \u640f\u9b25\u3001\u8ddf\u8a18\u61b6\u9ad4\u7b97\u5e33\u3001\u8ddf CPU \u7684\u6307\u4ee4\u9031\u671f\u65a4\u65a4\u8a08\u8f03\u3002<\/p>\n<p>\u4eca\u5929\u63db\u500b\u6230\u5834\uff1a\u5728\u8cc7\u6599\u9032 AI \u4e4b\u524d\uff0cYUV_420_888 to RGB \u662f\u660e\u986f\u53ef\u4ee5\u62fc\u770b\u770b\u52a0\u901f\u7684\u90e8\u5206\u3002<\/p>\n<p>\u5728\u6211\u5011\u7684\u7834\u677f\u5b50\u4e0a\uff0c\u5b83\u5403\u6389\u4e86\u5c07\u8fd1\u4e00\u5e40\u7684\u9810\u7b97\u3002\u76f4\u5230\u6211\u82b1\u4e86\u9ede\u6642\u9593\u53bb\u7406\u89e3\u70ba\u4ec0\u9ebc\u76f8\u6a5f\u8981\u5410\u90a3\u7a2e\u683c\u5f0f\u7684\u8cc7\u6599\uff0c\u624d\u77e5\u9053\u9019\u4e0d\u662f Android \u7684\u934b\uff0c<\/p>\n","protected":false},"author":1,"featured_media":1239,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[166],"tags":[231,238,275,313],"_links":{"self":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/952"}],"collection":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=952"}],"version-history":[{"count":10,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/952\/revisions"}],"predecessor-version":[{"id":1597,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/posts\/952\/revisions\/1597"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=\/wp\/v2\/media\/1239"}],"wp:attachment":[{"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/boochlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}