我想使用 Display.bind_lay 显示一个通道的内容,发现在某些通道下会导致另一个通道的 snapshot 产生错误 RuntimeError: sensor(0) snapshot chn(1) failed(3) 更改通道序号就没问题,具体哪些通道会产生错误写在代码里了
import os
import gc
import sys
import image
import utime
from media.sensor import *
from media.display import *
from media.media import *
'''
更改下面两个变量的值会产生不同的结果
CAM_CHN_ID_lcd CAM_CHN_ID_shot
0 1 RuntimeError: sensor(0) snapshot chn(1) failed(3)
0 2 RuntimeError: sensor(0) snapshot chn(2) failed(3)
1 2 RuntimeError: sensor(0) snapshot chn(2) failed(3)
1 0 OK
2 0 OK
2 1 OK
'''
CAM_CHN_ID_lcd = CAM_CHN_ID_0
CAM_CHN_ID_shot = CAM_CHN_ID_1
# 摄像头初始化
sensor = Sensor(id=2, width=1920, height=1080, fps=60)
sensor.reset()
# LCD显示通道
sensor.set_framesize(chn=CAM_CHN_ID_lcd, width=800, height=480)
sensor.set_pixformat(Sensor.YUV420SP, chn=CAM_CHN_ID_lcd)
print(sensor.bind_info())
# 图像处理通道
sensor.set_framesize(chn=CAM_CHN_ID_shot, width=1920, height=1080)
sensor.set_pixformat(Sensor.GRAYSCALE, chn=CAM_CHN_ID_shot)
# 配置Display
Display.bind_layer(src=(6, 0, CAM_CHN_ID_lcd), dstlayer=Display.LAYER_VIDEO1, rect=(0, 0, 800, 480), pix_format=Sensor.YUV420SP)
Display.init(Display.ST7701, width=800, height=480, to_ide=True)
MediaManager.init()
sensor.run()
clock = utime.clock()
while True:
clock.tick()
img = sensor.snapshot(chn=CAM_CHN_ID_shot)
gc.collect()
print(clock.fps())
去掉 Display.bind_layer(src=(6, 0, CAM_CHN_ID_lcd), dstlayer=Display.LAYER_VIDEO1, rect=(0, 0, 800, 480), pix_format=Sensor.YUV420SP)
或者 img = sensor.snapshot(chn=CAM_CHN_ID_shot)
都不会产生错误
板子是立创庐山派