# 使用 LiteRT 进行目标检测和编码

Source: [https://docs.qualcomm.com/doc/80-70022-50SC/topic/single-camera-stream-with-object-detection-and-encode.html](https://docs.qualcomm.com/doc/80-70022-50SC/topic/single-camera-stream-with-object-detection-and-encode.html)

该用例使用 YOLOv5 LiteRT 模型来识别场景中的目标。该用例在检测到的目标上叠加或合成边界框，然后将此流编码为 H.264 码流。

Note: 对于 Ubuntu Server，需要 `sudo` 访问权限才能将编码流写入 `/etc/media` 文件夹。

## 使用 qtivoverlay 插件应用边框叠加

在目标设备上运行用例：

    gst-launch-1.0 -e qtiqmmfsrc name=camsrc ! video/x-raw,format=NV12_Q08C,width=1280,height=720,framerate=30/1 ! queue ! tee name=split split. ! \
    queue ! qtimetamux name=metamux ! queue ! qtivoverlay ! queue ! v4l2h264enc capture-io-mode=4 output-io-mode=5 ! h264parse ! queue ! mp4mux ! \
    queue ! filesink location=/etc/media/video.mp4 split. ! queue ! qtimlvconverter ! queue ! qtimltflite delegate=external \
    external-delegate-path=libQnnTFLiteDelegate.so external-delegate-options="QNNExternalDelegate,backend_type=htp;" model=/etc/models/yolov5.tflite ! queue ! \
    qtimlpostprocess settings="{\"confidence\": 75.0}" results=10 module=yolov5 labels=/etc/labels/yolov5.json ! text/x-raw ! queue ! metamux.Copy to clipboard

要停止用例，请使用 CTRL + C。

下图显示了用例执行的流程：

1. 从摄像头源传来的视频流中识别目标场景。
2. 使用 overlaylib 将边框叠加在检测到的目标上。
3. 将数据流编码为 H.264 码流。
4. 多路复用 MP4 容器中的数据流并将其存储为 MP4 文件。

Figure : 边框叠加和编码的 pipeline
                
                <!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

<!-- Generated by Microsoft Visio, SVG Export pipeline_boundingbox_overlay_and_encode.svg pipeline_boundingbox_overlay_an -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="12.2917in" height="3.72433in" viewbox="0 0 885 268.152" xml:space="preserve" color-interpolation-filters="sRGB" class="st12"><v:documentproperties v:langid="1033" v:viewmarkup="false"></v:documentproperties>
<style>.svg-1 .st1 { fill: #fafafa; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st2 { fill: #d2d7e1; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st3 { fill: #007884; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st4 { fill: #ffffff; font-family: Roboto; font-size: 1.00001em }
.svg-1 .st5 { fill: #2a2aea; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st6 { stroke: #000000; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st7 { fill: #000000; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st8 { fill: none }
.svg-1 .st9 { fill: none; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-1 .st10 { fill: #000000; font-family: Roboto; font-size: 0.874992em }
.svg-1 .st11 { fill: #000000; font-family: SimHei; font-size: 0.874992em }
.svg-1 .st12 { fill: none; fill-rule: evenodd; font-size: 12px; overflow: visible; stroke-linecap: square; stroke-miterlimit: 3 }</style>
<g v:mid="0" v:index="1" v:groupcontext="foregroundPage">	<title>pipeline_boundingbox_overlay_an</title>	<v:pageproperties v:drawingscale="1" v:pagescale="1" v:drawingunits="19" v:shadowoffsetx="9" v:shadowoffsety="-9"></v:pageproperties>	<g id="shape3-1" v:mid="3" v:groupcontext="shape" transform="translate(0.375,-0.375366)">		<title>Sheet.3</title>		<path d="M0 262.53 A5.62513 5.62513 -180 0 0 5.63 268.15 L878.62 268.15 A5.62513 5.62513 -180 0 0 884.25 262.53 L884.25					 6.38 A5.62513 5.62513 -180 0 0 878.62 0.75 L5.62 0.75 A5.62513 5.62513 -180 0 0 -0 6.38 L0 262.53 Z" class="st1"></path>	</g>	<g id="shape4-3" v:mid="4" v:groupcontext="shape">		<title>Sheet.4</title>		<path d="M879 0.75 C881.89 0.75 884.25 3.11 884.25 6 L884.25 262.15 C884.25 265.05 881.89 267.4 879 267.4 L6 267.4 C3.11					 267.4 0.75 265.05 0.75 262.15 L0.75 6 C0.75 3.11 3.11 0.75 6 0.75 L879 0.75 ZM879 0 L6 0 C2.69 0 0 2.69					 0 6 L0 262.15 C0 265.47 2.69 268.15 6 268.15 L879 268.15 C882.31 268.15 885 265.47 885 262.15 L885 6 C885					 2.69 882.31 0 879 0 Z" class="st2"></path>	</g>	<g id="shape14-5" v:mid="14" v:groupcontext="shape" transform="translate(15.2729,-215.652)">		<title>Sheet.14</title>		<desc>camsrc</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st3"></path>		<text x="25.07" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>camsrc</text>		</g>	<g id="shape17-8" v:mid="17" v:groupcontext="shape" transform="translate(124.824,-215.652)">		<title>Sheet.17</title>		<desc>tee</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st3"></path>		<text x="36.68" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>tee</text>		</g>	<g id="shape20-11" v:mid="20" v:groupcontext="shape" transform="translate(109.824,-158.021)">		<title>Sheet.20</title>		<desc>qtimlvconverter</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="60" cy="249.402" width="120" height="37.5"></v:textrect>		<path d="M-0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L117 268.15 A3.00007 3.00007 -180 0 0 120 265.15 L120 233.65 A3.00007					 3.00007 -180 0 0 117 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 0 233.65 L0 265.15 Z" class="st5"></path>		<text x="18.39" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimlvconverter</text>		</g>	<g id="shape23-14" v:mid="23" v:groupcontext="shape" transform="translate(105.673,-234.402)">		<title>Sheet.23</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape24-17" v:mid="24" v:groupcontext="shape" transform="translate(119.89,-231.784)">		<title>Sheet.24</title>		<path d="M0 268.15 L4.53 265.53 L0 262.92 L0 268.15 Z" class="st7"></path>	</g>	<g id="shape26-19" v:mid="26" v:groupcontext="shape" transform="translate(233.974,-215.652)">		<title>Sheet.26</title>		<desc>qtimetamux</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90.01" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st5"></path>		<text x="12.97" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimetamux</text>		</g>	<g id="shape29-22" v:mid="29" v:groupcontext="shape" transform="translate(214.824,-234.402)">		<title>Sheet.29</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape30-25" v:mid="30" v:groupcontext="shape" transform="translate(229.04,-231.784)">		<title>Sheet.30</title>		<path d="M0 268.15 L4.53 265.53 L0 262.92 L0 268.15 Z" class="st7"></path>	</g>	<g id="shape32-27" v:mid="32" v:groupcontext="shape" transform="translate(343.125,-215.652)">		<title>Sheet.32</title>		<desc>qtioverlay</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90.01" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st5"></path>		<text x="19.08" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtioverlay</text>		</g>	<g id="shape35-30" v:mid="35" v:groupcontext="shape" transform="translate(323.974,-234.402)">		<title>Sheet.35</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape36-33" v:mid="36" v:groupcontext="shape" transform="translate(338.191,-231.784)">		<title>Sheet.36</title>		<path d="M0 268.15 L4.53 265.53 L0 262.92 L0 268.15 Z" class="st7"></path>	</g>	<g id="shape38-35" v:mid="38" v:groupcontext="shape" transform="translate(452.276,-215.652)">		<title>Sheet.38</title>		<desc>v4l2h264enc</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st3"></path>		<text x="10.86" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>v4l2h264enc</text>		</g>	<g id="shape41-38" v:mid="41" v:groupcontext="shape" transform="translate(433.125,-234.402)">		<title>Sheet.41</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape42-41" v:mid="42" v:groupcontext="shape" transform="translate(447.341,-231.784)">		<title>Sheet.42</title>		<path d="M0 268.15 L4.53 265.53 L0 262.92 L0 268.15 Z" class="st7"></path>	</g>	<g id="shape44-43" v:mid="44" v:groupcontext="shape" transform="translate(561.426,-215.652)">		<title>Sheet.44</title>		<desc>h264parse</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90.01" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st3"></path>		<text x="16.65" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>h264parse</text>		</g>	<g id="shape47-46" v:mid="47" v:groupcontext="shape" transform="translate(542.276,-234.402)">		<title>Sheet.47</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape48-49" v:mid="48" v:groupcontext="shape" transform="translate(556.492,-231.784)">		<title>Sheet.48</title>		<path d="M0 268.15 L4.53 265.53 L0 262.92 L0 268.15 Z" class="st7"></path>	</g>	<g id="shape50-51" v:mid="50" v:groupcontext="shape" transform="translate(670.577,-215.652)">		<title>Sheet.50</title>		<desc>mp4mux</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st3"></path>		<text x="21.47" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>mp4mux</text>		</g>	<g id="shape53-54" v:mid="53" v:groupcontext="shape" transform="translate(651.426,-234.402)">		<title>Sheet.53</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape54-57" v:mid="54" v:groupcontext="shape" transform="translate(665.643,-231.784)">		<title>Sheet.54</title>		<path d="M0 268.15 L4.53 265.53 L0 262.92 L0 268.15 Z" class="st7"></path>	</g>	<g id="shape56-59" v:mid="56" v:groupcontext="shape" transform="translate(779.727,-215.652)">		<title>Sheet.56</title>		<desc>filesink</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="45" cy="249.402" width="90.01" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L87 268.15 A3.00007 3.00007 -180 0 0 90 265.15 L90 233.65 A3.00007					 3.00007 -180 0 0 87 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 -0 233.65 L0 265.15 Z" class="st3"></path>		<text x="25.92" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>filesink</text>		</g>	<g id="shape59-62" v:mid="59" v:groupcontext="shape" transform="translate(760.577,-234.402)">		<title>Sheet.59</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape60-65" v:mid="60" v:groupcontext="shape" transform="translate(774.793,-231.784)">		<title>Sheet.60</title>		<path d="M0 268.15 L4.53 265.53 L0 262.92 L0 268.15 Z" class="st7"></path>	</g>	<g id="shape62-67" v:mid="62" v:groupcontext="shape" transform="translate(437.976,52.8462) rotate(90)">		<title>Sheet.62</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape63-70" v:mid="63" v:groupcontext="shape" transform="translate(167.206,-196.556)">		<title>Sheet.63</title>		<path d="M0 263.62 L2.62 268.15 L5.24 263.62 L0 263.62 Z" class="st7"></path>	</g>	<g id="shape65-72" v:mid="65" v:groupcontext="shape" transform="translate(109.824,-100.319)">		<title>Sheet.65</title>		<desc>qtimltflite</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="60" cy="249.402" width="120" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L117 268.15 A3.00007 3.00007 -180 0 0 120 265.15 L120 233.65 A3.00007					 3.00007 -180 0 0 117 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 0 233.65 L0 265.15 Z" class="st5"></path>		<text x="34.36" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimltflite</text>		</g>	<g id="shape68-75" v:mid="68" v:groupcontext="shape" transform="translate(437.976,110.548) rotate(90)">		<title>Sheet.68</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape69-78" v:mid="69" v:groupcontext="shape" transform="translate(167.206,-138.854)">		<title>Sheet.69</title>		<path d="M0 263.62 L2.62 268.15 L5.24 263.62 L0 263.62 Z" class="st7"></path>	</g>	<g id="shape71-80" v:mid="71" v:groupcontext="shape" transform="translate(109.824,-42)">		<title>Sheet.71</title>		<desc>qtimlpostprocess</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="60" cy="249.402" width="120.01" height="37.5"></v:textrect>		<path d="M0 265.15 A3.00007 3.00007 -180 0 0 3 268.15 L117 268.15 A3.00007 3.00007 -180 0 0 120 265.15 L120 233.65 A3.00007					 3.00007 -180 0 0 117 230.65 L3 230.65 A3.00007 3.00007 -180 0 0 0 233.65 L0 265.15 Z" class="st5"></path>		<text x="13.29" y="253" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimlpostprocess</text>		</g>	<g id="shape74-83" v:mid="74" v:groupcontext="shape" transform="translate(437.976,168.867) rotate(90)">		<title>Sheet.74</title>		<path d="M0 268.15 L14.98 268.15" class="st6"></path>	</g>	<g id="shape75-86" v:mid="75" v:groupcontext="shape" transform="translate(167.206,-80.5347)">		<title>Sheet.75</title>		<path d="M0 263.62 L2.62 268.15 L5.24 263.62 L0 263.62 Z" class="st7"></path>	</g>	<g id="shape77-88" v:mid="77" v:groupcontext="shape" transform="translate(229.824,-60.75)">		<title>Sheet.77</title>		<path d="M0 268.15 L49.15 268.15 L49.15 117.36 L0 268.15 Z" class="st8"></path>		<path d="M0 268.15 L49.15 268.15 L49.15 117.36" class="st6"></path>	</g>	<g id="shape78-91" v:mid="78" v:groupcontext="shape" transform="translate(276.357,-210.772)">		<title>Sheet.78</title>		<path d="M5.24 268.15 L2.62 263.62 L0 268.15 L5.24 268.15 Z" class="st7"></path>	</g>	<g id="group79-93" transform="translate(759.603,-14.7814)" v:mid="79" v:groupcontext="group">		<title>Sheet.79</title>		<g id="shape7-94" v:mid="7" v:groupcontext="shape" transform="translate(15.1882,0)">			<title>Sheet.7</title>			<desc>Qualcomm</desc>			<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>			<v:textrect cx="27.5383" cy="261.852" width="55.08" height="12.6"></v:textrect>			<rect x="0" y="255.552" width="55.0767" height="12.6" class="st9"></rect>			<text x="0" y="265" class="st10" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>Qualcomm  </text>			</g>		<g id="shape8-97" v:mid="8" v:groupcontext="shape" transform="translate(-9.99201E-16,-0.218607)">			<title>Sheet.8</title>			<path d="M0 266.65 A1.50003 1.50003 -180 0 0 1.5 268.15 L10.5 268.15 A1.50003 1.50003 -180 0 0 12 266.65 L12 257.65						 A1.50003 1.50003 -180 0 0 10.5 256.15 L1.5 256.15 A1.50003 1.50003 -180 0 0 0 257.65 L0 266.65 Z" class="st5"></path>		</g>		<g id="shape10-99" v:mid="10" v:groupcontext="shape" transform="translate(89.1246,0)">			<title>Sheet.10</title>			<desc>开源</desc>			<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>			<v:textrect cx="10.5" cy="261.852" width="21" height="12.6"></v:textrect>			<rect x="0" y="255.552" width="21" height="12.6" class="st9"></rect>			<text x="0" y="265.35" class="st11" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>开源</text>			</g>		<g id="shape11-102" v:mid="11" v:groupcontext="shape" transform="translate(73.9363,-0.218607)">			<title>Sheet.11</title>			<path d="M0 266.65 A1.50003 1.50003 -180 0 0 1.5 268.15 L10.5 268.15 A1.50003 1.50003 -180 0 0 12 266.65 L12 257.65						 A1.50003 1.50003 -180 0 0 10.5 256.15 L1.5 256.15 A1.50003 1.50003 -180 0 0 0 257.65 L0 266.65 Z" class="st3"></path>		</g>	</g></g>
</svg>

下表列出了 pipeline 执行的顺序处理阶段：

| 处理过程 | 说明 |
| --- | --- |
| [qtiqmmfsrc](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtiqmmfsrc.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_l2f_zgm_vbc"><br>                                    <li class="li">采集视频流（源）并创建源的两个副本：<ul class="ul" id="single-camera-stream-with-object-detection-and-encode__ol_m2f_zgm_vbc"><br>                                            <li class="li">一个视频流被发送到 qtimetamux 插件以保留视频流。</li><br><br>                                            <li class="li">另一个视频流被发送到 ML 推理 pipeline。</li><br><br>                                        </ul><br></li><br><br>                                </ol> |
| **预处理** | **预处理** |
| [qtimlvconverter](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtimlvconverter.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_xsf_q5l_vbc"><br>                                    <li class="li">在其接收端口上接收视频流。</li><br><br>                                    <li class="li">执行预处理：<ul class="ul" id="single-camera-stream-with-object-detection-and-encode__ul_ff2_twl_vbc"><br>                                            <li class="li">颜色转换</li><br><br>                                            <li class="li">缩小/放大</li><br><br>                                            <li class="li">当模型期望浮点值作为输入时对流数据进行标准化</li><br><br>                                        </ul><br></li><br><br>                                    <li class="li">在其发送端口上将视频流转换为张量数据。<p class="p">目标检测模型使用此张量数据进行推理。</p><br></li><br><br>                                </ol> |
| **推理** | **推理** |
| [qtimltflite](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtimltflite.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_ufn_2lm_vbc"><br>                                    <li class="li">加载目标检测模型。</li><br><br>                                    <li class="li">为选择的 delegate 修改图。</li><br><br>                                    <li class="li">在其接收端口上接收张量数据。</li><br><br>                                    <li class="li">运行推理并在其发送端上生成带有目标检测结果的张量数据。</li><br><br>                                </ol> |
| **后处理** | **后处理** |
| qtimlpostprocess | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_ky5_grn_vbc"><br>                                    <li class="li"> 接收来自目标检测模型的推理张量。 </li><br><br>                                    <li class="li">将接收端口上的推理张量转换为视频或文本等格式，稍后可由多媒体插件进行处理。</li><br><br>                                    <li class="li">将阈值应用于所选的结果数。 </li><br><br>                                    <li class="li">加载检测模型的相应模块。 <p class="p">在此用例中，qtimlpostprocess 执行以下操作：<br>                                            </p><ol class="ol" type="a" id="single-camera-stream-with-object-detection-and-encode__ol_jcd_wnk_5bc"><br>                                            <li class="li">加载 YOLOv5 子模块。 </li><br><br>                                            <li class="li">将结果生成为文本结构。</li><br><br>                                            <li class="li">接着发送到 qtimetamux 的接收端口。</li><br><br>                                        </ol><br></li><br><br>                                </ol> |
| [qtimetamux](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtimetamux.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_ll3_x5l_vbc"><br>                                    <li class="li">在接收端口上接收视频流和文本流，以及与视频流相对应的边框结果。</li><br><br>                                    <li class="li">使用接收端口中的视频流内容生成 GST 缓存。</li><br><br>                                    <li class="li">将边框作为 GstVideoRegionOfInterest 从数据接收端添加到其发送端口上的 GST 缓存元数据（元复用）。</li><br><br>                                </ol> |
| [qtivoverlay](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtioverlay.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_wst_y5l_vbc"><br>                                    <li class="li">接收多路复用流。</li><br><br>                                    <li class="li">使用 CL 将边框叠加在 VideoFrame 上。 </li><br><br>                                    <li class="li">在其发送端口上生成带有叠加层的 GST 缓存。</li><br><br>                                </ol> |
| [v4l2h264enc](https://docs.qualcomm.com/doc/80-70022-50SC/topic/v4l2h264enc.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_wsc_bsn_vbc"><br>                                    <li class="li">将参数应用于在接收端口上接收到的视频流的每一帧。</li><br><br>                                    <li class="li">将其编码为码流，并通过其发送端口发送。</li><br><br>                                </ol> |
| h264parse | 向 GStreamer 缓存元数据添加更多码流信息。 |
| mp4mux | 接收这些缓存并创建具有格式规范缓存的容器。 |
| **输出** | **输出** |
| Filesink | 将生成的数据流存储在 /etc/media/video.mp4文件中。 |
| Playback | 从主机拉取 video.mp4并在媒体播放器上播放：<br>`scp root@<IP address of<br>                                        target device>:/etc/media/video.mp4 <destination<br>                                        directory>` |

## 使用 qtivcomposer 混合原始帧与边框遮罩

在目标设备上运行用例：

    gst-launch-1.0 -e \
    qtiqmmfsrc name=camsrc ! video/x-raw,format=NV12_Q08C,width=1280,height=720,framerate=30/1 ! queue ! tee name=split \
    split. ! queue ! qtivcomposer name=mixer ! queue ! video/x-raw,format=NV12,width=1920,height=1080,interlace-mode=progressive,colorimetry=bt601 ! \
    v4l2h264enc capture-io-mode=4 output-io-mode=5 ! h264parse ! queue ! mp4mux ! queue ! filesink location=/etc/media/video.mp4 \
    split. ! queue ! qtimlvconverter ! queue ! qtimltflite delegate=external external-delegate-path=libQnnTFLiteDelegate.so \
    \external-delegate-options="QNNExternalDelegate,backend_type=htp;" model=/etc/models/yolov5.tflite ! queue ! \
    qtimlpostprocess settings="{\"confidence\": 75.0}" results=10 module=yolov5 labels=/etc/labels/yolov5.json ! \
    video/x-raw,format=BGRA,width=640,height=360 ! queue ! mixer.Copy to clipboard

要停止用例，请使用 CTRL + C。

下图显示了用例执行的流程：

1. 从摄像头源传来的视频流中识别目标场景。
2. 使用 qtivcomposer，在检测到的目标和原始视频流上组合边界框。
3. 将此流编码为 H.264 码流。
4. 多路复用 MP4 容器中的数据流并将其存储为 MP4 文件。

Figure : 使用 qtivcomposer 进行边框遮罩和编码的 pipeline
                
                <!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

<!-- Generated by Microsoft Visio, SVG Export pipeline_boundingbox_mask_and_encode_with_qtivcomposer.svg pipeline_boundingbox_mask_and_e -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="15.1152in" height="1.67171in" viewbox="0 0 1088.29 120.363" xml:space="preserve" color-interpolation-filters="sRGB" class="st12"><v:documentproperties v:langid="1033" v:viewmarkup="false"></v:documentproperties>
<style>.svg-2 .st1 { fill: #fafafa; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-2 .st2 { fill: #d2d7e1; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-2 .st3 { fill: #2a2aea; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-2 .st4 { fill: #ffffff; font-family: Roboto; font-size: 1.00001em }
.svg-2 .st5 { stroke: #000000; stroke-linecap: butt; stroke-width: 0.75 }
.svg-2 .st6 { fill: #000000; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-2 .st7 { fill: #007884; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-2 .st8 { fill: none; stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.5 }
.svg-2 .st9 { fill: none; stroke: none; stroke-linecap: butt; stroke-width: 0.75 }
.svg-2 .st10 { fill: #000000; font-family: Roboto; font-size: 0.874992em }
.svg-2 .st11 { fill: #000000; font-family: SimHei; font-size: 0.874992em }
.svg-2 .st12 { fill: none; fill-rule: evenodd; font-size: 12px; overflow: visible; stroke-linecap: square; stroke-miterlimit: 3 }</style>
<g v:mid="0" v:index="1" v:groupcontext="foregroundPage">	<title>pipeline_boundingbox_mask_and_e</title>	<v:pageproperties v:drawingscale="1" v:pagescale="1" v:drawingunits="19" v:shadowoffsetx="9" v:shadowoffsety="-9"></v:pageproperties>	<g id="shape3-1" v:mid="3" v:groupcontext="shape" transform="translate(0.375023,-0.375137)">		<title>Sheet.3</title>		<path d="M0 114.74 A5.62513 5.62513 -180 0 0 5.62 120.36 L1081.92 120.36 A5.62513 5.62513 -180 0 0 1087.54 114.74 L1087.54					 6.38 A5.62513 5.62513 -180 0 0 1081.92 0.75 L5.62 0.75 A5.62513 5.62513 -180 0 0 0 6.38 L0 114.74 Z" class="st1"></path>	</g>	<g id="shape4-3" v:mid="4" v:groupcontext="shape">		<title>Sheet.4</title>		<path d="M1082.29 0.75 C1085.19 0.75 1087.54 3.11 1087.54 6 L1087.54 114.36 C1087.54 117.26 1085.19 119.61 1082.29 119.61					 L6 119.61 C3.11 119.61 0.75 117.26 0.75 114.36 L0.75 6 C0.75 3.11 3.11 0.75 6 0.75 L1082.29 0.75 ZM1082.29					 0 L6 0 C2.69 0 0 2.69 0 6 L0 114.36 C0 117.68 2.69 120.36 6 120.36 L1082.29 120.36 C1085.61 120.36 1088.29					 117.68 1088.29 114.36 L1088.29 6 C1088.29 2.69 1085.61 0 1082.29 0 Z" class="st2"></path>	</g>	<g id="shape13-5" v:mid="13" v:groupcontext="shape" transform="translate(48.007,-41.9347)">		<title>Sheet.13</title>		<desc>qtiqmmfsrc</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="35.282" cy="88.6489" width="70.57" height="63.4282"></v:textrect>		<path d="M0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L67.56 120.36 A3.00007 3.00007 -180 0 0 70.56 117.36 L70.56 59.93					 A3.00007 3.00007 -180 0 0 67.56 56.93 L3 56.93 A3.00007 3.00007 -180 0 0 0 59.93 L0 117.36 Z" class="st3"></path>		<text x="4.18" y="92.25" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtiqmmfsrc</text>		</g>	<g id="shape15-8" v:mid="15" v:groupcontext="shape" transform="translate(118.571,-73.6489)">		<title>Sheet.15</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape16-11" v:mid="16" v:groupcontext="shape" transform="translate(127.966,-70.6571)">		<title>Sheet.16</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape17-13" v:mid="17" v:groupcontext="shape" transform="translate(36.4311,-73.6489)">		<title>Sheet.17</title>		<path d="M0 120.36 L11.58 120.36" class="st5"></path>	</g>	<g id="shape19-16" v:mid="19" v:groupcontext="shape" transform="translate(591.4,-65.7856)">		<title>Sheet.19</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape20-19" v:mid="20" v:groupcontext="shape" transform="translate(600.795,-62.7938)">		<title>Sheet.20</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape21-21" v:mid="21" v:groupcontext="shape" transform="translate(512.115,-42)">		<title>Sheet.21</title>		<desc>qtimetamux</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="39.6427" cy="88.6815" width="79.29" height="63.363"></v:textrect>		<path d="M6 57 L73.29 57 C76.6 57 79.29 59.69 79.29 63 L79.29 115.17 C79.29 118.04 76.96 120.36 74.1 120.36 L6 120.36					 C2.69 120.36 0 117.67 0 114.36 L0 63 C0 59.69 2.69 57 6 57 Z" class="st3"></path>		<text x="7.61" y="92.28" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimetamux</text>		</g>	<g id="shape23-24" v:mid="23" v:groupcontext="shape" transform="translate(133.489,-41.9347)">		<title>Sheet.23</title>		<desc>tee</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="24.0627" cy="88.6489" width="48.13" height="63.4282"></v:textrect>		<path d="M0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L45.13 120.36 A3.00007 3.00007 -180 0 0 48.13 117.36 L48.13 59.93					 A3.00007 3.00007 -180 0 0 45.13 56.93 L3 56.93 A3.00007 3.00007 -180 0 0 -0 59.93 L0 117.36 Z" class="st7"></path>		<text x="15.75" y="92.25" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>tee</text>		</g>	<g id="shape25-27" v:mid="25" v:groupcontext="shape" transform="translate(181.615,-65.7856)">		<title>Sheet.25</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape26-30" v:mid="26" v:groupcontext="shape" transform="translate(191.01,-62.7938)">		<title>Sheet.26</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape29-32" v:mid="29" v:groupcontext="shape" transform="translate(906.718,-42)">		<title>Sheet.29</title>		<desc>qtioverlay</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="39.6427" cy="88.6815" width="79.29" height="63.363"></v:textrect>		<path d="M6 57 L73.29 57 C76.6 57 79.29 59.69 79.29 63 L79.29 115.17 C79.29 118.04 76.96 120.36 74.1 120.36 L6 120.36					 C2.69 120.36 0 117.67 0 114.36 L0 63 C0 59.69 2.69 57 6 57 Z" class="st3"></path>		<text x="13.72" y="92.28" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtioverlay</text>		</g>	<g id="shape32-35" v:mid="32" v:groupcontext="shape" transform="translate(181.615,-96.6407)">		<title>Sheet.32</title>		<path d="M0 120.36 L326.19 120.36" class="st5"></path>	</g>	<g id="shape33-38" v:mid="33" v:groupcontext="shape" transform="translate(506.934,-93.6489)">		<title>Sheet.33</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape35-40" v:mid="35" v:groupcontext="shape" transform="translate(591.864,-96.6407)">		<title>Sheet.35</title>		<path d="M0 120.36 L310.55 120.36" class="st5"></path>	</g>	<g id="shape36-43" v:mid="36" v:groupcontext="shape" transform="translate(901.537,-93.6489)">		<title>Sheet.36</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape37-45" v:mid="37" v:groupcontext="shape" transform="translate(196.191,-42)">		<title>Sheet.37</title>		<desc>qtimlvconverter</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="47.5712" cy="96.5774" width="95.15" height="47.5712"></v:textrect>		<path d="M-0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L92.14 120.36 A3.00007 3.00007 -180 0 0 95.14 117.36 L95.14 75.79					 A3.00007 3.00007 -180 0 0 92.14 72.79 L3 72.79 A3.00007 3.00007 -180 0 0 0 75.79 L0 117.36 Z" class="st3"></path>		<text x="5.97" y="100.18" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimlvconverter</text>		</g>	<g id="shape39-48" v:mid="39" v:groupcontext="shape" transform="translate(291.333,-65.7856)">		<title>Sheet.39</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape40-51" v:mid="40" v:groupcontext="shape" transform="translate(300.728,-62.7938)">		<title>Sheet.40</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape41-53" v:mid="41" v:groupcontext="shape" transform="translate(305.964,-42)">		<title>Sheet.41</title>		<desc>qtimltflite</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="35.6784" cy="96.5774" width="71.36" height="47.5712"></v:textrect>		<path d="M-0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L68.36 120.36 A3.00007 3.00007 -180 0 0 71.36 117.36 L71.36 75.79					 A3.00007 3.00007 -180 0 0 68.36 72.79 L3 72.79 A3.00007 3.00007 -180 0 0 -0 75.79 L0 117.36 Z" class="st3"></path>		<text x="10.04" y="100.18" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimltflite</text>		</g>	<g id="shape43-56" v:mid="43" v:groupcontext="shape" transform="translate(377.321,-65.7856)">		<title>Sheet.43</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape44-59" v:mid="44" v:groupcontext="shape" transform="translate(386.716,-62.7938)">		<title>Sheet.44</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape46-61" v:mid="46" v:groupcontext="shape" transform="translate(497.539,-65.7856)">		<title>Sheet.46</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape47-64" v:mid="47" v:groupcontext="shape" transform="translate(506.934,-62.7938)">		<title>Sheet.47</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape48-66" v:mid="48" v:groupcontext="shape" transform="translate(391.897,-42)">		<title>Sheet.48</title>		<desc>qtimlpostprocess</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="52.8212" cy="96.5774" width="105.65" height="47.5712"></v:textrect>		<path d="M0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L102.64 120.36 A3.00007 3.00007 -180 0 0 105.64 117.36 L105.64					 75.79 A3.00007 3.00007 -180 0 0 102.64 72.79 L3 72.79 A3.00007 3.00007 -180 0 0 -0 75.79 L0 117.36 Z" class="st3"></path>		<text x="6.11" y="100.18" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>qtimlpostprocess</text>		</g>	<g id="shape52-69" v:mid="52" v:groupcontext="shape" transform="translate(605.976,-42)">		<title>Sheet.52</title>		<desc>v4l2h264enc</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="42.7519" cy="96.5774" width="85.51" height="47.5712"></v:textrect>		<path d="M-0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L82.5 120.36 A3.00007 3.00007 -180 0 0 85.5 117.36 L85.5 75.79					 A3.00007 3.00007 -180 0 0 82.5 72.79 L3 72.79 A3.00007 3.00007 -180 0 0 -0 75.79 L0 117.36 Z" class="st7"></path>		<text x="8.61" y="100.18" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>v4l2h264enc</text>		</g>	<g id="shape54-72" v:mid="54" v:groupcontext="shape" transform="translate(691.663,-65.7856)">		<title>Sheet.54</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape55-75" v:mid="55" v:groupcontext="shape" transform="translate(701.058,-62.7938)">		<title>Sheet.55</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape56-77" v:mid="56" v:groupcontext="shape" transform="translate(706.239,-42)">		<title>Sheet.56</title>		<desc>h264parse</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="42.7519" cy="96.5774" width="85.51" height="47.5712"></v:textrect>		<path d="M-0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L82.5 120.36 A3.00007 3.00007 -180 0 0 85.5 117.36 L85.5 75.79					 A3.00007 3.00007 -180 0 0 82.5 72.79 L3 72.79 A3.00007 3.00007 -180 0 0 -0 75.79 L0 117.36 Z" class="st7"></path>		<text x="14.41" y="100.18" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>h264parse</text>		</g>	<g id="shape58-80" v:mid="58" v:groupcontext="shape" transform="translate(791.743,-65.7856)">		<title>Sheet.58</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape59-83" v:mid="59" v:groupcontext="shape" transform="translate(801.138,-62.7938)">		<title>Sheet.59</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape61-85" v:mid="61" v:groupcontext="shape" transform="translate(892.142,-65.7856)">		<title>Sheet.61</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape62-88" v:mid="62" v:groupcontext="shape" transform="translate(901.537,-62.7938)">		<title>Sheet.62</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape63-90" v:mid="63" v:groupcontext="shape" transform="translate(1001.51,-42)">		<title>Sheet.63</title>		<desc>filesink</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="35.8927" cy="88.6815" width="71.79" height="63.363"></v:textrect>		<path d="M6 57 L65.79 57 C69.1 57 71.79 59.69 71.79 63 L71.79 115.17 C71.79 118.04 69.46 120.36 66.6 120.36 L6 120.36					 C2.69 120.36 0 117.67 0 114.36 L0 63 C0 59.69 2.69 57 6 57 Z" class="st7"></path>		<text x="16.82" y="92.28" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>filesink</text>		</g>	<g id="shape66-93" v:mid="66" v:groupcontext="shape" transform="translate(986.004,-65.7856)">		<title>Sheet.66</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape67-96" v:mid="67" v:groupcontext="shape" transform="translate(995.398,-62.7938)">		<title>Sheet.67</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape69-98" v:mid="69" v:groupcontext="shape" transform="translate(986.004,-96.6407)">		<title>Sheet.69</title>		<path d="M0 120.36 L10.27 120.36" class="st5"></path>	</g>	<g id="shape70-101" v:mid="70" v:groupcontext="shape" transform="translate(995.398,-93.6489)">		<title>Sheet.70</title>		<path d="M0 120.36 L5.18 117.37 L0 114.38 L0 120.36 Z" class="st6"></path>	</g>	<g id="shape71-103" v:mid="71" v:groupcontext="shape" transform="translate(806.502,-42)">		<title>Sheet.71</title>		<desc>mp4mux</desc>		<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>		<v:textrect cx="42.7519" cy="96.5774" width="85.51" height="47.5712"></v:textrect>		<path d="M0 117.36 A3.00007 3.00007 -180 0 0 3 120.36 L82.5 120.36 A3.00007 3.00007 -180 0 0 85.5 117.36 L85.5 75.79					 A3.00007 3.00007 -180 0 0 82.5 72.79 L3 72.79 A3.00007 3.00007 -180 0 0 0 75.79 L0 117.36 Z" class="st7"></path>		<text x="19.22" y="100.18" class="st4" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>mp4mux</text>		</g>	<g id="shape75-106" v:mid="75" v:groupcontext="shape" transform="translate(8.29271,-62.4556)">		<title>Sheet.75</title>		<path d="M17.49 97.98 L10.49 97.98 L7 102.17 L2.8 102.17 C1.25 102.17 0 103.43 0 104.97 L0 117.56 C0 119.11 1.25 120.36					 2.8 120.36 L25.18 120.36 C26.73 120.36 27.98 119.11 27.98 117.56 L27.98 104.97 C27.98 103.43 26.73 102.17					 25.18 102.17 L20.99 102.17 L17.49 97.98 Z" class="st8"></path>	</g>	<g id="shape76-108" v:mid="76" v:groupcontext="shape" transform="translate(18.0868,-69.4514)">		<title>Sheet.76</title>		<ellipse cx="4.19746" cy="116.166" rx="4.19746" ry="4.19746" class="st8"></ellipse>	</g>	<g id="group77-110" transform="translate(963.168,-14.7814)" v:mid="77" v:groupcontext="group">		<title>Sheet.77</title>		<g id="shape7-111" v:mid="7" v:groupcontext="shape" transform="translate(15.1883,0)">			<title>Sheet.7</title>			<desc>Qualcomm</desc>			<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>			<v:textrect cx="26.4187" cy="114.063" width="52.84" height="12.6"></v:textrect>			<rect x="0" y="107.763" width="52.8374" height="12.6" class="st9"></rect>			<text x="0" y="117.21" class="st10" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>Qualcomm  </text>			</g>		<g id="shape8-114" v:mid="8" v:groupcontext="shape" transform="translate(6.29496E-14,-0.218619)">			<title>Sheet.8</title>			<path d="M0 118.86 A1.50003 1.50003 -180 0 0 1.5 120.36 L10.5 120.36 A1.50003 1.50003 -180 0 0 12 118.86 L12 109.86						 A1.50003 1.50003 -180 0 0 10.5 108.36 L1.5 108.36 A1.50003 1.50003 -180 0 0 0 109.86 L0 118.86 Z" class="st3"></path>		</g>		<g id="shape10-116" v:mid="10" v:groupcontext="shape" transform="translate(89.1246,0)">			<title>Sheet.10</title>			<desc>开源</desc>			<v:textblock v:margins="rect(0,0,0,0)"></v:textblock>			<v:textrect cx="10.5" cy="114.063" width="21" height="12.6"></v:textrect>			<rect x="0" y="107.763" width="21" height="12.6" class="st9"></rect>			<text x="0" y="117.56" class="st11" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>开源</text>			</g>		<g id="shape11-119" v:mid="11" v:groupcontext="shape" transform="translate(73.9363,-0.218619)">			<title>Sheet.11</title>			<path d="M0 118.86 A1.50003 1.50003 -180 0 0 1.5 120.36 L10.5 120.36 A1.50003 1.50003 -180 0 0 12 118.86 L12 109.86						 A1.50003 1.50003 -180 0 0 10.5 108.36 L1.5 108.36 A1.50003 1.50003 -180 0 0 0 109.86 L0 118.86 Z" class="st7"></path>		</g>	</g></g>
</svg>

下表列出了 pipeline 执行的顺序处理阶段：

| 处理过程 | 说明 |
| --- | --- |
| [qtiqmmfsrc](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtiqmmfsrc.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_wqx_ntn_vbc"><br>                                    <li class="li">采集视频流（源）并创建源的两个副本：<ul class="ul" id="single-camera-stream-with-object-detection-and-encode__ol_xqx_ntn_vbc"><br>                                            <li class="li">一个视频流被发送到 qtimetamux 插件以保留视频流。</li><br><br>                                            <li class="li">另一个视频流被发送到 ML 推理 pipeline。</li><br><br>                                        </ul><br></li><br><br>                                </ol> |
| **预处理** | **预处理** |
| [qtimlvconverter](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtimlvconverter.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_yqx_ntn_vbc"><br>                                    <li class="li">在其接收端口上接收视频流。</li><br><br>                                    <li class="li">执行预处理：<ul class="ul" id="single-camera-stream-with-object-detection-and-encode__ul_zqx_ntn_vbc"><br>                                            <li class="li">颜色转换</li><br><br>                                            <li class="li">缩小/放大</li><br><br>                                            <li class="li">在模型需要浮点值作为输入时，对流数据进行归一化</li><br><br>                                        </ul><br></li><br><br>                                    <li class="li">在其发送端口上将视频流转换为张量数据。<p class="p">目标检测模型使用此张量数据进行推理。</p><br></li><br><br>                                </ol> |
| **推理** | **推理** |
| [qtimltflite](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtimltflite.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_arx_ntn_vbc"><br>                                    <li class="li">加载目标检测模型。</li><br><br>                                    <li class="li">为选择的 delegate 修改图。</li><br><br>                                    <li class="li">在其接收端口上接收张量数据。</li><br><br>                                    <li class="li">运行推理并在其发送端上生成带有目标检测结果的张量数据。</li><br><br>                                </ol> |
| **后处理** | **后处理** |
| qtimlpostprocess | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_brx_ntn_vbc"><br>                                    <li class="li"> 接收来自目标检测模型的推理张量。 </li><br><br>                                    <li class="li">将接收端口上的推理张量转换为视频或文本等格式，稍后可由多媒体插件进行处理。</li><br><br>                                    <li class="li">将阈值应用于所选的结果数。 </li><br><br>                                    <li class="li">加载检测模型的相应模块。 <p class="p">在此用例中，qtimlpostprocess 执行以下操作：<br>                                            </p><ol class="ol" type="a" id="single-camera-stream-with-object-detection-and-encode__ol_crx_ntn_vbc"><br>                                            <li class="li">加载 YOLOv5 子模块。 </li><br><br>                                            <li class="li">生成包含可叠加在目标上的边框的视频帧。</li><br><br>                                            <li class="li">将它们发送至 qtivcomposer 的接收端口。</li><br><br>                                        </ol><br></li><br><br>                                </ol> |
| [qtivcomposer](https://docs.qualcomm.com/doc/80-70022-50SC/topic/qtivcomposer.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_wgh_rtn_vbc"><br>                                    <li class="li">在其接收端上接收原始视频流和带有边框的视频流</li><br><br>                                    <li class="li">在其发送端口上，生成在其接收端口处理的视频流所组成的内容。</li><br><br>                                </ol> |
| [v4l2h264enc](https://docs.qualcomm.com/doc/80-70022-50SC/topic/v4l2h264enc.html) | <ol class="ol" id="single-camera-stream-with-object-detection-and-encode__ol_frx_ntn_vbc"><br>                                    <li class="li">将参数应用于在接收端口上接收到的视频流的每一帧。</li><br><br>                                    <li class="li">将其编码为码流，并通过其发送端口发送。</li><br><br>                                </ol> |
| h264parse | 向 GStreamer 缓存元数据添加更多码流信息。 |
| mp4mux | 接收这些缓存并创建具有格式规范缓存的容器。 |
| **输出** | **输出** |
| Filesink | 将生成的数据流存储在 /etc/media/video.mp4文件中。 |
| Playback | 从主机拉取 video.mp4并在媒体播放器上播放：<br>`scp root@<IP address of<br>                                        target device>:/etc/media/video.mp4 <destination<br>                                        directory>` |

**Parent Topic:** [LiteRT 用例](https://docs.qualcomm.com/doc/80-70022-50SC/topic/tensorflow-lite-use-cases.html)

Last Published: Nov 05, 2025

[Previous Topic
使用 LiteRT 进行目标检测和显示](https://docs.qualcomm.com/bundle/publicresource/80-70022-50SC/topics/single-camera-stream-with-object-detection-and-display.md) [Next Topic
使用 LiteRT 进行图像分割和显示](https://docs.qualcomm.com/bundle/publicresource/80-70022-50SC/topics/single-camera-stream-with-image-segmentation-and-display.md)