• 摄像头重置后它自己不能马上恢复,如果我们重置后立即访问它们,就会出错,以下是一些问题记录:

  • 之前是使用device=ctx.query_device(),后面重置后检测摄像头的时候直接用len(device),这样肯定是不行的,因为device储存的是重置前的设备列表,而ctx.query_device()在进行操作后是会变的,所以我们需要重新运行len(ctx.query_device())来检测。

  • 以下是对摄像头重置后使用len(ctx.query_device())循环测试多组打印1000次的结果:

Intel Realsense D435 hardware_reset()后循环打印测试len(ctx.query_device())结果

# D·C 191202:猜测摄像头重置后的若干秒内,摄像头是不稳定的,
# 这跟访问ctx.query_devices()时设备丢失是否是同一回事,有待考证!# D·C 191202:除此之外,我还怀疑,访问ctx.query_devices()会对设备连接造成影响,
# 在这里,我们尽量减少访问频率。如果没有影响,那还是要等设备稳定再运行。

修改后代码:https://blog.csdn.net/Dontla/article/details/103260753#201912021_202

  • 出现了,错误提示Camera not connected!,应该是没等摄像头稳定就访问造成的,虽然摄像头个数已然为6,但下一次可能就访问不到了,说明在未稳定状态下访问,是有问题的,所以,我们需要添加稳定检测机制,比如,连续访问len(ctx.query_devices()),个数都为6:

  • 有一次运行,在程序开头hardware_reset()那儿ctx.query_devices()就少摄像头了,导致其中一个摄像头没有被重置到:

    所以准备把连续验证机制的代码在重置前也加上:
    https://blog.csdn.net/Dontla/article/details/103260753#201912022_469

191212

经过一段时间的测试,发现采用 连续检测 --> 摄像头初始化 --> 连续检测 --> 运行识别 的方法对于摄像头的稳定运行是良好的:

开始连续验证,连续验证稳定值:10,最大验证次数:100:
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6开始初始化摄像头:
摄像头838212073161初始化成功
摄像头827312071726初始化成功
摄像头838212073249初始化成功
摄像头827312070790初始化成功
摄像头836612072369初始化成功
摄像头826212070395初始化成功开始连续验证,连续验证稳定值:10,最大验证次数:100:
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:5
摄像头个数:5
摄像头个数:5
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6
摄像头个数:6serial number 1:838212073161;usb port:3.2
serial number 2:827312071726;usb port:3.2
serial number 3:838212073249;usb port:3.2
serial number 4:827312070790;usb port:3.2
serial number 5:836612072369;usb port:3.2
serial number 6:826212070395;usb port:3.2开始识别:Process finished with exit code -1

191212

经过测试发现,在摄像头执行hardware_reset()后,即使通过len(ctx.query_devices())去检测摄像头个数等于全部摄像头数量,用for i in ctx.query_devices()去访问摄像头信息也有可能会失败(如获取摄像头序列号等)

已知三种报错形式:

RuntimeError: MFCreateDeviceSource(_device_attrs, &_source) returned: HResult 0xc00d36b6: "

RuntimeError


相同的代码,以上三种报错会交替出现。。。

以下每个摄像头重置后打印len(ctx.query_devices())的结果,猜测打印出数字5的情况可能是刚刚重置的摄像头并未完全重置成功,导致访问失败的情况出现:

RuntimeError: Camera not connected!
开始初始化摄像头:
6
6
6
6
6
5
5
6
6
6
838212073161 827312071726 838212073249 827312070790 836612072369 826212070395 摄像头838212073161初始化成功
6
6
6
6
5
5
5
6
6
6
838212073161 827312071726 838212073249 827312070790 836612072369 826212070395 摄像头827312071726初始化成功
6
6
6
6
5
5
5
6
6
6
838212073161 827312071726 838212073249 827312070790 836612072369 826212070395 摄像头838212073249初始化成功
6
6
6
6
5
5
5
6
6
6
838212073161 827312071726 838212073249 827312070790 836612072369 826212070395 摄像头827312070790初始化成功
6
6
6
6
5
5
5
6
6
6
838212073161 827312071726 838212073249 827312070790 836612072369 826212070395 摄像头836612072369初始化成功
6
6
6
6
5
5
5
6
6
6
838212073161 827312071726 838212073249 827312070790 836612072369 826212070395 摄像头826212070395初始化成功

因为我们的本意是想要通过摄像头序列号去重置其中若干个摄像头,但是用for循环时去访问摄像头序列号以便于与我们想要重置的摄像头序列号做对比时,若上一个摄像头刚被重置,它还未完全恢复稳定,它是不可访问的,这时去访问它就会出错,有没有一种可能,就是我们先遍历全部摄像头的序列号,然后与我们需要重置的摄像头序列号作对比,找出我们需要重置的设备,然后将它(就是那个dev对象)存进一个列表里,再用一个for循环将它重置。

不过好像其实也没必要那样做,我们可以通过for循环遍历设备,然后把需重置的全重置了,然后直接运行连续验证机制就可以了

(事实证明,在摄像头正常工作传输流的情况下,也是能够通过for i in ctx.query_devices(): print(i.get_info(rs.camera_info.serial_number), end=' ')访问信息的):
(访问len(ctx.query_devices()))也可以



解决办法:
直接上代码吧:

# -*- coding: utf-8 -*-
"""
@File    : obstacle_detection.py
@Time    : 2019/12/11 10:24
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
import timeimport numpy as np
import pyrealsense2 as rs
import cv2
import sysclass ObstacleDetection(object):def __init__(self):self.cam_serials = ['838212073161', '827312071726']def obstacle_detection(self):# 摄像头个数(在这里设置所需使用摄像头的总个数)cam_num = 6ctx = rs.context()'''连续验证机制'''# D·C 1911202:创建最大验证次数max_veri_times;创建连续稳定值continuous_stable_value,用于判断设备重置后是否处于稳定状态max_veri_times = 100continuous_stable_value = 10print('\n', end='')print('开始连续验证,连续验证稳定值:{},最大验证次数:{}:'.format(continuous_stable_value, max_veri_times))continuous_value = 0veri_times = 0while True:devices = ctx.query_devices()connected_cam_num = len(devices)if connected_cam_num == cam_num:continuous_value += 1if continuous_value == continuous_stable_value:breakelse:continuous_value = 0veri_times += 1if veri_times == max_veri_times:print("检测超时,请检查摄像头连接!")sys.exit()print('摄像头个数:{}'.format(connected_cam_num))'''循环reset摄像头'''# hardware_reset()后是不是应该延迟一段时间?不延迟就会报错print('\n', end='')print('开始初始化摄像头:')for dev in ctx.query_devices():# 先将设备的序列号放进一个变量里,免得在下面for循环里访问设备的信息过多(虽然不知道它会不会每次都重新访问)dev_serial = dev.get_info(rs.camera_info.serial_number)# 匹配序列号,重置我们需重置的特定摄像头(注意两个for循环顺序,哪个在外哪个在内很重要,不然会导致刚重置的摄像头又被访问导致报错)for serial in self.cam_serials:if serial == 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)))'''连续验证机制'''# D·C 1911202:创建最大验证次数max_veri_times;创建连续稳定值continuous_stable_value,用于判断设备重置后是否处于稳定状态print('\n', end='')print('开始连续验证,连续验证稳定值:{},最大验证次数:{}:'.format(continuous_stable_value, max_veri_times))continuous_value = 0veri_times = 0while True:devices = ctx.query_devices()connected_cam_num = len(devices)if connected_cam_num == cam_num:continuous_value += 1if continuous_value == continuous_stable_value:breakelse:continuous_value = 0veri_times += 1if veri_times == max_veri_times:print("检测超时,请检查摄像头连接!")sys.exit()print('摄像头个数:{}'.format(connected_cam_num))'''配置各个摄像头的基本对象'''pipeline1 = rs.pipeline(ctx)pipeline2 = rs.pipeline(ctx)config1 = rs.config()config2 = rs.config()config1.enable_device(self.cam_serials[0])config2.enable_device(self.cam_serials[1])config1.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)config2.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)config1.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)config2.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)pipeline1.start(config1)pipeline2.start(config2)align1 = rs.align(rs.stream.color)align2 = rs.align(rs.stream.color)'''运行摄像头'''try:while True:frames1 = pipeline1.wait_for_frames()frames2 = pipeline2.wait_for_frames()aligned_frames1 = align1.process(frames1)aligned_frames2 = align2.process(frames2)aligned_depth_frame1 = aligned_frames1.get_depth_frame()aligned_depth_frame2 = aligned_frames2.get_depth_frame()color_frame1 = aligned_frames1.get_color_frame()color_frame2 = aligned_frames2.get_color_frame()if not aligned_depth_frame1 \or not color_frame1 \or not aligned_depth_frame2 \or not color_frame2:continuecolor_profile1 = color_frame1.get_profile()color_profile2 = color_frame2.get_profile()cvsprofile1 = rs.video_stream_profile(color_profile1)cvsprofile2 = rs.video_stream_profile(color_profile2)color_intrin1 = cvsprofile1.get_intrinsics()color_intrin2 = cvsprofile2.get_intrinsics()color_intrin_part1 = [color_intrin1.ppx, color_intrin1.ppy, color_intrin1.fx, color_intrin1.fy]color_intrin_part2 = [color_intrin2.ppx, color_intrin2.ppy, color_intrin2.fx, color_intrin2.fy]color_image1 = np.asanyarray(color_frame1.get_data())# color_image1 = np.asanyarray(frames1.get_color_frame().get_data())color_image2 = np.asanyarray(color_frame2.get_data())depth_image1 = np.asanyarray(aligned_depth_frame1.get_data())# depth_image1 = np.asanyarray(frames1.get_depth_frame().get_data())depth_image2 = np.asanyarray(aligned_depth_frame2.get_data())depth_colormap1 = cv2.applyColorMap(cv2.convertScaleAbs(depth_image1, alpha=0.03), cv2.COLORMAP_JET)depth_colormap2 = cv2.applyColorMap(cv2.convertScaleAbs(depth_image2, alpha=0.03), cv2.COLORMAP_JET)image1 = np.hstack((color_image1, depth_colormap1))image2 = np.hstack((color_image2, depth_colormap2))cv2.imshow('win1', image1)cv2.imshow('win2', image2)cv2.waitKey(1)finally:pipeline1.stop()pipeline2.stop()if __name__ == '__main__':ObstacleDetection().obstacle_detection()

Intel Realsense D435 hardware_reset() 摄像头重置记录 context.query_devices()相关推荐

  1. intel realsense d435深度摄像头使用

    intel realsense d435深度摄像头基本环境配置 基本参考官网给的教程来就ok的 ,这里还是发一下我最初配置d435的记录 官网链接: https://github.com/intel- ...

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

    文章目录 不用测了 下面测试auto_exposure_priority参数在自动曝光下的作用 下面测试在自动曝光模式下如何实时获取曝光值 测试摄像头在不同曝光值下的帧生成时间 不用测了 参考文章:I ...

  3. 为什么Intel Realsense D435深度摄像头在基于深度的水平方向障碍物检测(避障)方案中,摄像头不宜安装太高?

    补一句,为啥R与b对比就要比R与a对比更容易区分? 因为a与b的右端和障碍物R属同一深度,但b左端明显比a左端深度大,总体比a拥有差异性更大的深度范围,因此b与a相比,对R拥有差异性更大的深度范围, ...

  4. Intel Realsense D435 多摄像头多线程目标识别架构

    每一个摄像头单独开一个线程,摄像头配置是否要放进线程内? 每一个摄像头线程内单独处理错误信息 每一个摄像头要存储最新彩色帧和深度帧(用于识别和获取深度信息) 接收打击信号要一个线程,对打击信号进行排序 ...

  5. Tensorflow yolov3 Intel Realsense D435 单摄像头下各模块识别时间测试

    文章目录 1.一次循环总耗时 2.从循环开始到self.predict()之前 3.第一次循环主要耗时函数:wait_for_frames()(其实self.predict()函数在第一次循环更耗时) ...

  6. Intel Realsense D435 奇怪的现象记录:帧卡住,但wait_for_frame()不报错

    如图,一号四号摄像头视频流显示卡住了,但流传输并未停止,使用目标检测发现,摄像头每次传过来的都是同样的一帧: 但也有可能是加了这句,导致空帧被跳过了: if not locals()['aligned ...

  7. Intel Realsense D435 获取摄像头option参数值 get_option()

    def get_option(self, option): # real signature unknown; restored from __doc__"""get_o ...

  8. Intel Realsense D435 当摄像头运行过程中突然USB线断开,对RuntimeError: Frame didn't arrived within 5000的异常捕获及处理

    如图,在摄像头运行过程中,摄像头突然断开,可能设备需要对异常进行捕获并处理(如摄像头重连,发出警报,发送信号给车辆让它停止前进等) 需阅读,python异常捕获及处理 191225 通过捕获所有异常, ...

  9. Intel Realsense D435 hardware_reset()后循环打印测试len(ctx.query_device())结果

    测试代码 for i in range(20):for j in range(50):print(len(ctx.query_devices()), end='')print('\n', end='' ...

最新文章

  1. 「鸡娃」是家长无处安放的「应试」焦虑
  2. masonry的约束应该写在哪里_规划奇思|“中心城区”到底在哪里?和城镇开发边界是什么关系?...
  3. LoadRunner脚本增强技巧之检查点
  4. canvas入门实战--邀请卡生成与下载
  5. django 日志配置
  6. 算法python知乎_20个算法李小文知乎文章与Github代码汇总
  7. InfoQ观点:Java EE的未来
  8. GTK+图形化应用程序开发学习笔记(七)—标签构件.事件盒构件
  9. 团队二阶段冲刺个人工作总结7
  10. 计算机校园网网络系统设计方案,计算机网络课程设计-XX大学校园网网络设计方案.doc...
  11. 如何将png格式的图片缩小?png怎么缩小kb?
  12. 小水智能-智慧工地与传统工地相比,数字科技赋予了以下三大优势
  13. 软件随想录(local.joelonsoftware.com/wiki)-2001年04月21日 别让架构太空人吓到你 - Don't Let Architecture Astronauts Scar
  14. linux发行版本号列举,查看Linux发行版的名称及其版本号
  15. 指纹锁的识别与原理及安全性
  16. ESP32 HttpServer模式下 本地OTA 例程(基于ESP-IDF类似Arduino下OTAWebUpdater例程)
  17. 如何判断软件质量的的好坏,软件质量的特征
  18. Vue框架Vue-cli脚手架引入图片报错
  19. solr5.x快速入门
  20. 计算机程序设计员理论试题答案,计算机程序设计员理论试题库.doc

热门文章

  1. loadrunner脚本练习
  2. wgan 不理解 损失函数_AI初识:深度学习中常用的损失函数有哪些?
  3. 【PM模块】技术对象管理
  4. SAP MM模块的预留详解
  5. SAP 解决长时间不操作掉线问题
  6. 租房还是买房结婚?大数据告诉你年轻人的真实想法
  7. 在消费女性身材焦虑上,大码女装和BM风没有本质区别
  8. 相对定位android,appium相对位置定位元素----父节点/兄弟节点定位
  9. 订单生产计划表范本_生产计划管理与物料控制的实施步骤与要领
  10. kindle词典_kindle盖泡面是什么梗?kindle官方盖章泡面盖子 网友:定位准确