> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 摄像头

IQ8-EVK 通过三个 MIPI CSI 接口支持摄像头传感器连接,支持 C-PHY 和 D-PHY 两种模式。

## 硬件架构

### CSI 接口映射

| CSI 接口 | 模拟开关              | 摄像头连接器 | B2B 连接器          |
| ------ | ----------------- | ------ | ---------------- |
| CSI0   | U45 (TMUX646ZECR) | JCAM0  | JEXP4,引脚 111–120 |
| CSI1   | U42 (TMUX646ZECR) | JCAM1  | JEXP4,引脚 51–60   |
| CSI2   | U44 (TMUX646ZECR) | JCAM2  | JEXP4,引脚 40–49   |

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/iq8275_camera_interface.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=d37bd4d98e138e5f99d753385ed3b378" width="796" height="710" data-path="Ubuntu/images/peripheral-interfaces/iq8275_camera_interface.png" />

### DIP 开关配置

<img src="https://mintcdn.com/qualcomm-prod/tRWO8v_Df_ujnDuD/Ubuntu/images/peripheral-interfaces/Camera_dipswitch.png?fit=max&auto=format&n=tRWO8v_Df_ujnDuD&q=85&s=94f4c6e39c1dae2cae22dd7741525ce1" width="416" height="145" data-path="Ubuntu/images/peripheral-interfaces/Camera_dipswitch.png" />

| 开关    | ON                      | OFF(默认)   |
| ----- | ----------------------- | --------- |
| SW1-5 | CSI0 → GMSL Mezzanine 板 | CSI0 → 主板 |
| SW1-6 | CSI1 → GMSL Mezzanine 板 | CSI1 → 主板 |
| SW1-7 | CSI2 → GMSL Mezzanine 板 | CSI2 → 主板 |

## 支持的 MIPI CSI 摄像头传感器

### ov9282 摄像头传感器

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/ov9282_camera_sensor.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=218e6065fa810b14982347d16280c62d" width="292" height="184" data-path="Ubuntu/images/peripheral-interfaces/ov9282_camera_sensor.png" />

### Arducam imx577 摄像头传感器

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/Rasberrypi_imx577_camera_sensor.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=8008fcdf4e8bbaf3f53d3ee1e8e35188" width="388" height="315" data-path="Ubuntu/images/peripheral-interfaces/Rasberrypi_imx577_camera_sensor.png" />

**Arducam 传感器需要额外的转换板(Arducam 22 针转 Qualcomm 30 针 CSI 适配器)**

<img src="https://mintcdn.com/qualcomm-prod/tRWO8v_Df_ujnDuD/Ubuntu/images/peripheral-interfaces/BoardSide_Flexi_cable_converter_for_RasberryPi_based_Camera.png?fit=max&auto=format&n=tRWO8v_Df_ujnDuD&q=85&s=d1f84333b6e0a9997e222bcf55c6a936" width="656" height="253" data-path="Ubuntu/images/peripheral-interfaces/BoardSide_Flexi_cable_converter_for_RasberryPi_based_Camera.png" />

<img src="https://mintcdn.com/qualcomm-prod/tRWO8v_Df_ujnDuD/Ubuntu/images/peripheral-interfaces/Cameraside_Flexi_cable_converter_for_RasberryPi_based_Camera.png?fit=max&auto=format&n=tRWO8v_Df_ujnDuD&q=85&s=d1728c4cb529f42d6fc9f89c853ecb3c" width="874" height="354" data-path="Ubuntu/images/peripheral-interfaces/Cameraside_Flexi_cable_converter_for_RasberryPi_based_Camera.png" />

**Arducam imx577 传感器 + 22 针排线 + 转换板**

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/arducam_flexcable_frontside.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=2ab9e3f94fabd1127d5a3a9fc0e6a822" width="1164" height="308" data-path="Ubuntu/images/peripheral-interfaces/arducam_flexcable_frontside.png" />

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/arducam_flexcable_backside.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=188d9119bcfa0a3335a39ccf185b32aa" width="1197" height="382" data-path="Ubuntu/images/peripheral-interfaces/arducam_flexcable_backside.png" />

### Arducam imx577 摄像头传感器与 iq8275 的连接

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/rb4_with_arducam_imx577.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=e08065194d482f9f8ab1ac87a1fd384b" width="678" height="873" data-path="Ubuntu/images/peripheral-interfaces/rb4_with_arducam_imx577.png" />

### ov9282 摄像头传感器与 iq8275 的连接

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/rb4_with_arducam_ov9282.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=1c620bd48b2385c8c2d138e1a7db6953" width="668" height="794" data-path="Ubuntu/images/peripheral-interfaces/rb4_with_arducam_ov9282.png" />

## 支持的分辨率

| 分辨率         | 宽高比  | IMX577 | OV9282 |
| ----------- | ---- | ------ | ------ |
| 4000 × 3000 | 4:3  | 是      | 否      |
| 3840 × 2160 | 16:9 | 是      | 否      |
| 1920 × 1080 | 16:9 | 是      | 否      |
| 1280 × 720  | 16:9 | 是      | 是      |
| 1024 × 768  | 4:3  | 是      | 是      |
| 640 × 480   | 4:3  | 是      | 是      |
| 320 × 240   | 4:3  | 是      | 是      |

<Note>
  * IQ-8275 不支持 SHDR、LDC 和 EIS 等高级功能。
  * 没有硬件 JPEG 编码器 — 快照使用在 CPU 上运行的软件编码器。
</Note>

## 摄像头串流

### 单摄像头串流

```bash theme={null}
gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 ! \
  'video/x-raw,format=NV12,width=1280,height=720,framerate=30/1' ! fakesink
```

上述命令以 720p、30 FPS 的配置启动摄像头。
来自摄像头传感器的帧会被 fakesink 丢弃。
如果 gst 流水线状态变为如下所示的"PLAYING",则表明摄像头正在运行。
由于此命令将摄像头帧转储到 fakesink,设备上不会保存任何内容。
如果流水线状态变为 `PLAYING`,则摄像头正在运行。按 `Ctrl+C` 停止。

```bash theme={null}
gbm_create_device(187): Info: backend name is: msm_drm
Setting pipeline to PAUSED ...
Pipeline is live and does not need PREROLL ...
Setting pipeline to PLAYING ...
New clock: GstSystemClock
```

### 视频编码

```bash theme={null}
gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 ! \
  video/x-raw,format=NV12,width=1280,height=720,framerate=30/1,\
  interlace-mode=progressive,colorimetry=bt601 ! \
  v4l2h264enc capture-io-mode=4 output-io-mode=5 \
  extra-controls="controls,video_bitrate=6000000,video_bitrate_mode=0;" ! \
  h264parse ! mp4mux ! filesink location=/home/ubuntu/mux_avc.mp4
```

### 目标检测流水线

首先下载所需的模型和资源:

```bash theme={null}
cd /home/ubuntu
curl -L -O https://raw.githubusercontent.com/quic/sample-apps-for-qualcomm-linux/refs/heads/main/qualcomm-linux/scripts/download_artifacts.sh
sudo chmod +x download_artifacts.sh && sudo ./download_artifacts.sh
```

## 使用离线 IFE 的多摄像头

IQ-8275 具有两个用于实时 Bayer 转 YUV 处理的 IFE。**离线 IFE(Offline IFE)** 功能允许单个 IFE 以离线模式处理两路摄像头,从而实现全部四路摄像头的并发串流。

<img src="https://mintcdn.com/qualcomm-prod/P0rmO3AZfXx7cgqQ/Ubuntu/images/peripheral-interfaces/camera_offline_IFE.png?fit=max&auto=format&n=P0rmO3AZfXx7cgqQ&q=85&s=37704df0003785a5ce4d5ba4730f22df" width="709" height="361" data-path="Ubuntu/images/peripheral-interfaces/camera_offline_IFE.png" />

<Note>
  使用实时 IFE 时,最多两路摄像头可以并发工作。使用离线 IFE 功能,全部四路摄像头都可以并发工作。
</Note>

## 故障排除

<AccordionGroup>
  <Accordion title="摄像头应用无法工作">
    <Steps>
      <Step title="检查摄像头模块连接和 DIP 开关设置" />

      <Step title="重启 cam-server">
        ```bash theme={null}
        systemctl restart cam-server
        ```
      </Step>

      <Step title="运行单路串流测试">
        ```bash theme={null}
        gst-launch-1.0 -e qtiqmmfsrc name=camsrc camera=0 ! \
          video/x-raw,format=NV12,width=1280,height=720,framerate=30/1 ! fakesink
        ```
      </Step>
    </Steps>
  </Accordion>

  <Accordion title="摄像头传感器无法探测">
    ```bash theme={null}
    journalctl -f > /home/ubuntu/log.txt
    ```

    查找:`CAM_INFO: CAM-SENSOR: Probe success, slot:0, ...`

    如果未出现探测成功的信息,请检查排线连接或摄像头模块。
  </Accordion>

  <Accordion title="摄像头无法串流">
    ```bash theme={null}
    sudo su
    echo 3 > /sys/kernel/debug/camera/ife/ife_csid_debug
    dmesg -w > /home/ubuntu/dmesg.txt
    ```
  </Accordion>
</AccordionGroup>

## 资源

| 主题           | 链接                                                                                                                                      |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| 摄像头架构        | [Camera Architecture](https://docs.qualcomm.com/doc/80-70023-17A/topic/camera-architecture.html)                                        |
| 摄像头传感器驱动开发   | [Camera Sensor Driver Development](https://docs.qualcomm.com/doc/80-70023-17A/topic/camera-sensor-driver-development.html)              |
| 自定义摄像头用例和流水线 | [Customize Camera Use Case and Pipeline](https://docs.qualcomm.com/doc/80-70023-17A/topic/customize-camera-use-case-and-pipelines.html) |
