官方的对焦摄像头可以同时多个吗

Viewed 59

问题描述


使用庐山派,csi0和csi1分别接了一个对焦摄像头。想要同时开启自动对焦功能。
对焦文档链接
出现一开始一两秒有画面,后面就报错。

报错日志:

Three Camera Test
find sensor gc2093_csi0, type 15, output 1920x1080@30
True
find sensor gc2093_csi1, type 19, output 1920x1080@30
True
[<Sensor object at 100048800>, <Sensor object at 10004e580>]
vb common pool count 7
sensor(0), mode 1, buffer_num 4, buffer_size 4149248
sensor(1), mode 1, buffer_num 4, buffer_size 4149248
Exception: sensor(0) snapshot chn(0) failed(3)

测试代码:

import time, os, sys
from media.sensor import *
from media.display import *
from media.media import *

sensors = []
MAX_CAMS = 2

def init_sensor(cam_id):
    try:
        sensor = Sensor(id=cam_id, fps=30)
        sensor.reset()
        if cam_id == 0 or cam_id == 1:
            sensor.auto_focus(True)
        print(sensor.auto_focus())
        sensor.set_framesize(width=320, height=240, chn=CAM_CHN_ID_0)
        sensor.set_pixformat(Sensor.RGB888, chn=CAM_CHN_ID_0)
        return sensor
    except Exception as e:
        print(f"Camera {cam_id} not detected: {e}")
        return None

try:
    print("Three Camera Test")

    # 初始化并检测所有可能的摄像头
    for i in range(MAX_CAMS):
        sensor = init_sensor(i)
        if sensor is not None:
            sensors.append(sensor)

    # 只有当至少有一个摄像头被成功初始化后才继续
    print(sensors)
    if len(sensors) > 0:
        Display.init(Display.ST7701, width=640, height=480, to_ide=True, osd_num=5)
        MediaManager.init()

        for sensor in sensors:
            sensor.run()

        while True:
            os.exitpoint()

            # 获取并显示每个摄像头的画面
            for idx, sensor in enumerate(sensors):
                img = sensor.snapshot(chn=CAM_CHN_ID_0)
                Display.show_image(img, x=320*(idx %2), y=240*(idx//2), layer=Display.LAYER_OSD0 + idx)

            time.sleep_ms(30)  # 控制帧率

except KeyboardInterrupt as e:
    print("User stop:", e)
except BaseException as e:
    print(f"Exception: {e}")
finally:
    # 停止所有已初始化的摄像头
    for sensor in sensors:
        if hasattr(sensor, 'stop'):
            sensor.stop()
    Display.deinit()
    MediaManager.deinit()
    os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)

有以下测试:
1.当我关闭不开启摄像头的对焦功能时,是正常运行的。
2.一个关闭一个开启,也是有问题。
3.只加载一个摄像头,并开启对焦功能是正常的。

复现步骤


对焦摄像头接csi0 和 csi1
运行脚本

硬件板卡


庐山派

1 Answers

你好,目前如果有一个开了自动对焦,其他的都要打开,如果关闭了,则可能会导致所有的都被关闭。