RDK-X5 IMX415 获取帧失败

RDK-X5,系统3.4.1,执行过update+upgrade,运行mipi示例程序01,修改了分辨率:

sunrise@ubuntu:/app/pydev_demo/08_mipi_camera_sample$ grep -rn "open_cam" /app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py 
228:    #cam.open_cam(0,-1,-1,[w,disp_w],[h,disp_h],1080,1920)
229:    cam.open_cam(0,-1,-1,1920,1080)

启动正常,持续运行几分钟后报错退出,错误日志在最后:

sunrise@ubuntu:/app/pydev_demo/08_mipi_camera_sample$ python 01_mipi_camera_yolov5s.py 
2026/07/15 17:33:51.062 !INFO [OpenCamera][0471]hbn module
set camera fps: -1,width: -1,height: -1
Camera 0:
        mipi_host: 0
Camera 1:
        mipi_host: 2
Camera 2:
        mipi_host: 0
Camera 3:
        mipi_host: 0
mipi mclk is not configed.
Searching camera sensor on device: /proc/device-tree/soc/cam/vcon@0 i2c bus: 6 mipi rx phy: 0
WARN: Sensor Name: sc1330t, Expected Chip ID: 0xCA18, Actual Chip ID Read: 0x00
WARN: Sensor Name: irs2875-tof, Expected Chip ID: 0x2875, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs_mono, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs_mono, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5640, Expected Chip ID: 0x5640, Actual Chip ID Read: 0x00
WARN: Sensor Name: f37, Expected Chip ID: 0xF37, Actual Chip ID Read: 0x00
[0] INFO: Found sensor name:imx415-30fps-2lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_30fps_2lane.c
[1] INFO: Found sensor name:imx415-30fps-4lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_30fps_4lane.c
WARN: Sensor Name: sc202cs-1600x1200, Expected Chip ID: 0xEB52, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc202cs-1600x1200, Expected Chip ID: 0xEB52, Actual Chip ID Read: 0x00
WARN: Sensor Name: irs2381c-tof, Expected Chip ID: 0x2381, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs-vc0, Expected Chip ID: 0x35, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs-vc1, Expected Chip ID: 0x35, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx586-30fps-4lane, Expected Chip ID: 0x586, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx586-30fps-4lane, Expected Chip ID: 0x586, Actual Chip ID Read: 0x00
WARN: Sensor Name: os08c10-30fps-2lane, Expected Chip ID: 0x53, Actual Chip ID Read: 0x00
WARN: Sensor Name: os08c10-30fps-2lane, Expected Chip ID: 0x53, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0820std-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0820std-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc1336, Expected Chip ID: 0xCA3F, Actual Chip ID Read: 0x00
WARN: Sensor Name: dummy, Expected Chip ID: 0x00, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-200fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-200fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-120fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-120fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-640x480-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-640x480-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1632x1232-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1632x1232-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1920x1080-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1920x1080-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-15fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-15fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-21fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-21fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-640x480-60fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-1280x960-30fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-1920x1080-30fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-2592x1944-15fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1280x960-120fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1280x960-120fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1920x1080-50fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1920x1080-50fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-2016x1520-21fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-2016x1520-21fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-4000x3000-10fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-4000x3000-10fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov50h40-30fps-4lane, Expected Chip ID: 0x6C, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov50h40-30fps-4lane, Expected Chip ID: 0x6C, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s_2lane, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s_2lane, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
[2] INFO: Found sensor name:imx415-60fps-4lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_60fps_4lane.c
WARN: Sensor Name: sc850sl-30fps, Expected Chip ID: 0x9D1E, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc850sl-30fps, Expected Chip ID: 0x9D1E, Actual Chip ID Read: 0x00
WARN: Sensor Name: shw3g-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: shw3g-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
Auto-selected sensor: imx415-60fps-4lane (Resolution: 3840x2160@60fps)
2026/07/15 17:33:51.398 !INFO [CamInitParam][0341]Setting VSE channel-0: input_width:3840, input_height:2160, dst_w:1920, dst_h:1080
2026/07/15 17:33:51.398 !INFO [CamInitParam][0345]ROI: x:0, y:0, w:3840, h:2160, target_w:1920, target_h:1080
2026/07/15 17:33:51.399 !INFO [CamInitParam][0341]Setting VSE channel-5: input_width:3840, input_height:2160, dst_w:3840, dst_h:2160
2026/07/15 17:33:51.399 !INFO [CamInitParam][0345]ROI: x:0, y:0, w:3840, h:2160, target_w:3840, target_h:2160
2026/07/15 17:33:51.399 !INFO [vp_vin_init][0055]csi0 ignore mclk ex attr, because mclk is not configed at device tree.
================= VP Modules Status ====================
======================== VFLOW =========================
(active)[S0] vin0_C0*(dma)-m2m-isp0_C0-m2m-vse0_C0
========================= SIF ==========================
------------------- flow0 info -------------------
rx_index:0
vc_index:0
ipi_channels:1
width:3840
height:2160
format:0x2b
online_isp:0
ddr_en:0
bufnum:0
emb_en:0
embeded_dependence:0
embeded_width:0
embeded_height:0
size_err_cnt:0
========================= ISP ==========================
------------------- flow0 info -------------------
input_mode:2
sched_mode:0
tile_mode:0
af_mode:0
sensor_mode:0
input_width:3840
input_height:2160
input_format:1
input_bit_width:10
input_crop_x:0
input_crop_y:0
input_crop_w:3840
input_crop_h:2160
ddr_en:1
output_format:2
output_bit_width:8
========================= VSE ==========================
------------------- flow0 info -------------------
input_fps:0/0
input_width:3840
input_height:2160
input_format:2
input_bitwidth:8
dns0 channel: roi [0][0][3840][2160], target [1920][1080], fps [30/30]
ups channel: roi [0][0][0][0], target [0][0], fps [0/30]
========================= VENC =========================
Cannot open file /sys/kernel/debug/vpu/venc.========================= VDEC =========================
Cannot open file /sys/kernel/debug/vpu/vdec.========================= JENC =========================
Cannot open file /sys/kernel/debug/jpu/jenc.======================= Buffer =========================
----------------------------------------------
flowid module cid chn FREE  REQ  PRO  COM USED
----------------------------------------------
0      vin0   0   0     16    0    0    0    0
0      vin0   0   8      0    2    1    0    0

0      isp0   0   0     16    0    0    0    0
0      isp0   0   8      0    3    0    0    0

0      vse0   0   0     16    0    0    0    0
0      vse0   0   8      0    3    0    0    0
0      vse0   0   13     0    3    0    0    0

----------------------------------------------
flowid module cid chn FREE  REQ  PRO  COM USED
----------------------------------------------
0      vin0   0   0     16    0    0    0    0
0      vin0   0   8      0    2    1    0    0

0      isp0   0   0     16    0    0    0    0
0      isp0   0   8      0    3    0    0    0

0      vse0   0   0     16    0    0    0    0
0      vse0   0   8      0    3    0    0    0
0      vse0   0   13     0    3    0    0    0

========================= END ===========================
Opened DRM device: /dev/dri/card0
DRM is available, using libdrm for rendering.
------------------------------------------------------
Plane 0:
  Plane ID: 41
  Src W: 1920
  Src H: 1080
  CRTC X: 0
  CRTC Y: 0
  CRTC W: 1920
  CRTC H: 1080
  Format: NV12
  Z Pos: 0
  Alpha: 65535
  Pixel Blend Mode: 1
  Rotation: -1
  Color Encoding: -1
  Color Range: -1
------------------------------------------------------
Setting DRM client capabilities...
Setting up KMS...
CRTC ID: 31
CRTC ID: 63
Number of connectors: 1
Connector ID: 74
    Type: 11
    Type Name: HDMI-A
    Connection: Connected
    Modes: 41
    Subpixel: 1
    Mode 0: 1280x720 @ 60Hz
    Mode 1: 1920x1080 @ 60Hz
    Mode 2: 1920x1080 @ 60Hz
    Mode 3: 1920x1080 @ 60Hz
    Mode 4: 1920x1080i @ 60Hz
    Mode 5: 1920x1080i @ 60Hz
    Mode 6: 1920x1080 @ 50Hz
    Mode 7: 1920x1080i @ 50Hz
    Mode 8: 1920x1080i @ 50Hz
    Mode 9: 1920x1080 @ 24Hz
    Mode 10: 1920x1080 @ 24Hz
    Mode 11: 1680x1050 @ 60Hz
    Mode 12: 1280x1024 @ 60Hz
    Mode 13: 1280x960 @ 60Hz
    Mode 14: 1280x800 @ 60Hz
    Mode 15: 1280x720 @ 60Hz
    Mode 16: 1280x720 @ 60Hz
    Mode 17: 1280x720 @ 60Hz
    Mode 18: 1280x720 @ 50Hz
    Mode 19: 1280x720 @ 50Hz
    Mode 20: 1024x768 @ 60Hz
    Mode 21: 800x600 @ 60Hz
    Mode 22: 800x600 @ 56Hz
    Mode 23: 720x576 @ 50Hz
    Mode 24: 720x576 @ 50Hz
    Mode 25: 720x576 @ 50Hz
    Mode 26: 720x576i @ 50Hz
    Mode 27: 720x576i @ 50Hz
    Mode 28: 720x480 @ 60Hz
    Mode 29: 720x480 @ 60Hz
    Mode 30: 720x480 @ 60Hz
    Mode 31: 720x480 @ 60Hz
    Mode 32: 720x480 @ 60Hz
    Mode 33: 720x480i @ 60Hz
    Mode 34: 720x480i @ 60Hz
    Mode 35: 720x480i @ 60Hz
    Mode 36: 720x480i @ 60Hz
    Mode 37: 640x480 @ 60Hz
    Mode 38: 640x480 @ 60Hz
    Mode 39: 640x480 @ 60Hz
    Mode 40: 720x400 @ 70Hz
2026/07/15 17:33:52.456 !INFO [BindTo][0088]BindTo_CHN:-1

2026/07/15 17:33:52.457 !INFO [BindTo][0093]m_prev_module_chn:0

[BPU_PLAT]BPU Platform Version(1.3.6)! soc info(x5)
[HBRT] set log level as 0. version = 3.15.55.0
[DNN] Runtime version = 1.24.5_(3.15.55 HBRT)
2026/07/15 17:33:52.470 !INFO [SetImageFrame][0493]N2D init done!

Created new framebuffer: fb_id=77 for dma_buf_fd=57
add mapping dma_buf_fd:57 fb_id:77, mapping_count: 1
Created new framebuffer: fb_id=78 for dma_buf_fd=58
add mapping dma_buf_fd:58 fb_id:78, mapping_count: 2
[A][DNN][packed_model.cpp:247][Model](2026-07-15,17:33:52.625.466) [HorizonRT] The model builder version = 1.23.5
[W][DNN]bpu_model_info.cpp:491][Version](2026-07-15,17:33:52.691.932) Model: yolov5s_v2_672x672_bayese_nv12. Inconsistency between the hbrt library version 3.15.55.0 and the model build version 3.15.47.0 detected, in order to ensure correct model results, it is recommended to use compilation tools and the BPU SDK from the same OpenExplorer package.
^[[BTraceback (most recent call last):
  File "/app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py", line 259, in <module>
    input_array = yolov5x.pre_process(nv12_bytes, original_width=w, original_height=h)
  File "/app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py", line 104, in pre_process
    y, uv = pre_utils.split_nv12_bytes(img, original_width, original_height)
  File "/app/pydev_demo/utils/preprocess_utils.py", line 201, in split_nv12_bytes
    nv12_array = np.frombuffer(nv12_bytes, dtype=np.uint8)
TypeError: a bytes-like object is required, not 'NoneType'

问题分析

从你的错误日志看,核心问题是:

TypeError: a bytes-like object is required, not 'NoneType'

这个错误发生在 split_nv12_bytes 函数中,说明 nv12_bytesNone,即相机帧获取失败

结合日志中的几个关键信息:

  1. 传感器识别正常Auto-selected sensor: imx415-60fps-4lane
  2. VSE/ISP 配置正常:3840x2160@60fps 输入,输出 1920x1080
  3. 运行几分钟后崩溃:说明不是初始化问题,而是运行时帧获取超时或缓冲区耗尽

可能原因

1. 带宽/性能瓶颈

IMX415 在 60fps 4K 分辨率下数据量极大:

  • 原始数据:3840×2160×10bit × 60fps ≈ 5Gbps
  • X5 的 MIPI 和内存带宽可能无法持续支撑

2. 缓冲区不足

日志显示:

flowid module cid chn FREE  REQ  PRO  COM USED
0      vin0   0   8      0    2    1    0    0

缓冲区使用异常,可能导致后续帧获取失败。

3. 系统版本问题

你提到执行过 update+upgrade,这可能导致:

  • 驱动版本不匹配
  • 固件与 SDK 版本不一致

解决步骤

步骤 1:降低分辨率和帧率测试

修改代码,使用更低配置验证稳定性:

# 尝试 1080p@30fps
cam.open_cam(0,-1,-1,1920,1080,30)  # 如果支持 fps 参数

# 或者使用 720p
cam.open_cam(0,-1,-1,1280,720)

步骤 2:检查系统版本一致性

# 查看当前系统版本
cat /etc/version

# 查看 SDK 版本
python3 -c "import hobot_vio; print(hobot_vio.__version__)"

# 检查是否有未完成的更新
sudo apt update
sudo apt list --upgradable

步骤 3:增加错误处理和重试机制

在代码中添加帧获取失败的处理:

# 在 01_mipi_camera_yolov5s.py 中添加
max_retries = 3
for i in range(max_retries):
    nv12_bytes = vps.get_image()
    if nv12_bytes is not None:
        break
    print(f"Frame get failed, retry {i+1}/{max_retries}")
    time.sleep(0.1)

if nv12_bytes is None:
    print("Failed to get frame after retries, restarting camera...")
    # 添加相机重启逻辑
    continue

步骤 4:检查系统资源

运行时监控资源使用:

# 新开一个终端,监控内存和 CPU
watch -n 1 'free -h && echo "---" && top -bn1 | grep "Cpu(s)"'

# 监控 MIPI 相关错误
dmesg -w | grep -i "mipi\|vin\|isp"

步骤 5:回退系统版本(如必要)

如果 update+upgrade 后出现问题,考虑回退:

# 查看可用的内核版本
dpkg --list | linux-image

# 或者重新刷写官方镜像
# 下载地址:https://developer.d-robotics.cc/

建议

  1. 优先测试 1080p@30fps:IMX415 在 4K@60fps 下对 X5 压力过大
  2. 避免在生产环境执行 upgrade:等待官方验证的稳定版本
  3. 查看相关帖子

如果降低分辨率后问题消失,说明是带宽/性能瓶颈,建议:

  • 使用 1080p@30fps 或 720p@60fps
  • 或者考虑升级到更高性能的平台

需要我帮你查看具体的代码修改方案吗?

尝试过降低分辨率,报错了

sunrise@ubuntu:/app/pydev_demo/08_mipi_camera_sample$ sudo vim 01_mipi_camera_yolov5s.py 
sunrise@ubuntu:/app/pydev_demo/08_mipi_camera_sample$ python 01_mipi_camera_yolov5s.py 
2026/07/15 17:52:09.163 !INFO [OpenCamera][0471]hbn module
set camera fps: -1,width: -1,height: -1
Camera 0:
        mipi_host: 0
Camera 1:
        mipi_host: 2
Camera 2:
        mipi_host: 0
Camera 3:
        mipi_host: 0
mipi mclk is not configed.
Searching camera sensor on device: /proc/device-tree/soc/cam/vcon@0 i2c bus: 6 mipi rx phy: 0
WARN: Sensor Name: sc1330t, Expected Chip ID: 0xCA18, Actual Chip ID Read: 0x00
WARN: Sensor Name: irs2875-tof, Expected Chip ID: 0x2875, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs_mono, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs_mono, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5640, Expected Chip ID: 0x5640, Actual Chip ID Read: 0x00
WARN: Sensor Name: f37, Expected Chip ID: 0xF37, Actual Chip ID Read: 0x00
[0] INFO: Found sensor name:imx415-30fps-2lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_30fps_2lane.c
[1] INFO: Found sensor name:imx415-30fps-4lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_30fps_4lane.c
WARN: Sensor Name: sc202cs-1600x1200, Expected Chip ID: 0xEB52, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc202cs-1600x1200, Expected Chip ID: 0xEB52, Actual Chip ID Read: 0x00
WARN: Sensor Name: irs2381c-tof, Expected Chip ID: 0x2381, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs-vc0, Expected Chip ID: 0x35, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs-vc1, Expected Chip ID: 0x35, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx586-30fps-4lane, Expected Chip ID: 0x586, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx586-30fps-4lane, Expected Chip ID: 0x586, Actual Chip ID Read: 0x00
WARN: Sensor Name: os08c10-30fps-2lane, Expected Chip ID: 0x53, Actual Chip ID Read: 0x00
WARN: Sensor Name: os08c10-30fps-2lane, Expected Chip ID: 0x53, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0820std-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0820std-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc1336, Expected Chip ID: 0xCA3F, Actual Chip ID Read: 0x00
WARN: Sensor Name: dummy, Expected Chip ID: 0x00, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-200fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-200fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-120fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-120fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-640x480-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-640x480-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1632x1232-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1632x1232-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1920x1080-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1920x1080-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-15fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-15fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-21fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-21fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-640x480-60fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-1280x960-30fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-1920x1080-30fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-2592x1944-15fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1280x960-120fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1280x960-120fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1920x1080-50fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1920x1080-50fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-2016x1520-21fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-2016x1520-21fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-4000x3000-10fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-4000x3000-10fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov50h40-30fps-4lane, Expected Chip ID: 0x6C, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov50h40-30fps-4lane, Expected Chip ID: 0x6C, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s_2lane, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s_2lane, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
[2] INFO: Found sensor name:imx415-60fps-4lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_60fps_4lane.c
WARN: Sensor Name: sc850sl-30fps, Expected Chip ID: 0x9D1E, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc850sl-30fps, Expected Chip ID: 0x9D1E, Actual Chip ID Read: 0x00
WARN: Sensor Name: shw3g-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: shw3g-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
Auto-selected sensor: imx415-60fps-4lane (Resolution: 3840x2160@60fps)
2026/07/15 17:52:09.493 !INFO [CamInitParam][0341]Setting VSE channel-0: input_width:3840, input_height:2160, dst_w:640, dst_h:480
2026/07/15 17:52:09.493 !INFO [CamInitParam][0345]ROI: x:0, y:0, w:3840, h:2160, target_w:640, target_h:480
2026/07/15 17:52:09.494 !INFO [CamInitParam][0341]Setting VSE channel-5: input_width:3840, input_height:2160, dst_w:3840, dst_h:2160
2026/07/15 17:52:09.494 !INFO [CamInitParam][0345]ROI: x:0, y:0, w:3840, h:2160, target_w:3840, target_h:2160
2026/07/15 17:52:09.494 !INFO [vp_vin_init][0055]csi0 ignore mclk ex attr, because mclk is not configed at device tree.
================= VP Modules Status ====================
======================== VFLOW =========================
(active)[S0] vin0_C0*(dma)-m2m-isp0_C0-m2m-vse0_C0
========================= SIF ==========================
------------------- flow0 info -------------------
rx_index:0
vc_index:0
ipi_channels:1
width:3840
height:2160
format:0x2b
online_isp:0
ddr_en:0
bufnum:0
emb_en:0
embeded_dependence:0
embeded_width:0
embeded_height:0
size_err_cnt:0
========================= ISP ==========================
------------------- flow0 info -------------------
input_mode:2
sched_mode:0
tile_mode:0
af_mode:0
sensor_mode:0
input_width:3840
input_height:2160
input_format:1
input_bit_width:10
input_crop_x:0
input_crop_y:0
input_crop_w:3840
input_crop_h:2160
ddr_en:1
output_format:2
output_bit_width:8
========================= VSE ==========================
------------------- flow0 info -------------------
input_fps:0/0
input_width:3840
input_height:2160
input_format:2
input_bitwidth:8
dns0 channel: roi [0][0][3840][2160], target [640][480], fps [30/30]
ups channel: roi [0][0][0][0], target [0][0], fps [0/30]
========================= VENC =========================
Cannot open file /sys/kernel/debug/vpu/venc.========================= VDEC =========================
Cannot open file /sys/kernel/debug/vpu/vdec.========================= JENC =========================
Cannot open file /sys/kernel/debug/jpu/jenc.======================= Buffer =========================
----------------------------------------------
flowid module cid chn FREE  REQ  PRO  COM USED
----------------------------------------------
0      vin0   0   0     16    0    0    0    0
0      vin0   0   8      0    2    1    0    0

0      isp0   0   0     16    0    0    0    0
0      isp0   0   8      0    3    0    0    0

0      vse0   0   0     16    0    0    0    0
0      vse0   0   8      0    3    0    0    0
0      vse0   0   13     0    3    0    0    0

----------------------------------------------
flowid module cid chn FREE  REQ  PRO  COM USED
----------------------------------------------
0      vin0   0   0     16    0    0    0    0
0      vin0   0   8      0    2    1    0    0

0      isp0   0   0     16    0    0    0    0
0      isp0   0   8      0    3    0    0    0

0      vse0   0   0     16    0    0    0    0
0      vse0   0   8      0    3    0    0    0
0      vse0   0   13     0    3    0    0    0

========================= END ===========================
Opened DRM device: /dev/dri/card0
DRM is available, using libdrm for rendering.
------------------------------------------------------
Plane 0:
  Plane ID: 41
  Src W: 1920
  Src H: 1080
  CRTC X: 0
  CRTC Y: 0
  CRTC W: 1920
  CRTC H: 1080
  Format: NV12
  Z Pos: 0
  Alpha: 65535
  Pixel Blend Mode: 1
  Rotation: -1
  Color Encoding: -1
  Color Range: -1
------------------------------------------------------
Setting DRM client capabilities...
Setting up KMS...
CRTC ID: 31
CRTC ID: 63
Number of connectors: 1
Connector ID: 74
    Type: 11
    Type Name: HDMI-A
    Connection: Connected
    Modes: 41
    Subpixel: 1
    Mode 0: 1280x720 @ 60Hz
    Mode 1: 1920x1080 @ 60Hz
    Mode 2: 1920x1080 @ 60Hz
    Mode 3: 1920x1080 @ 60Hz
    Mode 4: 1920x1080i @ 60Hz
    Mode 5: 1920x1080i @ 60Hz
    Mode 6: 1920x1080 @ 50Hz
    Mode 7: 1920x1080i @ 50Hz
    Mode 8: 1920x1080i @ 50Hz
    Mode 9: 1920x1080 @ 24Hz
    Mode 10: 1920x1080 @ 24Hz
    Mode 11: 1680x1050 @ 60Hz
    Mode 12: 1280x1024 @ 60Hz
    Mode 13: 1280x960 @ 60Hz
    Mode 14: 1280x800 @ 60Hz
    Mode 15: 1280x720 @ 60Hz
    Mode 16: 1280x720 @ 60Hz
    Mode 17: 1280x720 @ 60Hz
    Mode 18: 1280x720 @ 50Hz
    Mode 19: 1280x720 @ 50Hz
    Mode 20: 1024x768 @ 60Hz
    Mode 21: 800x600 @ 60Hz
    Mode 22: 800x600 @ 56Hz
    Mode 23: 720x576 @ 50Hz
    Mode 24: 720x576 @ 50Hz
    Mode 25: 720x576 @ 50Hz
    Mode 26: 720x576i @ 50Hz
    Mode 27: 720x576i @ 50Hz
    Mode 28: 720x480 @ 60Hz
    Mode 29: 720x480 @ 60Hz
    Mode 30: 720x480 @ 60Hz
    Mode 31: 720x480 @ 60Hz
    Mode 32: 720x480 @ 60Hz
    Mode 33: 720x480i @ 60Hz
    Mode 34: 720x480i @ 60Hz
    Mode 35: 720x480i @ 60Hz
    Mode 36: 720x480i @ 60Hz
    Mode 37: 640x480 @ 60Hz
    Mode 38: 640x480 @ 60Hz
    Mode 39: 640x480 @ 60Hz
    Mode 40: 720x400 @ 70Hz
2026/07/15 17:52:10.547 !INFO [BindTo][0088]BindTo_CHN:-1

2026/07/15 17:52:10.547 !INFO [BindTo][0093]m_prev_module_chn:-1

[BPU_PLAT]BPU Platform Version(1.3.6)! soc info(x5)
[HBRT] set log level as 0. version = 3.15.55.0
[DNN] Runtime version = 1.24.5_(3.15.55 HBRT)
[A][DNN][packed_model.cpp:247][Model](2026-07-15,17:52:10.704.268) [HorizonRT] The model builder version = 1.23.5
[W][DNN]bpu_model_info.cpp:491][Version](2026-07-15,17:52:10.761.671) Model: yolov5s_v2_672x672_bayese_nv12. Inconsistency between the hbrt library version 3.15.55.0 and the model build version 3.15.47.0 detected, in order to ensure correct model results, it is recommended to use compilation tools and the BPU SDK from the same OpenExplorer package.
2026/07/15 17:52:10.765 ERROR [GetImageFrame][0711]get chn from 1920x1080 failed
Traceback (most recent call last):
  File "/app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py", line 259, in <module>
    input_array = yolov5x.pre_process(nv12_bytes, original_width=w, original_height=h)
  File "/app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py", line 104, in pre_process
    y, uv = pre_utils.split_nv12_bytes(img, original_width, original_height)
  File "/app/pydev_demo/utils/preprocess_utils.py", line 201, in split_nv12_bytes
    nv12_array = np.frombuffer(nv12_bytes, dtype=np.uint8)
TypeError: a bytes-like object is required, not 'NoneType'
sunrise@ubuntu:/app/pydev_demo/08_mipi_camera_sample$ grep -rn "open_cam" /app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py 
228:    #cam.open_cam(0,-1,-1,[w,disp_w],[h,disp_h],1080,1920)
229:    cam.open_cam(0,-1,-1,640,480)

问题定位

从新日志看到关键错误:

2026/07/15 17:52:10.765 ERROR [GetImageFrame][0711]get chn from 1920x1080 failed

核心问题:虽然你设置了 640x480,但系统仍在尝试从 1920x1080 通道获取帧。这说明 open_cam 参数格式不对,VSE 通道绑定错误。

根本原因

看日志中 VSE 配置:

Setting VSE channel-0: input_width:3840, input_height:2160, dst_w:640, dst_h:480
Setting VSE channel-5: input_width:3840, input_height:2160, dst_w:3840, dst_h:2160
  • Channel-0 输出 640x480(你设置的)
  • Channel-5 输出 3840x2160(原始分辨率)
  • get_image() 默认从 1920x1080 通道获取(可能是默认通道或之前配置残留)

解决方案

方案 1:修正 open_cam 参数格式

查看示例代码中 open_cam 的正确参数格式:

从新的错误日志看到关键问题:

2026/07/15 17:52:10.765 ERROR [GetImageFrame][0711]get chn from 1920x1080 failed

问题定位:虽然你修改了 open_cam 为 640x480,但系统仍在尝试从 1920x1080 通道获取帧。这说明:

  1. open_cam 参数格式可能不正确
  2. 获取帧的代码仍在请求 1920x1080 的通道

核心问题

查看日志中的 VSE 配置:

dns0 channel: roi [0][0][3840][2160], target [640][480], fps [30/30]

VSE channel-0 已正确配置为 640x480 输出,但获取帧的代码可能还在请求错误的通道

解决步骤

步骤 1:检查 open_cam 参数格式

查看示例代码中 open_cam 的完整签名:

# 查看函数定义
grep -A 20 "def open_cam" /app/pydev_demo/utils/*.py
# 或
python3 -c "from hobot_vio import libsrcampy as srcampy; help(srcampy.Camera.open_cam)"

步骤 2:修改代码,明确指定通道

根据日志,VSE channel-0 输出 640x480,你需要确保获取帧时从正确的通道获取。修改代码:

# 在 01_mipi_camera_yolov5s.py 中
# 原来的调用可能是这样的:
# nv12_bytes = vps.get_image()  # 默认可能请求 1920x1080

# 需要修改为指定通道或分辨率
# 方法1:指定通道 ID
nv12_bytes = vps.get_image(channel_id=0)  # 从 VSE channel-0 获取 640x480

# 或方法2:指定分辨率
nv12_bytes = vps.get_image(width=640, height=480)

步骤 3:检查 vps 初始化代码

查看 vps 是如何绑定的,可能需要修改绑定配置:

# 查找 vps 初始化代码
grep -n "vps" /app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py | head -20

步骤 4:临时测试方案

如果上述方法复杂,可以尝试使用官方推荐的分辨率配置:

# 使用 1280x720@30fps(X5 更稳定的配置)
cam.open_cam(0, 30, -1, 1280, 720)

# 同时修改后续获取帧的分辨率匹配
w, h = 1280, 720

步骤 5:查看完整示例代码

让我帮你查看示例代码的正确用法:

问题定位

关键错误信息:

2026/07/15 17:52:10.765 ERROR [GetImageFrame][0711]get chn from 1920x1080 failed

核心问题:你修改了 open_cam 的输出分辨率为 640x480,但代码后续仍在请求 1920x1080 通道的图像,导致获取失败。

原因分析

查看你的日志:

cam.open_cam(0,-1,-1,640,480)  # 你设置的输出分辨率

但日志显示:

Setting VSE channel-0: input_width:3840, input_height:2160, dst_w:640, dst_h:480  # VSE channel-0 输出 640x480
Setting VSE channel-5: input_width:3840, input_height:2160, dst_w:3840, dst_h:2160  # VSE channel-5 输出 3840x2160

关键矛盾

  • open_cam 的第三个参数 -1 表示使用默认通道
  • 但示例代码中 vps.get_image() 默认请求的是 1920x1080 通道(channel-0 的默认配置)
  • 你修改后 channel-0 输出变成了 640x480,但代码仍在按 1920x1080 请求

解决方案

方案 1:使用正确的通道参数(推荐)

修改 open_cam 调用,明确指定通道和输出分辨率:

# 原代码(第 229 行)
# cam.open_cam(0,-1,-1,640,480)

# 修改为:明确指定 channel-0 输出 640x480
cam.open_cam(0, 0, -1, 640, 480)
# 参数说明:(camera_id, channel_id, fps, width, height)

同时需要修改后续获取图像的代码,确保请求正确的分辨率:

# 在 01_mipi_camera_yolov5s.py 中找到 vps.get_image() 调用
# 确保传入的 w, h 与 open_cam 设置一致
w, h = 640, 480  # 与 open_cam 保持一致
nv12_bytes = vps.get_image()

方案 2:恢复 1920x1080 输出(快速验证)

如果只是想验证相机是否正常工作,先恢复默认配置:

# 恢复为 1920x1080
cam.open_cam(0, -1, -1, 1920, 1080)

方案 3:查看示例代码的完整参数格式

查看示例代码中 open_cam 的完整定义:

# 查看函数定义
grep -A 20 "def open_cam" /app/pydev_demo/utils/*.py

# 或者查看示例中的注释
head -250 /app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py | tail -30

立即执行步骤

  1. 查看当前代码的完整调用
cat /app/pydev_demo/08_mipi_camera_sample/01_mipi_camera_yolov5s.py | grep -A 5 -B 5 "open_cam"
  1. 修改为正确格式(假设使用 640x480):
# 第 229 行修改为
cam.open_cam(0, 0, 30, 640, 480)  # 明确指定 channel=0, fps=30, 640x480
  1. 同时修改后续分辨率变量
# 找到定义 w, h 的地方,确保与 open_cam 一致
w, h = 640, 480
  1. 运行测试
python 01_mipi_camera_yolov5s.py

补充检查

如果上述修改后仍有问题,请提供:

  1. open_cam 函数的完整定义(查看源码)
  2. 代码中 vps.get_image() 的调用方式
  3. 变量 wh 的定义位置

这样可以更精准定位参数不匹配的问题。

你好 415 是否为 手册提供的那款 意思是可以启动 但是几分钟后会报错退出吗

不是手册里的那款,我又重刷了3.4.1系统,不 upgrade,在旧示例上跑,只出了几帧就崩了:

sunrise@ubuntu:/app/pydev_demo/03_mipi_camera_sample$ sudo systemctl stop lightdm
sunrise@ubuntu:/app/pydev_demo/03_mipi_camera_sample$ python mipi_camera.py 
Opened DRM device: /dev/dri/card0
1920x1080
1680x1050
1280x1024
1280x960
1280x800
1280x720
1024x768
800x600
720x576
720x480
720x400
640x480
Resolution 3840x2160 does not exist in the list.
Resolution 1920x1080.
[BPU_PLAT]BPU Platform Version(1.3.6)! soc info(x5)
[HBRT] set log level as 0. version = 3.15.55.0
[DNN] Runtime version = 1.24.5_(3.15.55 HBRT)
[A][DNN][packed_model.cpp:247][Model](2026-07-16,11:53:15.609.429) [HorizonRT] The model builder version = 1.23.5
[W][DNN]bpu_model_info.cpp:491][Version](2026-07-16,11:53:15.682.225) Model: fcos_efficientnetb0_512x512_nv12. Inconsistency between the hbrt library version 3.15.55.0 and the model build version 3.15.47.0 detected, in order to ensure correct model results, it is recommended to use compilation tools and the BPU SDK from the same OpenExplorer package.
--- model input properties ---
tensor type: NV12
data type: uint8
layout: NCHW
shape: (1, 3, 512, 512)
--- model output properties ---
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 64, 64, 80)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 32, 32, 80)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 16, 16, 80)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 8, 8, 80)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 4, 4, 80)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 64, 64, 4)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 32, 32, 4)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 16, 16, 4)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 8, 8, 4)
tensor type: int32
data type: int32
layout: NHWC
shape: (1, 4, 4, 4)
tensor type: int32
data type: int32
layout: NCHW
shape: (1, 64, 64, 1)
tensor type: int32
data type: int32
layout: NCHW
shape: (1, 32, 32, 1)
tensor type: int32
data type: int32
layout: NCHW
shape: (1, 16, 16, 1)
tensor type: int32
data type: int32
layout: NCHW
shape: (1, 8, 8, 1)
tensor type: int32
data type: int32
layout: NCHW
shape: (1, 4, 4, 1)
2026/07/16 11:53:15.690 !INFO [OpenCamera][0447]hbn module
set camera fps: -1,width: 3840,height: 2160
Camera 0:
        mipi_host: 0
Camera 1:
        mipi_host: 2
Camera 2:
        mipi_host: 0
Camera 3:
        mipi_host: 0
mipi mclk is not configed.
Searching camera sensor on device: /proc/device-tree/soc/cam/vcon@0 i2c bus: 6 mipi rx phy: 0
WARN: Sensor Name: sc1330t, Expected Chip ID: 0xCA18, Actual Chip ID Read: 0x00
WARN: Sensor Name: irs2875-tof, Expected Chip ID: 0x2875, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-10fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc230ai-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-1280p, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc132gs-hdr-2lane, Expected Chip ID: 0x132, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs_mono, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs_mono, Expected Chip ID: 0x31, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5640, Expected Chip ID: 0x5640, Actual Chip ID Read: 0x00
WARN: Sensor Name: f37, Expected Chip ID: 0xF37, Actual Chip ID Read: 0x00
[0] INFO: Found sensor name:imx415-30fps-2lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_30fps_2lane.c
[1] INFO: Found sensor name:imx415-30fps-4lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_30fps_4lane.c
WARN: Sensor Name: sc202cs-1600x1200, Expected Chip ID: 0xEB52, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc202cs-1600x1200, Expected Chip ID: 0xEB52, Actual Chip ID Read: 0x00
WARN: Sensor Name: irs2381c-tof, Expected Chip ID: 0x2381, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs-vc0, Expected Chip ID: 0x35, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc035hgs-vc1, Expected Chip ID: 0x35, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc231ai-30fps, Expected Chip ID: 0xCB6A, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx586-30fps-4lane, Expected Chip ID: 0x586, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx586-30fps-4lane, Expected Chip ID: 0x586, Actual Chip ID Read: 0x00
WARN: Sensor Name: os08c10-30fps-2lane, Expected Chip ID: 0x53, Actual Chip ID Read: 0x00
WARN: Sensor Name: os08c10-30fps-2lane, Expected Chip ID: 0x53, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0820std-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0820std-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc1336, Expected Chip ID: 0xCA3F, Actual Chip ID Read: 0x00
WARN: Sensor Name: dummy, Expected Chip ID: 0x00, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ar0233-30fps, Expected Chip ID: 0xA55A, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-200fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-200fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-120fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov9782-120fps-2lane, Expected Chip ID: 0x9281, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-640x480-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-640x480-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1632x1232-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1632x1232-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1920x1080-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-1920x1080-30fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-15fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-15fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-21fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx219-3264x2464-21fps, Expected Chip ID: 0x219, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-640x480-60fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-1280x960-30fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-1920x1080-30fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov5647-2592x1944-15fps, Expected Chip ID: 0x5647, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1280x960-120fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1280x960-120fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1920x1080-50fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-1920x1080-50fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-2016x1520-21fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-2016x1520-21fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-4000x3000-10fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: imx477-4000x3000-10fps, Expected Chip ID: 0x477, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov50h40-30fps-4lane, Expected Chip ID: 0x6C, Actual Chip ID Read: 0x00
WARN: Sensor Name: ov50h40-30fps-4lane, Expected Chip ID: 0x6C, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s_2lane, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
WARN: Sensor Name: ox05b1s_2lane, Expected Chip ID: 0x58, Actual Chip ID Read: 0x00
[2] INFO: Found sensor name:imx415-60fps-4lane on mipi rx csi 0, i2c addr 0x1a, config_file:linear_3840x2160_raw10_60fps_4lane.c
WARN: Sensor Name: sc850sl-30fps, Expected Chip ID: 0x9D1E, Actual Chip ID Read: 0x00
WARN: Sensor Name: sc850sl-30fps, Expected Chip ID: 0x9D1E, Actual Chip ID Read: 0x00
WARN: Sensor Name: shw3g-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
WARN: Sensor Name: shw3g-30fps, Expected Chip ID: 0xCB34, Actual Chip ID Read: 0x00
Auto-selected sensor: imx415-60fps-4lane (Resolution: 3840x2160@60fps)
2026/07/16 11:53:16.037 !INFO [CamInitParam][0326]Setting VSE channel-0: input_width:3840, input_height:2160, dst_w:512, dst_h:512
2026/07/16 11:53:16.037 !INFO [CamInitParam][0326]Setting VSE channel-1: input_width:3840, input_height:2160, dst_w:1920, dst_h:1080
2026/07/16 11:53:16.037 !INFO [CamInitParam][0326]Setting VSE channel-5: input_width:3840, input_height:2160, dst_w:3840, dst_h:2160
2026/07/16 11:53:16.037 !INFO [vp_vin_init][0055]csi0 ignore mclk ex attr, because mclk is not configed at device tree.
================= VP Modules Status ====================
======================== VFLOW =========================
(active)[S0] vin0_C0*(dma)-m2m-isp0_C0-m2m-vse0_C0
========================= SIF ==========================
------------------- flow0 info -------------------
rx_index:0
vc_index:0
ipi_channels:1
width:3840
height:2160
format:0x2b
online_isp:0
ddr_en:0
bufnum:0
emb_en:0
embeded_dependence:0
embeded_width:0
embeded_height:0
size_err_cnt:0
========================= ISP ==========================
------------------- flow0 info -------------------
input_mode:2
sched_mode:0
tile_mode:0
af_mode:0
sensor_mode:0
input_width:3840
input_height:2160
input_format:1
input_bit_width:10
input_crop_x:0
input_crop_y:0
input_crop_w:3840
input_crop_h:2160
ddr_en:1
output_format:2
output_bit_width:8
========================= VSE ==========================
------------------- flow0 info -------------------
input_fps:0/0
input_width:3840
input_height:2160
input_format:2
input_bitwidth:8
dns0 channel: roi [0][0][3840][2160], target [512][512], fps [30/30]
dns1 channel: roi [0][0][3840][2160], target [1920][1080], fps [30/30]
ups channel: roi [0][0][0][0], target [0][0], fps [0/30]
========================= VENC =========================
Cannot open file /sys/kernel/debug/vpu/venc.========================= VDEC =========================
Cannot open file /sys/kernel/debug/vpu/vdec.========================= JENC =========================
Cannot open file /sys/kernel/debug/jpu/jenc.======================= Buffer =========================
----------------------------------------------
flowid module cid chn FREE  REQ  PRO  COM USED
----------------------------------------------
0      vin0   0   0     16    0    0    0    0
0      vin0   0   8      0    2    1    0    0

0      isp0   0   0     16    0    0    0    0
0      isp0   0   8      0    3    0    0    0

0      vse0   0   0     16    0    0    0    0
0      vse0   0   8      0    3    0    0    0
0      vse0   0   9      0    3    0    0    0
0      vse0   0   13     0    3    0    0    0

----------------------------------------------
flowid module cid chn FREE  REQ  PRO  COM USED
----------------------------------------------
0      vin0   0   0     16    0    0    0    0
0      vin0   0   8      0    2    1    0    0

0      isp0   0   0     16    0    0    0    0
0      isp0   0   8      0    3    0    0    0

0      vse0   0   0     16    0    0    0    0
0      vse0   0   8      0    3    0    0    0
0      vse0   0   9      0    3    0    0    0
0      vse0   0   13     0    3    0    0    0

========================= END ===========================
Opened DRM device: /dev/dri/card0
DRM is available, using libdrm for rendering.
------------------------------------------------------
Plane 0:
  Plane ID: 41
  Src W: 1920
  Src H: 1080
  CRTC X: 0
  CRTC Y: 0
  CRTC W: 1920
  CRTC H: 1080
  Format: NV12
  Z Pos: 0
  Alpha: 65535
  Pixel Blend Mode: 1
  Rotation: -1
  Color Encoding: -1
  Color Range: -1
------------------------------------------------------
Setting DRM client capabilities...
Setting up KMS...
CRTC ID: 31
CRTC ID: 63
Number of connectors: 1
Connector ID: 74
    Type: 11
    Type Name: HDMI-A
    Connection: Connected
    Modes: 41
    Subpixel: 1
    Mode 0: 1280x720 @ 60Hz
    Mode 1: 1920x1080 @ 60Hz
    Mode 2: 1920x1080 @ 60Hz
    Mode 3: 1920x1080 @ 60Hz
    Mode 4: 1920x1080i @ 60Hz
    Mode 5: 1920x1080i @ 60Hz
    Mode 6: 1920x1080 @ 50Hz
    Mode 7: 1920x1080i @ 50Hz
    Mode 8: 1920x1080i @ 50Hz
    Mode 9: 1920x1080 @ 24Hz
    Mode 10: 1920x1080 @ 24Hz
    Mode 11: 1680x1050 @ 60Hz
    Mode 12: 1280x1024 @ 60Hz
    Mode 13: 1280x960 @ 60Hz
    Mode 14: 1280x800 @ 60Hz
    Mode 15: 1280x720 @ 60Hz
    Mode 16: 1280x720 @ 60Hz
    Mode 17: 1280x720 @ 60Hz
    Mode 18: 1280x720 @ 50Hz
    Mode 19: 1280x720 @ 50Hz
    Mode 20: 1024x768 @ 60Hz
    Mode 21: 800x600 @ 60Hz
    Mode 22: 800x600 @ 56Hz
    Mode 23: 720x576 @ 50Hz
    Mode 24: 720x576 @ 50Hz
    Mode 25: 720x576 @ 50Hz
    Mode 26: 720x576i @ 50Hz
    Mode 27: 720x576i @ 50Hz
    Mode 28: 720x480 @ 60Hz
    Mode 29: 720x480 @ 60Hz
    Mode 30: 720x480 @ 60Hz
    Mode 31: 720x480 @ 60Hz
    Mode 32: 720x480 @ 60Hz
    Mode 33: 720x480i @ 60Hz
    Mode 34: 720x480i @ 60Hz
    Mode 35: 720x480i @ 60Hz
    Mode 36: 720x480i @ 60Hz
    Mode 37: 640x480 @ 60Hz
    Mode 38: 640x480 @ 60Hz
    Mode 39: 640x480 @ 60Hz
    Mode 40: 720x400 @ 70Hz
2026/07/16 11:53:17.088 !INFO [BindTo][0088]BindTo_CHN:-1

2026/07/16 11:53:17.088 !INFO [BindTo][0093]m_prev_module_chn:1

2026/07/16 11:53:17.101 !INFO [SetImageFrame][0493]N2D init done!

Created new framebuffer: fb_id=78 for dma_buf_fd=90
add mapping dma_buf_fd:90 fb_id:78, mapping_count: 1
Created new framebuffer: fb_id=79 for dma_buf_fd=91
add mapping dma_buf_fd:91 fb_id:79, mapping_count: 2
tv is in the picture with confidence:0.6016, bbox:[754, 262, 906, 382]
tv is in the picture with confidence:0.5725, bbox:[754, 262, 905, 381]
tv is in the picture with confidence:0.5539, bbox:[430, 406, 545, 458]
chair is in the picture with confidence:0.5257, bbox:[407, 443, 568, 593]
chair is in the picture with confidence:0.5373, bbox:[401, 443, 566, 592]
tv is in the picture with confidence:0.5339, bbox:[706, 381, 796, 449]
person is in the picture with confidence:0.5142, bbox:[1630, 343, 1761, 491]
tv is in the picture with confidence:0.5051, bbox:[430, 405, 546, 456]
chair is in the picture with confidence:0.5691, bbox:[401, 441, 572, 593]
tv is in the picture with confidence:0.5613, bbox:[752, 262, 905, 382]
person is in the picture with confidence:0.5449, bbox:[1633, 342, 1762, 493]
chair is in the picture with confidence:0.5030, bbox:[645, 425, 876, 681]
chair is in the picture with confidence:0.5744, bbox:[402, 442, 571, 591]
person is in the picture with confidence:0.5683, bbox:[1631, 344, 1762, 492]
tv is in the picture with confidence:0.5398, bbox:[749, 264, 905, 383]
chair is in the picture with confidence:0.5179, bbox:[645, 425, 879, 683]
tv is in the picture with confidence:0.5669, bbox:[748, 263, 906, 383]
chair is in the picture with confidence:0.5591, bbox:[401, 443, 572, 594]
person is in the picture with confidence:0.5337, bbox:[1628, 343, 1759, 490]
tv is in the picture with confidence:0.5406, bbox:[752, 264, 905, 385]
person is in the picture with confidence:0.5330, bbox:[1631, 340, 1760, 494]
chair is in the picture with confidence:0.5300, bbox:[408, 441, 568, 593]
chair is in the picture with confidence:0.5749, bbox:[402, 443, 566, 594]
tv is in the picture with confidence:0.5676, bbox:[751, 263, 906, 385]
person is in the picture with confidence:0.5359, bbox:[1634, 342, 1761, 489]
person is in the picture with confidence:0.5119, bbox:[1289, 117, 1914, 662]
chair is in the picture with confidence:0.5623, bbox:[403, 443, 568, 594]
tv is in the picture with confidence:0.5411, bbox:[751, 264, 905, 382]
person is in the picture with confidence:0.5312, bbox:[1633, 344, 1758, 486]
person is in the picture with confidence:0.5203, bbox:[1295, 116, 1914, 665]
person is in the picture with confidence:0.5014, bbox:[1156, 115, 1917, 887]
tv is in the picture with confidence:0.5759, bbox:[752, 262, 907, 381]
chair is in the picture with confidence:0.5645, bbox:[403, 443, 572, 594]
person is in the picture with confidence:0.5486, bbox:[1633, 344, 1759, 485]
chair is in the picture with confidence:0.5966, bbox:[403, 443, 567, 594]
tv is in the picture with confidence:0.5645, bbox:[750, 263, 907, 384]
person is in the picture with confidence:0.5279, bbox:[1631, 341, 1758, 484]
chair is in the picture with confidence:0.5165, bbox:[643, 423, 888, 726]
tv is in the picture with confidence:0.5776, bbox:[752, 264, 904, 382]
chair is in the picture with confidence:0.5751, bbox:[403, 441, 569, 593]
person is in the picture with confidence:0.5281, bbox:[1629, 343, 1759, 488]
chair is in the picture with confidence:0.5186, bbox:[644, 427, 877, 682]
person is in the picture with confidence:0.5176, bbox:[1195, 117, 1913, 686]
chair is in the picture with confidence:0.5551, bbox:[402, 438, 567, 593]
tv is in the picture with confidence:0.5444, bbox:[752, 265, 906, 383]
person is in the picture with confidence:0.5188, bbox:[1635, 342, 1758, 485]
chair is in the picture with confidence:0.5033, bbox:[649, 425, 875, 678]
chair is in the picture with confidence:0.5719, bbox:[401, 443, 570, 593]
person is in the picture with confidence:0.5322, bbox:[1637, 341, 1758, 486]
person is in the picture with confidence:0.5041, bbox:[1048, 111, 1920, 799]
chair is in the picture with confidence:0.5764, bbox:[399, 443, 569, 593]
tv is in the picture with confidence:0.5585, bbox:[752, 263, 904, 382]
person is in the picture with confidence:0.5413, bbox:[1632, 341, 1761, 487]
chair is in the picture with confidence:0.6027, bbox:[401, 442, 567, 593]
person is in the picture with confidence:0.5738, bbox:[1633, 342, 1762, 488]
chair is in the picture with confidence:0.5345, bbox:[643, 421, 878, 713]
tv is in the picture with confidence:0.5220, bbox:[752, 264, 905, 377]
chair is in the picture with confidence:0.5748, bbox:[405, 442, 565, 592]
person is in the picture with confidence:0.5497, bbox:[1637, 345, 1762, 483]
tv is in the picture with confidence:0.5348, bbox:[753, 265, 905, 381]
chair is in the picture with confidence:0.5326, bbox:[644, 423, 878, 756]
chair is in the picture with confidence:0.5662, bbox:[400, 442, 571, 591]
tv is in the picture with confidence:0.5418, bbox:[750, 263, 905, 385]
person is in the picture with confidence:0.5142, bbox:[1639, 343, 1752, 491]
chair is in the picture with confidence:0.5765, bbox:[403, 443, 568, 594]
tv is in the picture with confidence:0.5357, bbox:[748, 264, 904, 383]
person is in the picture with confidence:0.5175, bbox:[1637, 342, 1756, 487]
chair is in the picture with confidence:0.5136, bbox:[644, 421, 878, 760]
tv is in the picture with confidence:0.5781, bbox:[751, 263, 906, 385]
chair is in the picture with confidence:0.5493, bbox:[403, 443, 567, 594]
chair is in the picture with confidence:0.5345, bbox:[644, 436, 875, 682]
person is in the picture with confidence:0.5259, bbox:[1638, 343, 1756, 492]
chair is in the picture with confidence:0.5429, bbox:[403, 441, 570, 594]
person is in the picture with confidence:0.5408, bbox:[1636, 344, 1760, 492]
tv is in the picture with confidence:0.5323, bbox:[751, 264, 905, 380]
chair is in the picture with confidence:0.5028, bbox:[644, 426, 878, 699]
tv is in the picture with confidence:0.5840, bbox:[751, 263, 905, 384]
chair is in the picture with confidence:0.5450, bbox:[401, 443, 567, 594]
person is in the picture with confidence:0.5212, bbox:[1637, 342, 1757, 496]
tv is in the picture with confidence:0.5872, bbox:[750, 264, 905, 386]
chair is in the picture with confidence:0.5633, bbox:[404, 440, 568, 594]
person is in the picture with confidence:0.5139, bbox:[1637, 345, 1750, 495]
tv is in the picture with confidence:0.5691, bbox:[753, 264, 904, 384]
chair is in the picture with confidence:0.5573, bbox:[401, 442, 568, 594]
chair is in the picture with confidence:0.5296, bbox:[649, 433, 878, 682]
laptop is in the picture with confidence:0.5193, bbox:[933, 634, 1743, 823]
person is in the picture with confidence:0.5028, bbox:[1640, 342, 1747, 494]
tv is in the picture with confidence:0.5638, bbox:[751, 262, 905, 383]
chair is in the picture with confidence:0.5510, bbox:[402, 440, 567, 594]
chair is in the picture with confidence:0.5507, bbox:[644, 422, 876, 682]
person is in the picture with confidence:0.5121, bbox:[1640, 341, 1756, 496]
chair is in the picture with confidence:0.5536, bbox:[401, 444, 565, 594]
tv is in the picture with confidence:0.5323, bbox:[748, 264, 902, 382]
person is in the picture with confidence:0.5215, bbox:[1643, 343, 1756, 494]
chair is in the picture with confidence:0.5152, bbox:[644, 422, 877, 684]
chair is in the picture with confidence:0.6036, bbox:[403, 442, 568, 593]
chair is in the picture with confidence:0.5720, bbox:[403, 443, 569, 593]
tv is in the picture with confidence:0.5266, bbox:[753, 264, 905, 378]
tv is in the picture with confidence:0.5941, bbox:[750, 263, 903, 386]
person is in the picture with confidence:0.5052, bbox:[1297, 115, 1911, 663]
person is in the picture with confidence:0.5198, bbox:[1643, 343, 1756, 496]
tv is in the picture with confidence:0.5821, bbox:[749, 262, 905, 382]
chair is in the picture with confidence:0.5522, bbox:[402, 443, 566, 591]
chair is in the picture with confidence:0.5247, bbox:[408, 441, 567, 592]
chair is in the picture with confidence:0.5144, bbox:[649, 422, 877, 677]
person is in the picture with confidence:0.5066, bbox:[1646, 342, 1754, 494]
person is in the picture with confidence:0.5015, bbox:[1013, 105, 1912, 792]
tv is in the picture with confidence:0.5309, bbox:[750, 263, 904, 385]
chair is in the picture with confidence:0.5246, bbox:[649, 415, 878, 680]
person is in the picture with confidence:0.5026, bbox:[1643, 341, 1755, 496]
chair is in the picture with confidence:0.5999, bbox:[402, 442, 567, 592]
tv is in the picture with confidence:0.5276, bbox:[752, 264, 906, 384]
person is in the picture with confidence:0.5146, bbox:[1061, 108, 1919, 759]
person is in the picture with confidence:0.5099, bbox:[1295, 117, 1909, 656]
chair is in the picture with confidence:0.5503, bbox:[406, 443, 564, 594]
tv is in the picture with confidence:0.5259, bbox:[752, 264, 905, 381]
person is in the picture with confidence:0.5051, bbox:[1643, 343, 1753, 495]
laptop is in the picture with confidence:0.5018, bbox:[929, 632, 1720, 819]
chair is in the picture with confidence:0.5405, bbox:[402, 439, 574, 594]
chair is in the picture with confidence:0.5278, bbox:[645, 422, 878, 697]
person is in the picture with confidence:0.5047, bbox:[1643, 343, 1756, 495]
chair is in the picture with confidence:0.5795, bbox:[401, 442, 573, 593]
tv is in the picture with confidence:0.5256, bbox:[748, 263, 907, 386]
chair is in the picture with confidence:0.5906, bbox:[398, 443, 567, 593]
tv is in the picture with confidence:0.5451, bbox:[751, 263, 904, 384]
person is in the picture with confidence:0.5242, bbox:[1642, 342, 1758, 496]
chair is in the picture with confidence:0.5149, bbox:[632, 823, 944, 948]
tv is in the picture with confidence:0.5949, bbox:[749, 263, 906, 384]
chair is in the picture with confidence:0.5682, bbox:[404, 439, 567, 594]
person is in the picture with confidence:0.5147, bbox:[1643, 343, 1755, 493]
chair is in the picture with confidence:0.5741, bbox:[402, 443, 569, 593]
tv is in the picture with confidence:0.5294, bbox:[750, 263, 905, 382]
person is in the picture with confidence:0.5201, bbox:[1640, 342, 1758, 493]
chair is in the picture with confidence:0.5034, bbox:[644, 424, 881, 760]
chair is in the picture with confidence:0.5911, bbox:[401, 443, 569, 594]
tv is in the picture with confidence:0.5451, bbox:[747, 263, 901, 384]
chair is in the picture with confidence:0.5169, bbox:[644, 414, 879, 685]
person is in the picture with confidence:0.5048, bbox:[1642, 340, 1756, 493]
tv is in the picture with confidence:0.5634, bbox:[750, 263, 906, 385]
chair is in the picture with confidence:0.5510, bbox:[407, 444, 567, 594]
person is in the picture with confidence:0.5327, bbox:[1640, 344, 1755, 492]
chair is in the picture with confidence:0.5772, bbox:[402, 443, 567, 594]
tv is in the picture with confidence:0.5366, bbox:[751, 264, 905, 382]
person is in the picture with confidence:0.5333, bbox:[1640, 343, 1760, 495]
chair is in the picture with confidence:0.5029, bbox:[644, 422, 882, 680]
tv is in the picture with confidence:0.5441, bbox:[751, 264, 904, 382]
chair is in the picture with confidence:0.5431, bbox:[404, 441, 572, 591]
chair is in the picture with confidence:0.5292, bbox:[627, 820, 944, 953]
person is in the picture with confidence:0.5234, bbox:[1637, 342, 1753, 489]
chair is in the picture with confidence:0.5213, bbox:[649, 421, 872, 679]
chair is in the picture with confidence:0.5606, bbox:[402, 441, 569, 594]
chair is in the picture with confidence:0.5669, bbox:[407, 443, 565, 594]
person is in the picture with confidence:0.5117, bbox:[1638, 345, 1749, 494]
tv is in the picture with confidence:0.5039, bbox:[753, 262, 901, 384]
chair is in the picture with confidence:0.5610, bbox:[402, 441, 567, 593]
tv is in the picture with confidence:0.5305, bbox:[752, 264, 904, 381]
person is in the picture with confidence:0.5214, bbox:[1638, 345, 1756, 492]
chair is in the picture with confidence:0.5084, bbox:[645, 422, 877, 676]
chair is in the picture with confidence:0.5717, bbox:[402, 442, 567, 593]
chair is in the picture with confidence:0.5301, bbox:[648, 424, 876, 677]
person is in the picture with confidence:0.5117, bbox:[1638, 343, 1755, 489]
tv is in the picture with confidence:0.5019, bbox:[748, 264, 903, 384]
chair is in the picture with confidence:0.5518, bbox:[402, 443, 568, 594]
person is in the picture with confidence:0.5102, bbox:[1127, 108, 1908, 733]
tv is in the picture with confidence:0.5092, bbox:[749, 263, 905, 382]
person is in the picture with confidence:0.5043, bbox:[1636, 343, 1754, 494]
tv is in the picture with confidence:0.5562, bbox:[749, 262, 904, 383]
chair is in the picture with confidence:0.5494, bbox:[402, 442, 567, 594]
person is in the picture with confidence:0.5327, bbox:[1637, 343, 1754, 483]
chair is in the picture with confidence:0.5016, bbox:[650, 423, 875, 679]
chair is in the picture with confidence:0.5447, bbox:[405, 441, 567, 594]
chair is in the picture with confidence:0.5465, bbox:[401, 443, 571, 594]
tv is in the picture with confidence:0.5447, bbox:[752, 264, 904, 380]
person is in the picture with confidence:0.5396, bbox:[1635, 345, 1758, 490]
chair is in the picture with confidence:0.5032, bbox:[649, 424, 880, 679]
person is in the picture with confidence:0.5437, bbox:[1634, 345, 1761, 490]
chair is in the picture with confidence:0.5202, bbox:[633, 827, 932, 949]
tv is in the picture with confidence:0.5079, bbox:[753, 263, 906, 387]
person is in the picture with confidence:0.5395, bbox:[1628, 349, 1758, 495]
chair is in the picture with confidence:0.5350, bbox:[407, 443, 568, 594]
person is in the picture with confidence:0.5604, bbox:[1626, 344, 1760, 492]
tv is in the picture with confidence:0.5451, bbox:[749, 267, 904, 383]
chair is in the picture with confidence:0.5361, bbox:[402, 443, 569, 595]
chair is in the picture with confidence:0.5248, bbox:[649, 420, 877, 682]
person is in the picture with confidence:0.5511, bbox:[1624, 346, 1764, 490]
chair is in the picture with confidence:0.5388, bbox:[401, 440, 569, 593]
tv is in the picture with confidence:0.5376, bbox:[753, 264, 905, 380]
chair is in the picture with confidence:0.5342, bbox:[649, 424, 877, 681]
Traceback (most recent call last):
  File "/app/pydev_demo/03_mipi_camera_sample/mipi_camera.py", line 406, in <module>
    img = np.frombuffer(img, dtype=np.uint8)
TypeError: a bytes-like object is required, not 'NoneType'
sunrise@ubuntu:/app/pydev_demo/03_mipi_camera_sample$

旧示例代码:

sunrise@ubuntu:/app/pydev_demo/03_mipi_camera_sample$ cat mipi_camera.py 
#!/usr/bin/env python3

################################################################################
# Copyright (c) 2024,D-Robotics.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
################################################################################

import sys
import signal
import os
import numpy as np
import cv2
import colorsys
from time import time,sleep
import multiprocessing
from threading import BoundedSemaphore
import ctypes
import json
# Camera API libs

try:
    from hobot_vio import libsrcampy as srcampy
except ImportError:
    from hobot_vio_rdkx5 import libsrcampy as srcampy
try:
    from hobot_dnn import pyeasy_dnn as dnn
except ImportError:
    from hobot_dnn_rdkx5 import pyeasy_dnn as dnn
import threading

# sensor 
sensor_width = 3840
sensor_height = 2160

image_counter = None
is_stop=False
output_tensors = None

fcos_postprocess_info = None

# def signal_handler(signal, frame):
#     sys.exit(0)
#     global is_stop
#     print("Stopping!\n")
#     is_stop=True

class hbSysMem_t(ctypes.Structure):
    _fields_ = [
        ("phyAddr",ctypes.c_double),
        ("virAddr",ctypes.c_void_p),
        ("memSize",ctypes.c_int)
    ]

class hbDNNQuantiShift_yt(ctypes.Structure):
    _fields_ = [
        ("shiftLen",ctypes.c_int),
        ("shiftData",ctypes.c_char_p)
    ]

class hbDNNQuantiScale_t(ctypes.Structure):
    _fields_ = [
        ("scaleLen",ctypes.c_int),
        ("scaleData",ctypes.POINTER(ctypes.c_float)),
        ("zeroPointLen",ctypes.c_int),
        ("zeroPointData",ctypes.c_char_p)
    ]

class hbDNNTensorShape_t(ctypes.Structure):
    _fields_ = [
        ("dimensionSize",ctypes.c_int * 8),
        ("numDimensions",ctypes.c_int)
    ]

class hbDNNTensorProperties_t(ctypes.Structure):
    _fields_ = [
        ("validShape",hbDNNTensorShape_t),
        ("alignedShape",hbDNNTensorShape_t),
        ("tensorLayout",ctypes.c_int),
        ("tensorType",ctypes.c_int),
        ("shift",hbDNNQuantiShift_yt),
        ("scale",hbDNNQuantiScale_t),
        ("quantiType",ctypes.c_int),
        ("quantizeAxis", ctypes.c_int),
        ("alignedByteSize",ctypes.c_int),
        ("stride",ctypes.c_int * 8)
    ]

class hbDNNTensor_t(ctypes.Structure):
    _fields_ = [
        ("sysMem",hbSysMem_t * 4),
        ("properties",hbDNNTensorProperties_t)
    ]


class FcosPostProcessInfo_t(ctypes.Structure):
    _fields_ = [
        ("height",ctypes.c_int),
        ("width",ctypes.c_int),
        ("ori_height",ctypes.c_int),
        ("ori_width",ctypes.c_int),
        ("score_threshold",ctypes.c_float),
        ("nms_threshold",ctypes.c_float),
        ("nms_top_k",ctypes.c_int),
        ("is_pad_resize",ctypes.c_int)
    ]


libpostprocess = ctypes.CDLL('/usr/lib/libpostprocess.so')

get_Postprocess_result = libpostprocess.FcosPostProcess
get_Postprocess_result.argtypes = [ctypes.POINTER(FcosPostProcessInfo_t)]
get_Postprocess_result.restype = ctypes.c_char_p

def get_TensorLayout(Layout):
    if Layout == "NCHW":
        return int(2)
    else:
        return int(0)
is_stop=False

def signal_handler(signal, frame):
    global is_stop
    print("Stopping!\n")
    is_stop=True
    sys.exit(0)


def get_display_res():
    disp_w_small=1920
    disp_h_small=1080
    disp = srcampy.Display()
    resolution_list = disp.get_display_res()
    if (sensor_width, sensor_height) in resolution_list:
        print(f"Resolution {sensor_width}x{sensor_height} exists in the list.")
        return int(sensor_width), int(sensor_height)
    else:
        print(f"Resolution {sensor_width}x{sensor_height} does not exist in the list.")
        for res in resolution_list:
            # Exclude 0 resolution first.
            if res[0] == 0 and res[1] == 0:
                break
            else:
                disp_w_small=res[0]
                disp_h_small=res[1]

            # If the disp_w、disp_h is not set or not in the list, default to iterating to the smallest resolution for use.
            if res[0] <= sensor_width and res[1] <= sensor_height:
                print(f"Resolution {res[0]}x{res[1]}.")
                return int(res[0]), int(res[1])

    disp.close()
    return disp_w_small, disp_h_small

disp_w, disp_h = get_display_res()

# detection model class names
def get_classes():
    return np.array([
        "person", "bicycle", "car", "motorcycle", "airplane", "bus", "train",
        "truck", "boat", "traffic light", "fire hydrant", "stop sign",
        "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep",
        "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella",
        "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard",
        "sports ball", "kite", "baseball bat", "baseball glove", "skateboard",
        "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork",
        "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange",
        "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair",
        "couch", "potted plant", "bed", "dining table", "toilet", "tv",
        "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave",
        "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase",
        "scissors", "teddy bear", "hair drier", "toothbrush"
    ])


def get_hw(pro):
    if pro.layout == "NCHW":
        return pro.shape[2], pro.shape[3]
    else:
        return pro.shape[1], pro.shape[2]

def print_properties(pro):
    print("tensor type:", pro.tensor_type)
    print("data type:", pro.dtype)
    print("layout:", pro.layout)
    print("shape:", pro.shape)


class ParallelExector(object):
    def __init__(self, counter, parallel_num=4):
        global image_counter
        image_counter = counter
        self.parallel_num = parallel_num
        if parallel_num != 1:
            self._pool = multiprocessing.Pool(processes=self.parallel_num,
                                              maxtasksperchild=5)
            self.workers = BoundedSemaphore(self.parallel_num)

    def infer(self, output):
        if self.parallel_num == 1:
            run(output)
        else:
            self.workers.acquire()
            self._pool.apply_async(func=run,
                                   args=(output, ),
                                   callback=self.task_done,
                                   error_callback=print)

    def task_done(self, *args, **kwargs):
        """Called once task is done, releases the queue is blocked."""
        self.workers.release()

    def close(self):
        if hasattr(self, "_pool"):
            self._pool.close()
            self._pool.join()


def limit_display_cord(coor):
    coor[0] = max(min(disp_w, coor[0]), 0)
    # min coor is set to 2 not 0, leaving room for string display
    coor[1] = max(min(disp_h, coor[1]), 2)
    coor[2] = max(min(disp_w, coor[2]), 0)
    coor[3] = max(min(disp_h, coor[3]), 0)
    return coor


def scale_bbox(bbox, input_w, input_h, output_w, output_h):

    scale_x = output_w / input_w
    scale_y = output_h / input_h

    x1 = int(bbox[0] * scale_x)
    y1 = int(bbox[1] * scale_y)
    x2 = int(bbox[2] * scale_x)
    y2 = int(bbox[3] * scale_y)

    return [x1, y1, x2, y2]


def run(outputs):
    global image_counter

    strides = [8, 16, 32, 64, 128]
    for i in range(len(strides)):
        if (output_tensors[i].properties.quantiType == 0):
            output_tensors[i].sysMem[0].virAddr = ctypes.cast(outputs[i].ctypes.data_as(ctypes.POINTER(ctypes.c_float)), ctypes.c_void_p)
            output_tensors[i + 5].sysMem[0].virAddr = ctypes.cast(outputs[i + 5].ctypes.data_as(ctypes.POINTER(ctypes.c_float)), ctypes.c_void_p)
            output_tensors[i + 10].sysMem[0].virAddr = ctypes.cast(outputs[i + 10].ctypes.data_as(ctypes.POINTER(ctypes.c_float)), ctypes.c_void_p)
        else:
            output_tensors[i].sysMem[0].virAddr = ctypes.cast(outputs[i].ctypes.data_as(ctypes.POINTER(ctypes.c_int32)), ctypes.c_void_p)
            output_tensors[i + 5].sysMem[0].virAddr = ctypes.cast(outputs[i + 5].ctypes.data_as(ctypes.POINTER(ctypes.c_int32)), ctypes.c_void_p)
            output_tensors[i + 10].sysMem[0].virAddr = ctypes.cast(outputs[i + 10].ctypes.data_as(ctypes.POINTER(ctypes.c_int32)), ctypes.c_void_p)

        libpostprocess.FcosdoProcess(output_tensors[i], output_tensors[i + 5], output_tensors[i + 10], ctypes.pointer(fcos_postprocess_info), i)

    result_str = get_Postprocess_result(ctypes.pointer(fcos_postprocess_info))
    result_str = result_str.decode('utf-8')
    # print(result_str)

    # draw result
    # 解析JSON字符串
    data = json.loads(result_str[14:])

    # 遍历每一个结果
    for index, result in enumerate(data):
        bbox = result['bbox']  # 矩形框位置信息
        score = result['score']  # 得分
        id = int(result['id'])  # id
        name = result['name']  # 类别名称

        bbox = scale_bbox(bbox, 512, 512, disp_w, disp_h)
        coor = limit_display_cord(bbox)
        coor = [round(i) for i in coor]
        # get bbox score
        score = float(score)
        # concat bbox string
        bbox_string = '%s: %.2f' % (name, score)
        bbox_string = bbox_string.encode('gb2312')
        # concat bbox color
        box_color = colors[id]
        color_base = 0xFF000000
        box_color_ARGB = color_base | (box_color[0]) << 16 | (
            box_color[1]) << 8 | (box_color[2])

        print("{} is in the picture with confidence:{:.4f}, bbox:{}".format(name, score, coor))

        # if new frame come in, need to flush the display buffer.
        # For the meaning of parameters, please refer to the relevant documents of display api
        if index == 0:
            disp.set_graph_rect(coor[0], coor[1], coor[2], coor[3], 3, 1,
                                box_color_ARGB)
            disp.set_graph_word(coor[0], coor[1] - 2, bbox_string, 3, 1,
                                box_color_ARGB)
        else:
            disp.set_graph_rect(coor[0], coor[1], coor[2], coor[3], 3, 0,
                                box_color_ARGB)
            disp.set_graph_word(coor[0], coor[1] - 2, bbox_string, 3, 0,
                                box_color_ARGB)

    # fps timer and counter
    with image_counter.get_lock():
        image_counter.value += 1
    if image_counter.value == 100:
        finish_time = time()
        print(
            f"Total time cost for 100 frames: {finish_time - start_time}, fps: {100/(finish_time - start_time)}"
        )


if __name__ == '__main__':
    signal.signal(signal.SIGINT, signal_handler)

    models = dnn.load('../models/fcos_512x512_nv12.bin')
    print("--- model input properties ---")
    # 打印输入 tensor 的属性
    print_properties(models[0].inputs[0].properties)
    print("--- model output properties ---")
    # 打印输出 tensor 的属性
    for output in models[0].outputs:
        print_properties(output.properties)

    # 获取结构体信息
    fcos_postprocess_info = FcosPostProcessInfo_t()
    fcos_postprocess_info.height = 512
    fcos_postprocess_info.width = 512
    fcos_postprocess_info.ori_height = disp_h
    fcos_postprocess_info.ori_width = disp_w
    fcos_postprocess_info.score_threshold = 0.5
    fcos_postprocess_info.nms_threshold = 0.6
    fcos_postprocess_info.nms_top_k = 5
    fcos_postprocess_info.is_pad_resize = 0

    output_tensors = (hbDNNTensor_t * len(models[0].outputs))()

    for i in range(len(models[0].outputs)):
        output_tensors[i].properties.tensorLayout = get_TensorLayout(models[0].outputs[i].properties.layout)
        #print(output_tensors[i].properties.tensorLayout)
        if (len(models[0].outputs[i].properties.scale_data) == 0):
            output_tensors[i].properties.quantiType = 0
        else:
            output_tensors[i].properties.quantiType = 2
            scale_data_tmp = models[0].outputs[i].properties.scale_data.reshape(1, 1, 1, models[0].outputs[i].properties.shape[3])
            output_tensors[i].properties.scale.scaleData = scale_data_tmp.ctypes.data_as(ctypes.POINTER(ctypes.c_float))

        for j in range(len(models[0].outputs[i].properties.shape)):
            output_tensors[i].properties.validShape.dimensionSize[j] = models[0].outputs[i].properties.shape[j]
            output_tensors[i].properties.alignedShape.dimensionSize[j] = models[0].outputs[i].properties.shape[j]

    # Camera API, get camera object
    cam = srcampy.Camera()

    # get model info
    h, w = get_hw(models[0].inputs[0].properties)
    input_shape = (h, w)
    # Open f37 camera
    # For the meaning of parameters, please refer to the relevant documents of camera
    cam.open_cam(0, -1, -1, [w, disp_w], [h, disp_h],sensor_height,sensor_width)

    # Get HDMI display object
    disp = srcampy.Display()
    # For the meaning of parameters, please refer to the relevant documents of HDMI display
    disp.display(0, disp_w, disp_h)

    # bind camera directly to display
    srcampy.bind(cam, disp)

    # change disp for bbox display
    disp.display(3, disp_w, disp_h)

    # setup for box color and box string
    classes = get_classes()
    num_classes = len(classes)
    hsv_tuples = [(1.0 * x / num_classes, 1., 1.) for x in range(num_classes)]
    colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
    colors = list(
        map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)),
            colors))

    # fps timer and counter
    start_time = time()
    image_counter = multiprocessing.Value("i", 0)

    # post process parallel executor
    parallel_exe = ParallelExector(image_counter)

    while not is_stop:
        # image_counter += 1
        # Get image data with shape of 512x512 nv12 data from camera
        cam_start_time = time()
        img = cam.get_img(2, 512, 512)
        cam_finish_time = time()

        # Convert to numpy
        buffer_start_time = time()
        img = np.frombuffer(img, dtype=np.uint8)
        buffer_finish_time = time()

        # Forward
        infer_start_time = time()
        outputs = models[0].forward(img)
        infer_finish_time = time()

        output_array = []
        for item in outputs:
            output_array.append(item.buffer)
        parallel_exe.infer(output_array)

    cam.close_cam()
    disp.close()

问题定位

从最新日志看,核心问题是 cam.get_img() 返回 None,导致 np.frombuffer() 失败。这不是代码问题,而是运行时帧获取超时/失败

关键信息:

  • :white_check_mark: 传感器识别正常:imx415-60fps-4lane
  • :white_check_mark: 初始化成功:能输出几十帧检测结果
  • :cross_mark: 运行几十帧后崩溃:cam.get_img() 返回 None

根本原因分析

1. 带宽瓶颈(最可能)

IMX415 @ 4K@60fps 数据量:

3840 × 2160 × 10bit × 60fps ≈ 5Gbps

X5 的 MIPI RX 和内存带宽无法持续支撑这个数据率,导致缓冲区耗尽后帧获取失败。

2. 传感器兼容性问题

你说"不是手册里的那款",这很关键:

  • 官方示例针对特定型号的 IMX415 调优
  • 第三方/不同批次传感器可能存在时序/寄存器差异
  • 运行初期正常,但长时间运行后累积误差导致失步

3. 版本不匹配警告

HBRT: 3.15.55.0
Model: 3.15.47.0

虽然这不直接导致崩溃,但建议保持一致。

解决方案

方案 1:降低传感器输出帧率(推荐优先测试)

修改 open_cam 调用,强制使用 30fps 而非 60fps:

# 在 mipi_camera.py 第 377 行附近
# 原代码:
cam.open_cam(0, -1, -1, [w, disp_w], [h, disp_h], sensor_height, sensor_width)

# 修改为(明确指定 fps=30):
cam.open_cam(0, -1, 30, [w, disp_w], [h, disp_h], sensor_height, sensor_width)

如果上述格式不支持,尝试直接修改传感器配置文件:

# 查看可用的传感器配置
ls /lib/firmware/hb_sensor_cfg/ | grep imx415

# 备份后修改配置,将 60fps 改为 30fps
sudo cp /lib/firmware/hb_sensor_cfg/linear_3840x2160_raw10_60fps_4lane.c \
        /lib/firmware/hb_sensor_cfg/linear_3840x2160_raw10_60fps_4lane.c.bak

方案 2:降低分辨率测试稳定性

# 使用 1080p@30fps 验证是否稳定
sensor_width = 1920
sensor_height = 1080

# open_cam 相应修改
cam.open_cam(0, -1, 30, [w, disp_w], [h, disp_h], sensor_height, sensor_width)

方案 3:增加帧获取超时处理和相机重启

while not is_stop: 循环中添加错误处理:

# 在 while 循环中修改
max_retries = 3
retry_count = 0

while not is_stop:
    img = cam.get_img(2, 512, 512)
    
    # 帧获取失败处理
    if img is None:
        retry_count += 1
        print(f"Frame get failed ({retry_count}/{max_retries}), retrying...")
        
        if retry_count >= max_retries:
            print("Camera frame get timeout, restarting camera...")
            cam.close_cam()
            sleep(0.5)
            cam.open_cam(0, -1, 30, [w, disp_w], [h, disp_h], sensor_height, sensor_width)
            retry_count = 0
            start_time = time()  # 重置 fps 计时
            image_counter.value = 0
        continue
    
    retry_count = 0  # 成功获取后重置计数
    
    # 后续处理代码...
    img = np.frombuffer(img, dtype=np.uint8)

方案 4:监控运行时状态

新开终端监控,帮助定位瓶颈:

# 监控内存使用
watch -n 1 'free -h'

# 监控 MIPI/ISP 错误
dmesg -w | grep -iE "mipi|vin|isp|error"

# 监控温度(如果支持)
cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null

立即执行步骤

# 1. 查看当前系统版本
cat /etc/version

# 2. 查看可用的 IMX415 配置文件
ls -la /lib/firmware/hb_sensor_cfg/ | grep imx415

# 3. 备份原代码后修改测试
cp /app/pydev_demo/03_mipi_camera_sample/mipi_camera.py \
   /app/pydev_demo/03_mipi_camera_sample/mipi_camera.py.bak

# 4. 修改 open_cam 添加 fps 参数(如果支持)
# 或降低 sensor_width/sensor_height 为 1920/1080

# 5. 运行测试并监控 dmesg
dmesg -w > /tmp/mipi_log.txt &
python /app/pydev_demo/03_mipi_camera_sample/mipi_camera.py

需要确认的信息

请提供以下信息以便进一步定位:

  1. 传感器采购渠道:是官方套件还是第三方购买?
  2. MIPI 连接方式:是 X5 评估板自带接口还是通过转接板?
  3. 崩溃前运行时长:大概多少秒/多少帧后崩溃?
  4. dmesg 日志:崩溃时是否有 MIPI/ISP 相关错误?

如果降低到 1080p@30fps 仍然崩溃,基本可以确定是传感器兼容性或硬件连接问题,建议联系硬件供应商确认传感器规格是否与 X5 兼容。

这个sample 对 IMX415 兼容存在问题

你这边的I2C能取到地址的话可以先用 TROS方法可以用这个启动:2.1 数据采集 | RDK DOC 来启动

不是我们手册的话还需要自己改下地址

指定帧率60fps 测试一下看看?

问题总结

根据你的测试和官方回复,核心问题已定位:

  1. Sample 兼容性问题:当前示例代码对非官方 IMX415 传感器支持不完善
  2. 帧获取超时:运行几十帧后 cam.get_img() 返回 None
  3. 传感器配置:非手册指定型号,I2C 地址/时序可能需要调整

立即测试方案

方案 1:指定 60fps 测试(runingsoc 建议)

修改 open_cam 调用,明确指定帧率参数:

# 在 mipi_camera.py 第 377 行附近
# 原代码:
cam.open_cam(0, -1, -1, [w, disp_w], [h, disp_h], sensor_height, sensor_width)

# 修改为(指定 fps=60):
cam.open_cam(0, -1, 60, [w, disp_w], [h, disp_h], sensor_height, sensor_width)
#                        ↑↑
#                     fps 参数

如果上述格式不支持,尝试简化参数:

# 另一种格式
cam.open_cam(0, 0, 60, 1920, 1080)

方案 2:使用 TROS MIPI 采集(Marcelo6151 建议)

官方推荐的替代方案,参考文档:
MIPI 图像采集 - TROS 文档

步骤:

# 1. 查看 TROS 示例位置
ls /opt/tros/share/hobot_camera/sample/

# 2. 运行 TROS 相机示例
cd /opt/tros/share/hobot_camera/sample/
python3 mipi_camera_demo.py

# 3. 如果报错,检查传感器 I2C 地址
i2cdetect -y -r 6  # IMX415 通常在 0x1a

关键排查步骤

1. 确认传感器 I2C 地址

# 扫描 I2C 总线 6(从日志看是 bus 6)
i2cdetect -y -r 6

# 确认 0x1a 地址是否有设备响应

2. 查看可用传感器配置

ls -la /lib/firmware/hb_sensor_cfg/ | grep imx415

如果配置文件与你的传感器不匹配,需要:

  • 确认传感器的实际分辨率/帧率支持
  • 修改或创建对应的 .c 配置文件

3. 监控运行时错误

# 新开终端监控内核日志
dmesg -w | grep -iE "mipi|vin|isp|error" > /tmp/mipi_debug.log &

# 运行测试
python /app/pydev_demo/03_mipi_camera_sample/mipi_camera.py

# 崩溃后查看日志
cat /tmp/mipi_debug.log

建议执行顺序

步骤 操作 目的
1 修改 open_cam 指定 fps=60 验证帧率参数影响
2 运行 TROS 示例 排除示例代码问题
3 检查 dmesg 日志 定位硬件/驱动错误
4 确认 I2C 地址 验证传感器通信

需要反馈的信息

测试后请提供:

  1. 指定 60fps 后的运行结果(能跑多少帧)
  2. TROS 示例是否能正常运行
  3. dmesg 中的关键错误信息
  4. 传感器采购信息(确认是否官方兼容型号)

如果 TROS 示例能稳定运行,说明是原示例代码的兼容性问题,可以基于 TROS 方案开发。如果同样崩溃,基本确定是传感器硬件兼容性或 MIPI 连接问题

换了新的RDK-X5后就可以,应该是之前的板子有点问题。

用新主板跑03_mipi_camera_sample/mipi_camera.py不会崩了,就是画面会闪,运行几分钟后识别功能挂了,还能出图,画面不闪了,CPU测温80℃。

现在是改为使用TROS调用相机了,跑自己程序出图正常。

另一个问题是跑示例必会导致ssh、vnc网络服务超时断开,wifi连着,ping 网关不通(主机不可达)。
在我自己的程序里通过TROS调用相机也会出现这种情况,程序退了也恢复不了。

问题定位

恭喜找到根因!旧板子硬件问题导致帧获取失败。但现在有两个新问题需要解决:

  1. CPU 高温 (80℃) + 画面闪烁 + 识别功能挂掉
  2. 网络服务崩溃(SSH/VNC 断开,ping 不通网关)

这两个问题很可能相关——系统资源耗尽导致网络栈异常


立即排查步骤

1. 检查系统资源状态

网络断开时,在新终端(或串口)执行:

# 查看内存使用
free -h

# 查看进程资源占用
top -bn1 | head -20

# 查看网络接口状态
ip addr show
ip route show

# 查看网络服务状态
systemctl status ssh
systemctl status NetworkManager

# 查看系统日志中的网络错误
journalctl -xe | grep -i "network\|wifi\|ssh" | tail -50

2. 检查 MIPI/ISP 资源泄漏

# 查看 VIN/ISP 缓冲区状态
cat /sys/kernel/debug/vin/vin0/status 2>/dev/null

# 查看是否有 MIPI 错误
dmesg | grep -iE "mipi|vin|isp|error" | tail -30

# 查看 DMA 缓冲区
cat /sys/kernel/debug/dma_buf/bufinfo 2>/dev/null | head -50

3. 降低 CPU 负载测试

# 查看当前 CPU 频率
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq

# 临时降低 CPU 频率(如果支持)
echo powersave | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

# 监控温度
watch -n 1 'cat /sys/class/thermal/thermal_zone*/temp'

解决方案

方案 1:优化 TROS 相机调用(推荐)

你提到 TROS 调用 640x480@30fps 也会出问题,需要检查是否正确释放资源:

# 确保在程序退出时正确释放相机资源
import rospy
from hobot_camera import Camera

cam = Camera()
cam.open(0, 640, 480, 30)

try:
    while not rospy.is_shutdown():
        img = cam.get_image()
        # 处理图像...
except KeyboardInterrupt:
    pass
finally:
    # 关键:确保关闭相机
    cam.close()
    rospy.signal_shutdown("exit")

方案 2:添加看门狗重启网络服务

在程序中添加网络健康检查:

import subprocess
import time

def check_network():
    try:
        result = subprocess.run(['ping', '-c1', '192.168.1.1'], 
                              timeout=2, capture_output=True)
        return result.returncode == 0
    except:
        return False

def restart_network():
    subprocess.run(['sudo', 'systemctl', 'restart', 'NetworkManager'])
    time.sleep(2)

# 在主循环中每 30 秒检查一次
if not check_network():
    print("Network lost, restarting...")
    restart_network()

方案 3:降低系统负载

# 1. 关闭不必要的服务
sudo systemctl stop lightdm  # 如果不用桌面
sudo systemctl disable bluetooth

# 2. 限制程序 CPU 使用
taskset -c 0-3 python your_program.py  # 限制在前 4 核

# 3. 增加散热
# - 加风扇
# - 降低环境温度
# - 避免阳光直射

方案 4:检查系统版本兼容性

# 查看当前版本
cat /etc/version

# 如果是 3.4.1,考虑升级到 3.5.0(如果有网络)
# 或重新刷写最新镜像

社区类似问题参考

搜索到相关帖子供参考:

问题 链接
X5 系统莫名重启 查看帖子
打开摄像头就死机 查看帖子
RDK X5 系统版本问题 查看帖子

需要反馈的信息

请提供以下信息以便进一步定位:

# 1. 网络断开时的系统状态
free -h
top -bn1 | head -10

# 2. 网络接口状态
ip addr show
ip route show

# 3. 系统日志
dmesg | tail -50

# 4. TROS 程序代码片段(相机调用部分)

临时 workaround

如果急需使用,可以:

  1. 用串口调试代替 SSH/VNC
  2. 程序运行前备份网络状态,断开后手动重启
  3. 降低相机分辨率和帧率减少负载(如 320x240@15fps)
# 网络断开后快速恢复
sudo systemctl restart NetworkManager && sudo systemctl restart ssh

先按上述步骤排查,把 free -hdmesg 日志发出来,可以进一步分析是内存泄漏还是网络栈问题。

CPU 80度 已经开始降频了,需要散热的