Intel Realsense D435 测试摄像头在不同曝光值下的帧生成时间(防止曝光时间过长导致fps下降)auto_exposure_priority(没成功)

不用测了

参考文章:Intel Realsense D435 pyrealsense2 get_option_range() 获取rs.option中参数值取值范围

突然发现,option.py中有option.auto_exposure_priority参数能够限制自动曝光以维持恒定的fps速率,所以就不用担心曝光时间过长导致fps下降了

想了想,不对,还是要测

因为自动曝光优先是在自动曝光开启时才用到的,当自动曝光关闭时,它就失去作用了。。。我检验一下

# -*- coding: utf-8 -*-
"""
@File    : 200108_测试获取Intel_Realsense_options参数.py
@Time    : 2020/1/8 13:18
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
import time

import numpy as np
import pyrealsense2 as rs
import cv2

ctx = rs.context()

pipeline = rs.pipeline(ctx)
cfg = rs.config()
cfg.enable_device('838212073161')
cfg.enable_stream(rs.stream.depth, 640, 360, rs.format.z16, 30)
cfg.enable_stream(rs.stream.color, 640, 360, rs.format.bgr8, 30)
pipeline_profile = pipeline.start(cfg)

sensor = pipeline.get_active_profile().get_device().query_sensors()[1]
sensor.set_option(rs.option.enable_auto_exposure, True)
print(sensor.get_option(rs.option.exposure))  # 156.0
sensor.set_option(rs.option.exposure, 5000.000)
print(sensor.get_option(rs.option.exposure))  # 5000.0
sensor.set_option(rs.option.auto_exposure_priority, True)
print(sensor.get_option(rs.option.exposure))  # 5000.0

结果:
在这里插入图片描述
将曝光值设置为5000后,明显感觉传输帧变慢了(其实没慢,就是没曝光完全,存在残影),说明auto_exposure_priority并未限制曝光值以维持帧速率,为了保证验证的准确性,我又将auto_exposure_priority设置为False,发现还是同样的结果

下面测试auto_exposure_priority参数在自动曝光下的作用

# -*- coding: utf-8 -*-
"""
@File    : 200109_测试摄像头自动曝光优先.py
@Time    : 2020/1/9 14:43
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""

import numpy as np
import pyrealsense2 as rs
import cv2

ctx = rs.context()

pipeline = rs.pipeline(ctx)
cfg = rs.config()
cfg.enable_device('838212073161')
cfg.enable_stream(rs.stream.depth, 640, 360, rs.format.z16, 30)
cfg.enable_stream(rs.stream.color, 640, 360, rs.format.bgr8, 30)
pipeline_profile = pipeline.start(cfg)

sensor = pipeline.get_active_profile().get_device().query_sensors()[1]
sensor.set_option(rs.option.enable_auto_exposure, True)
sensor.set_option(rs.option.auto_exposure_priority, False)

while True:
    frames = pipeline.wait_for_frames()
    color_frame = frames.get_color_frame()
    color_image = np.asanyarray(color_frame.get_data())
    cv2.imshow('win', color_image)
    cv2.waitKey(1)

结果:
将auto_exposure_priority设置为False,发现并没有出现帧速率下降的现象,每帧传来都约0.033秒(设置帧速率为30帧每秒):
在这里插入图片描述
将auto_exposure_priority设置为True,结果还是相同
在这里插入图片描述
那这个auto_exposure_priority参数有啥用???

仔细观察,还是有区别的,当设置auto_exposure_priority为True时,当摄像头的场景由暗向光转变,图像会突然闪亮一下,像是曝光过度的感觉,当场景由光向暗转变时,摄像头会在一瞬间暗得特别厉害,就是过渡不平滑;但是如果auto_exposure_priority设置为False时,过渡就会非常平滑

由于不知道这种平滑过渡或不平滑过渡会对我们项目带来哪些影响,就暂时按照它默认的设置吧,默认为Ture,参考:Intel Realsense D435 pyrealsense2 get_option_range() 获取rs.option中参数值取值范围

下面测试在自动曝光模式下如何实时获取曝光值

# -*- coding: utf-8 -*-
"""
@File    : 200108_测试获取Intel_Realsense_options参数.py
@Time    : 2020/1/8 13:18
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
import time
import numpy as np
import pyrealsense2 as rs
import cv2

ctx = rs.context()

pipeline = rs.pipeline(ctx)
cfg = rs.config()
cfg.enable_device('838212073161')
cfg.enable_stream(rs.stream.depth, 640, 360, rs.format.z16, 30)
cfg.enable_stream(rs.stream.color, 640, 360, rs.format.bgr8, 30)
pipeline_profile = pipeline.start(cfg)

sensor = pipeline.get_active_profile().get_device().query_sensors()[1]
sensor.set_option(rs.option.enable_auto_exposure, True)

while True:
    print(sensor.get_option(rs.option.exposure))
    frames = pipeline.wait_for_frames()
    color_frame = frames.get_color_frame()
    color_image = np.asanyarray(color_frame.get_data())
    cv2.imshow('win', color_image)
    cv2.waitKey(1)

程序启动后,分别将摄像头在光暗处来回移动
结果:
在这里插入图片描述
曝光值一直都是156没变。。。。

然后我手动将曝光值设置成156,发现:
在这里插入图片描述
没有自动曝光的效果,极差!

难道说,在pipeline start后,就没有办法获取到实时曝光值了吗???

测试摄像头在不同曝光值下的帧生成时间

我擦嘞,发现测不出来,无论把曝光时间设为多少,它都是按照设置的帧率传过来,30fps,每帧就约33ms。。。

增大曝光值,它的残影就多了,就像本来要曝光200ms,它强制33ms就传过来一样,没爆光完全。。。

所以以前看到视频一卡一卡的,以为是帧传送慢了,其实不是,这是假象,真实的情况是图片存在残影,感觉里面物体移动变慢了,所以看起来像一卡一卡的一样

无论如何,现在还是暂时就使用它的自动曝光吧

# -*- coding: utf-8 -*-
"""
@File    : 200109_测试不同曝光值下帧生成时间.py
@Time    : 2020/1/9 16:52
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""

import time

import numpy as np
import pyrealsense2 as rs
import cv2

ctx = rs.context()

for dev in ctx.query_devices():
    # 先将设备的序列号放进一个变量里,免得在下面for循环里访问设备的信息过多(虽然不知道它会不会每次都重新访问)
    dev_serial = dev.get_info(rs.camera_info.serial_number)
    # 匹配序列号,重置我们需重置的特定摄像头(注意两个for循环顺序,哪个在外哪个在内很重要,不然会导致刚重置的摄像头又被访问导致报错)
    if '838212073161' == dev_serial:
        dev.hardware_reset()
        # 像下面这条语句居然不会报错,不是刚刚才重置了dev吗?莫非区别在于没有通过for循环ctx.query_devices()去访问?
        # 是不是刚重置后可以通过ctx.query_devices()去查看有这个设备,但是却没有存储设备地址?如果是这样,
        # 也就能够解释为啥能够通过len(ctx.query_devices())函数获取设备数量,但访问序列号等信息就会报错的原因了
        print('摄像头{}初始化成功'.format(dev.get_info(rs.camera_info.serial_number)))
# 如果只有一个摄像头,要让它睡够5秒(避免出错,保险起见)
time.sleep(5)

pipeline = rs.pipeline(ctx)
cfg = rs.config()
cfg.enable_device('838212073161')
cfg.enable_stream(rs.stream.depth, 640, 360, rs.format.z16, 30)
cfg.enable_stream(rs.stream.color, 640, 360, rs.format.bgr8, 30)
pipeline_profile = pipeline.start(cfg)

sensor = pipeline.get_active_profile().get_device().query_sensors()[1]
sensor.set_option(rs.option.exposure, 330)
sensor.set_option(rs.option.auto_exposure_priority, True)

time0 = time.time()
while True:
    frames = pipeline.wait_for_frames()
    color_frame = frames.get_color_frame()
    color_image = np.asanyarray(color_frame.get_data())
    cv2.imshow('win', color_image)
    cv2.waitKey(1)
    time_difference = time.time() - time0
    print(time_difference)
    time0 = time.time()
    # cv2.imwrite('{:.3f}.jpg'.format(time.time()), color_image)

在这里插入图片描述
参考文章:Intel Realsense D435 pyrealsense2 get_option_range() 获取rs.option中参数值取值范围 获取默认值

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dontla

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值