文章目录

  • 双管道方法
  • 回调callback方法

【D455】【python】How to get color_stream\depth_steam\accel_stream\gyro_stream at the same time?

MartyG-RealSense commented yesterday •
Hi @Dontla When streaming depth, color and IMU at the same time, there is sometimes a problem where the RGB stream becomes No Frames Received or more rarely, the IMU frames stop being received. To deal with this issue, the recommended solutions are to either use two separate pipelines (IMU alone on one pipeline and depth / color on the other pipeline), or to use callbacks.

For the separate pipeline approach, I recommend the Python script in the link below…

#5628 (comment)

For the callback approach in Python, the link below is a good reference.

#5417

双管道方法

# -*- coding: utf-8 -*-
"""
@File    : D455_double_pipeline.py
@Time    : 2020/12/19 16:07
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
## License: Apache 2.0. See LICENSE file in root directory.
## Parts of this code are
## Copyright(c) 2015-2017 Intel Corporation. All Rights Reserved.##################################################
##      configurable realsense viewer           ##
##################################################import pyrealsense2 as rs
import numpy as np
import cv2
import time#
# NOTE: it appears that imu, rgb and depth cannot all be running simultaneously.
#       Any two of those 3 are fine, but not all three: causes timeout on wait_for_frames()
#
device_id = None  # "923322071108" # serial number of device to use or None to use default
enable_imu = True
enable_rgb = True
enable_depth = True
# TODO: enable_pose
# TODO: enable_ir_stereo# Configure streams
if enable_imu:imu_pipeline = rs.pipeline()imu_config = rs.config()if None != device_id:imu_config.enable_device(device_id)imu_config.enable_stream(rs.stream.accel, rs.format.motion_xyz32f, 63)  # accelerationimu_config.enable_stream(rs.stream.gyro, rs.format.motion_xyz32f, 200)  # gyroscopeimu_profile = imu_pipeline.start(imu_config)if enable_depth or enable_rgb:pipeline = rs.pipeline()config = rs.config()# if we are provided with a specific device, then enable itif None != device_id:config.enable_device(device_id)if enable_depth:config.enable_stream(rs.stream.depth, 848, 480, rs.format.z16, 60)  # depthif enable_rgb:config.enable_stream(rs.stream.color, 424, 240, rs.format.bgr8, 60)  # rgb# Start streamingprofile = pipeline.start(config)# Getting the depth sensor's depth scale (see rs-align example for explanation)if enable_depth:depth_sensor = profile.get_device().first_depth_sensor()depth_scale = depth_sensor.get_depth_scale()print("Depth Scale is: ", depth_scale)if enable_depth:# Create an align object# rs.align allows us to perform alignment of depth frames to others frames# The "align_to" is the stream type to which we plan to align depth frames.align_to = rs.stream.coloralign = rs.align(align_to)try:frame_count = 0start_time = time.time()frame_time = start_timewhile True:last_time = frame_timeframe_time = time.time() - start_timeframe_count += 1## get the frames#if enable_rgb or enable_depth:frames = pipeline.wait_for_frames(200 if (frame_count > 1) else 10000)  # wait 10 seconds for first frameif enable_imu:imu_frames = imu_pipeline.wait_for_frames(200 if (frame_count > 1) else 10000)if enable_rgb or enable_depth:# Align the depth frame to color framealigned_frames = align.process(frames) if enable_depth and enable_rgb else Nonedepth_frame = aligned_frames.get_depth_frame() if aligned_frames is not None else frames.get_depth_frame()color_frame = aligned_frames.get_color_frame() if aligned_frames is not None else frames.get_color_frame()# Convert images to numpy arraysdepth_image = np.asanyarray(depth_frame.get_data()) if enable_depth else Nonecolor_image = np.asanyarray(color_frame.get_data()) if enable_rgb else None# Apply colormap on depth image (image must be converted to 8-bit per pixel first)depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03),cv2.COLORMAP_JET) if enable_depth else None# Stack both images horizontallyimages = Noneif enable_rgb:images = np.hstack((color_image, depth_colormap)) if enable_depth else color_imageelif enable_depth:images = depth_colormap# Show imagescv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)if images is not None:cv2.imshow('RealSense', images)if enable_imu:accel_frame = imu_frames.first_or_default(rs.stream.accel, rs.format.motion_xyz32f)gyro_frame = imu_frames.first_or_default(rs.stream.gyro, rs.format.motion_xyz32f)print("imu frame {} in {} seconds: \n\taccel = {}, \n\tgyro = {}".format(str(frame_count),str(frame_time - last_time), str(accel_frame.as_motion_frame().get_motion_data()), str(gyro_frame.as_motion_frame().get_motion_data())))# Press esc or 'q' to close the image windowkey = cv2.waitKey(1)if key & 0xFF == ord('q') or key == 27:cv2.destroyAllWindows()breakfinally:# Stop streamingpipeline.stop()

不错的,能正常运行

回调callback方法

代码运行不成功,还没解决咋弄

# -*- coding: utf-8 -*-
"""
@File    : D455_callback.py
@Time    : 2020/12/25 11:30
@Author  : Dontla
@Email   : sxana@qq.com
@Software: PyCharm
"""
import pyrealsense2 as rspipeline = rs.pipeline()def test_callback(fs):global framesetframeset = fspipeline.stop()profile = pipeline.start(test_callback)
# print(profile)
# <pyrealsense2.pyrealsense2.pipeline_profile object at 0x000001FF99DE3490>profile.get_streams()
# print(stream)
# [<pyrealsense2.video_stream_profile: 1(0) 848x480 @ 30fps 1>, <pyrealsense2.video_stream_profile: 2(0) 1280x720 @ 30fps 5>, <pyrealsense2.stream_profile: 5(0) @ 200fps 16>, <pyrealsense2.stream_profile: 6(0) @ 63fps 16>]frameset
D:\20191031_tensorflow_yolov3\python\python.exe C:/Users/Administrator/Desktop/test_D455/D455_callback.py
Traceback (most recent call last):File "C:/Users/Administrator/Desktop/test_D455/D455_callback.py", line 28, in <module>frameset
NameError: name 'frameset' is not definedProcess finished with exit code 1

D455 如何同时传输视频深度流和惯性单元IMU流?(双管道方法与调用回调方法)相关推荐

  1. linux fifo数据流,在linux / bash中使用非阻塞FIFO流式传输视频(示例代码)

    我正在努力实现以下目标: 将我的Raspberry Pi相机中的视频写入磁盘,不受任何流式干扰 通过网络流式传输相同的视频优化延迟 重要的是流不会干扰正在写入磁盘的视频,因为网络连接可能不稳定,例如W ...

  2. Robust Consistent Video Depth Estimation_具有鲁棒一致性的视频深度估计

    论文 Code 核心:利用卷积神经网络训练 单张图像深度估计 优化深度图的对齐 连续优化 共同优化相机位姿参数的内外参 估计的深度图3D对齐 解决Naive alignment:提出一种更灵活变形的模 ...

  3. 利用IP组播技术传输视频信息

    利用IP组播技术传输视频信息   随着全球互联网(Internet)的迅猛发展,上网人数正以几何级数快速增长,以因特网技术为主导的数据通信在通信业务总量中的比列迅速上升,因特网业务已成为多媒体通信业中 ...

  4. python传输视频文件_Python视频传输

    ubuntu16.04+python2+opencv (一) 开发前的准备工作 sudo apt-get install python-pip pip install numpy pip instal ...

  5. 视频深度学习:行为识别指南

    我的小程序: 待办计划:卷起来吧,少年! 我们记账:年薪50w够花么? 动作识别困难的原因: 1 巨大的计算成本: 一个简单的卷积2D网络用于101个类的分类只有~5M个参数,而相同的结构在膨胀为3D ...

  6. android实时传输视频Socket

    android实时传输视频Socket https://download.csdn.net/download/u012560682/7780979?spm=1001.2101.3001.5697 An ...

  7. 传输视频的带宽如何计算?传输4K视频需要多少带宽?

    在视频监控的实际运用中,很多配置都会影响视频传输的质量,比如清晰度.码率.视频存储空间等,跟这些内容相关的,就是网络的带宽.很多用户不知道带宽的概念是如何换算的,在很多高清视频传输项目当中,也难以计算 ...

  8. Consistent Video Depth Estimation——视频深度一致估计

    Paper | Code 文章核心: 提出一种算法--重构单眼视频中所有像素的稠密的几何一致的深度,其利用了传统的SFM(从运动中重构)来建立视频中像素的几何约束.与经典重建中的特殊先验不同的是,本文 ...

  9. 眼界大开 声临其境丨胡宜峰:视频深度伪造检测技术在内容安全领域的探索与实践

    导读:「眼界大开 声临其境」技术系列课第三期.网易易盾资深计算机视觉算法工程师胡宜峰带来了主题为<视频深度伪造检测技术在内容安全领域的探索与实践>技术分享. 讲师简介:胡宜峰,网易易盾资深 ...

最新文章

  1. asp.net内置对象了解
  2. 传统网站与营销型网站区别盘比
  3. python的可变对象和不可变对象
  4. 百度的html代码是什么,百度网页源代码是什么?
  5. getbook netty实战_Netty 入门教程
  6. 【抽象代数】类方程和有限群
  7. Alpha 冲刺报告2
  8. vision画流程图的软件_流程图制作软件visio|流程图制作软件visio vs2010 中文版 - 软件下载 - 绿茶软件园|33LC.com...
  9. 清华大学计算机系2016名单,清华大学2016年自主招生北京考生入选名单汇总
  10. 用户验收测试要求目标
  11. Unity基本认识——走进Unity
  12. c语言二维数组a中,a,a[0],a[0][0]的值与值的类型
  13. TSP的最佳解决方案
  14. Hashtable的用法
  15. 桌面出现“了解此图片”如何删除?
  16. 前端食堂技术周刊第 53 期:React Router 6.4、VS Code August 2022、2022 Google 谷歌开发者大会、Meta 开源 MemLab、Vue.js 技术内幕
  17. CSS中如何快速生成雪碧图
  18. 来,让我们认识一哈工程高等代数
  19. xp职称计算机考试题库,全国职称计算机考试题库(WindowsXP模块)
  20. sae 本地 php,如何在 SAE 下操作本地IO

热门文章

  1. GRUB2 管理器—Grub Customizer
  2. 用SCCM2007 R2管理Windows更新,SCCM系列之六
  3. mysql select db 废弃_php 项目放服务器显示mysql_connect 已经废弃 ?
  4. 7系统启动到一半停止_太突然!国际饮料巨头计划狂砍一半品牌,这些饮料就快喝不到了…...
  5. google浏览器javascript没反应_浏览器之导航这件小事
  6. 【一周入门MySQL—4】数据库进阶练习
  7. 【学习笔记】13、标准数据类型—元组
  8. SAP中破解系统管理员密码
  9. 如何查询MySql日志
  10. 如何配note,打补丁