# 摄像头检测编码

Source: [https://docs.qualcomm.com/doc/80-70015-50SC/topic/camera-detection-encode.html](https://docs.qualcomm.com/doc/80-70015-50SC/topic/camera-detection-encode.html)

**gst-camera-detection-encode.py** 使用 YOLOv8 TensorFlow Lite 模型从摄像头流中识别场景中的目标对象，并在检测到的目标对象上叠加边框，然后转储结果。

**命令**： `python3 /usr/bin/dec`

## 预期输出

文件路径在 Python 脚本中固定配置为：OUTPUT\_FILE = "/opt/data/det\_recording\_720p.mp4" MODEL\_FILE = "/opt/data/YOLOv8-Detection-Quantized.tflite" LABELS\_FILE = "/opt/data/yolov5m.labels"

| **过程** | **说明** |
| --- | --- |
| **qtiqmmfsrc** | 采集视频流（源）并创建源的 2 个副本：<ul class="ul" id="camera-detection-encode__ul_mhq_hfg_zcc"><br>                                        <li class="li">一个视频流被发送到 <strong class="ph b">qtimetamux</strong> 插件以保留该视频流。</li><br><br>                                        <li class="li">另一个视频流被发送到 ML 推理 pipeline。</li><br><br>                                    </ul> |
| **预处理** | **预处理** |
| **qtimlvconverter** | <ol class="ol" id="camera-detection-encode__ol_crb_jfg_zcc"><br>                                        <li class="li">在其接收设备接插口上接收视频流。</li><br><br>                                        <li class="li">执行预处理：<ol class="ol" type="a" id="camera-detection-encode__ol_s1g_kfg_zcc"><br>                                                <li class="li">色彩转换</li><br><br>                                                <li class="li">缩小/放大</li><br><br>                                                <li class="li">在模型使用浮点值输入时，对流数据进行归一化。</li><br><br>                                            </ol><br></li><br><br>                                        <li class="li">在其源接插口上将视频流转换为张量数据。目标检测模型使用此张量数据进行推理。</li><br><br>                                    </ol> |
| **推理** | **推理** |
| **qtimltflite** | <ol class="ol" id="camera-detection-encode__ol_kft_53r_zcc"><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> |
| **后处理** | **后处理** |
| **qtimlvdetection** | <ol class="ol" id="camera-detection-encode__ol_ekt_rfg_zcc"><br>                                        <li class="li">接收来自目标检测的推理张量。</li><br><br>                                        <li class="li">将接收设备接插口上的推理张量转换为视频或文本等格式，稍后可由多媒体插件进行处理。</li><br><br>                                        <li class="li">将阈值应用于所选的结果数。</li><br><br>                                        <li class="li">加载检测模型的相应模块。</li><br><br>                                    </ol><br><br>                                    <br>在此用例中，**qtimlvdetection** 执行以下操作：<ul class="ul" id="camera-detection-encode__ul_ump_5fg_zcc"><br>                                            <li class="li">加载 YOLOv8 子模块。</li><br><br>                                            <li class="li">将结果生成为文本结构。</li><br><br>                                            <li class="li">接着发送到 <strong class="ph b">qtimetamux</strong> 的接收设备接插口。</li><br><br>                                        </ul> |
| **qtimetamux** | <ol class="ol" id="camera-detection-encode__ol_fcg_xfg_zcc"><br>                                        <li class="li">在接收设备接插口上接收视频流和文本流，以及与视频流相对应的边框结果。</li><br><br>                                        <li class="li">使用接收设备接插口中的视频流内容生成 GST 缓冲区。</li><br><br>                                        <li class="li">将边框作为 GstVideoRegionOfInterest 从数据接收设备接插口添加到其源接插口上的 GST 缓冲区元数据（元多路复用）。</li><br><br>                                    </ol> |
| **qtioverlay** | <ol class="ol" id="camera-detection-encode__ol_zg2_1gg_zcc"><br>                                        <li class="li">接收多路复用流。</li><br><br>                                        <li class="li">使用 CL 将边框叠加在 VideoFrame 上。</li><br><br>                                        <li class="li">在其源接插口上生成带有叠加层的 GST 缓冲区</li><br><br>                                    </ol> |
| **v4l2h264enc** | <ol class="ol" id="camera-detection-encode__ol_cpl_bgg_zcc"><br>                                        <li class="li">将参数应用于在接收设备接插口上接收的视频的每一帧。</li><br><br>                                        <li class="li">将其编码为码流，并通过其源接插口发送。</li><br><br>                                    </ol> |
| **h264parse** | 将与码流对应的其他信息添加到 GStreamer 缓冲区 |
| **mp4mux** | 接收这些缓冲区并创建具有格式规范缓冲区的容器。 |
| **输出** | **输出** |
| Filesink | 将生成的流存储在 `/opt/data/det_recording_720p.mp4 ` 文件中 |
| 播放 | 使用以下命令从主机拉取 `det_recording_720p.mp4` 并进行播放：<br><br><br>                                    <br>在 MediaPlayer 应用程序上运行：`scp root@<IP address of target device>:/opt/data/ <destinationdirectory>` |

**Parent Topic:** [摄像头应用示例](https://docs.qualcomm.com/doc/80-70015-50SC/topic/sample-applications-for-camera.html)

Last Published: Nov 11, 2025

[Previous Topic
摄像头检测显示](https://docs.qualcomm.com/bundle/publicresource/80-70015-50SC/topics/camera-detection-display.md) [Next Topic
解码检测显示](https://docs.qualcomm.com/bundle/publicresource/80-70015-50SC/topics/decode-detection-display.md)