Intel Realsense D435 测试摄像头在不同曝光值下的帧生成时间(防止曝光时间过长导致fps下降)auto_exposure_priority(没成功)
文章目錄
- 不用測了
- 下面測試auto_exposure_priority參數(shù)在自動曝光下的作用
- 下面測試在自動曝光模式下如何實時獲取曝光值
- 測試攝像頭在不同曝光值下的幀生成時間
不用測了
參考文章:Intel Realsense D435 pyrealsense2 get_option_range() 獲取rs.option中參數(shù)值取值范圍
突然發(fā)現(xiàn),option.py中有option.auto_exposure_priority參數(shù)能夠限制自動曝光以維持恒定的fps速率,所以就不用擔心曝光時間過長導致fps下降了
想了想,不對,還是要測
因為自動曝光優(yōu)先是在自動曝光開啟時才用到的,當自動曝光關(guān)閉時,它就失去作用了。。。我檢驗一下
# -*- coding: utf-8 -*- """ @File : 200108_測試獲取Intel_Realsense_options參數(shù).py @Time : 2020/1/8 13:18 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """ import timeimport numpy as np import pyrealsense2 as rs import cv2ctx = 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結(jié)果:
將曝光值設(shè)置為5000后,明顯感覺傳輸幀變慢了(其實沒慢,就是沒曝光完全,存在殘影),說明auto_exposure_priority并未限制曝光值以維持幀速率,為了保證驗證的準確性,我又將auto_exposure_priority設(shè)置為False,發(fā)現(xiàn)還是同樣的結(jié)果
下面測試auto_exposure_priority參數(shù)在自動曝光下的作用
# -*- coding: utf-8 -*- """ @File : 200109_測試攝像頭自動曝光優(yōu)先.py @Time : 2020/1/9 14:43 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """import numpy as np import pyrealsense2 as rs import cv2ctx = 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)結(jié)果:
將auto_exposure_priority設(shè)置為False,發(fā)現(xiàn)并沒有出現(xiàn)幀速率下降的現(xiàn)象,每幀傳來都約0.033秒(設(shè)置幀速率為30幀每秒):
將auto_exposure_priority設(shè)置為True,結(jié)果還是相同
那這個auto_exposure_priority參數(shù)有啥用???
仔細觀察,還是有區(qū)別的,當設(shè)置auto_exposure_priority為True時,當攝像頭的場景由暗向光轉(zhuǎn)變,圖像會突然閃亮一下,像是曝光過度的感覺,當場景由光向暗轉(zhuǎn)變時,攝像頭會在一瞬間暗得特別厲害,就是過渡不平滑;但是如果auto_exposure_priority設(shè)置為False時,過渡就會非常平滑
由于不知道這種平滑過渡或不平滑過渡會對我們項目帶來哪些影響,就暫時按照它默認的設(shè)置吧,默認為Ture,參考:Intel Realsense D435 pyrealsense2 get_option_range() 獲取rs.option中參數(shù)值取值范圍
下面測試在自動曝光模式下如何實時獲取曝光值
# -*- coding: utf-8 -*- """ @File : 200108_測試獲取Intel_Realsense_options參數(shù).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 cv2ctx = 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)程序啟動后,分別將攝像頭在光暗處來回移動
結(jié)果:
曝光值一直都是156沒變。。。。
然后我手動將曝光值設(shè)置成156,發(fā)現(xiàn):
沒有自動曝光的效果,極差!
難道說,在pipeline start后,就沒有辦法獲取到實時曝光值了嗎???
測試攝像頭在不同曝光值下的幀生成時間
我擦嘞,發(fā)現(xiàn)測不出來,無論把曝光時間設(shè)為多少,它都是按照設(shè)置的幀率傳過來,30fps,每幀就約33ms。。。
增大曝光值,它的殘影就多了,就像本來要曝光200ms,它強制33ms就傳過來一樣,沒爆光完全。。。
所以以前看到視頻一卡一卡的,以為是幀傳送慢了,其實不是,這是假象,真實的情況是圖片存在殘影,感覺里面物體移動變慢了,所以看起來像一卡一卡的一樣
無論如何,現(xiàn)在還是暫時就使用它的自動曝光吧
# -*- coding: utf-8 -*- """ @File : 200109_測試不同曝光值下幀生成時間.py @Time : 2020/1/9 16:52 @Author : Dontla @Email : sxana@qq.com @Software: PyCharm """import timeimport numpy as np import pyrealsense2 as rs import cv2ctx = rs.context()for dev in ctx.query_devices():# 先將設(shè)備的序列號放進一個變量里,免得在下面for循環(huán)里訪問設(shè)備的信息過多(雖然不知道它會不會每次都重新訪問)dev_serial = dev.get_info(rs.camera_info.serial_number)# 匹配序列號,重置我們需重置的特定攝像頭(注意兩個for循環(huán)順序,哪個在外哪個在內(nèi)很重要,不然會導致剛重置的攝像頭又被訪問導致報錯)if '838212073161' == dev_serial:dev.hardware_reset()# 像下面這條語句居然不會報錯,不是剛剛才重置了dev嗎?莫非區(qū)別在于沒有通過for循環(huán)ctx.query_devices()去訪問?# 是不是剛重置后可以通過ctx.query_devices()去查看有這個設(shè)備,但是卻沒有存儲設(shè)備地址?如果是這樣,# 也就能夠解釋為啥能夠通過len(ctx.query_devices())函數(shù)獲取設(shè)備數(shù)量,但訪問序列號等信息就會報錯的原因了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() - time0print(time_difference)time0 = time.time()# cv2.imwrite('{:.3f}.jpg'.format(time.time()), color_image)
參考文章:Intel Realsense D435 pyrealsense2 get_option_range() 獲取rs.option中參數(shù)值取值范圍 獲取默認值
總結(jié)
以上是生活随笔為你收集整理的Intel Realsense D435 测试摄像头在不同曝光值下的帧生成时间(防止曝光时间过长导致fps下降)auto_exposure_priority(没成功)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: RuntimeError: get_ac
- 下一篇: Intel Realsense D435