Intel Realsense C/C++ 转 python (9)rs-multicam 多摄像头可视化窗体显示
https://dev.intelrealsense.com/docs/code-samples
The multicam sample demonstrates the ability to use the SDK for streaming and rendering multiple devices simultaneously.
多摄像头示例演示了使用SDK来同时流式传输和渲染多个设备的能力。
C/C++源码:
代码概述
与任何SDK应用程序一样,我们包括英特尔实感跨平台API:
#include // Include RealSense Cross Platform API
在此示例中,我们还将使用以下辅助库example.hpp
:
#include "example.hpp" // Include short list of convenience functions for rendering
examples.hpp 让我们轻松地打开一个新窗口并准备要渲染的纹理。
我们使用的第一个对象是window,它将用于显示所有摄像机的图像。
// Create a simple OpenGL window for rendering:
window app(1280, 960, "CPP Multi-Camera Example");
本window类驻留在example.hpp
,让我们轻松地打开一个新的窗口,为渲染准备纹理。
接下来,我们定义示例中要使用的对象。
rs2::context ctx; // Create librealsense context for managing devicesrs2::colorizer colorizer; // Utility class to convert depth data RGBstd::vector pipelines;
该rs2::context
封装封装了所有设备和传感器,并提供了一些其他功能。我们使用rs2::colorizer
将深度数据转换为RGB格式。
在示例中,我们使用多个rs2::pipeline
对象,每个对象控制单个硬件设备的寿命。
该示例的流程从列出并激活所有连接的英特尔®实感™设备开始:
// Start a streaming pipe per each connected device
for (auto&& dev : ctx.query_devices())
{rs2::pipeline pipe(ctx);rs2::config cfg;cfg.enable_device(dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER));pipe.start(cfg);pipelines.emplace_back(pipe);
}
首先,我们rs2::pipeline
为每个识别的设备分配对象。请注意,我们rs2::context
在所有rs2::pipeline
实例之间共享对象。
rs2::pipeline pipe(ctx);
要将特定设备映射到新分配的管道,我们定义rs2::config
对象,并为其分配设备的序列号。
然后,我们请求rs::pipeline
开始流式传输并产生帧。
pipe.start(cfg);
由于我们未指定明确的流请求,因此在内部将每个设备配置为运行针对该特定设备推荐的一组预定义流配置文件。
添加设备后,我们开始应用程序的主循环:
while (app)
在每个应用周期中,我们遍历已注册的设备并检索所有可用的帧:
// Collect the new frames from all the connected devices
std::vector new_frames;
for (auto &&pipe : pipelines)
{rs2::frameset fs;if (pipe.poll_for_frames(&fs)){for (rs2::frame& f : fs)new_frames.emplace_back(f);}
}
每rs::pipeline
一个都针对为其分配的设备配置的所有流产生同步的帧集合。这些都包含在rs2::frameset
对象中。
的rs2::frameset
本身为一个包装composite_frame
,它可以保存比单个类型的帧的更多。
为了最大程度地减少对UI的影响,我们使用非阻塞帧轮询方法:
if (pipe.poll_for_frames(&fs))
为了简化演示,我们将这些rs2::frameset
容器分成单独的帧集,并将它们存储在标准C ++容器中,以备后用:
for (rs2::frame& f : fs)new_frames.emplace_back(f);
深度数据以uint16_t
类型传送,无法直接渲染,因此我们rs2::colorizer
将深度表示转换为人类可读的RGB贴图:
// Convert the newly-arrived frames to render-friendly format
for (const auto& frame : new_frames)
{render_frames[frame.get_profile().unique_id()] = colorizer.process(frame);
}
最后发送收集的帧以更新openGl马赛克:
app.show(render_frames);
python:
# Include short list of convenience functions for rendering
import pyrealsense2 as rs# 自己编的 20191009
import cv2
import numpy as np# Create a simple OpenGL window for rendering:
# window app(1280, 960, "CPP Multi-Camera Example");# Create librealsense context for managing devices
ctx = rs.context()# Utility class to convert depth data RGB
# colorizer = rs.colorizer()# std::vector pipelines;
# 创建存放pipeline对象的空列表:
pipelines = []# Start a streaming pipe per each connected device
for dev in ctx.query_devices():# print(dev)# 接了两个D435摄像头:# <pyrealsense2.device: Intel RealSense D435 (S/N: 827312071726)># <pyrealsense2.device: Intel RealSense D435 (S/N: 838212074152)>pipe = rs.pipeline(ctx)cfg = rs.config()cfg.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 15)cfg.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 15)cfg.enable_device(dev.get_info(rs.camera_info.serial_number))# print(dev.get_info)# < bound method PyCapsule.get_info of < pyrealsense2.device: Intel RealSense D435(S / N: 827312071726) >># < bound method PyCapsule.get_info of < pyrealsense2.device: Intel RealSense D435(S / N: 838212074152) >># print(dev.get_info(rs.camera_info.serial_number))# 接了两个D435摄像头,显示:# 827312071726# 838212074152pipe.start(cfg)pipelines.append(pipe)# print(pipelines)# 接了两个D435摄像头,因为是在循环内,第一次打印了一个元素,第二次打印了两个元素:# [ < pyrealsense2.pyrealsense2.pipeline object at 0x0000023DD3CE5D88 >]# [ < pyrealsense2.pyrealsense2.pipeline object at 0x0000023DD3CE5D88 >, < pyrealsense2.pyrealsense2.pipeline object at 0x0000023DC44EBA08 >]# reformed by Dontla at 20191009
while True:image_set = []for pipe in pipelines:frames = pipe.wait_for_frames()depth_frame = frames.get_depth_frame()color_frame = frames.get_color_frame()if not depth_frame or not color_frame:continuedepth_image = np.asanyarray(depth_frame.get_data())color_image = np.asanyarray(color_frame.get_data())depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)images = np.hstack((color_image, depth_colormap))image_set.append(images)image_stack = image_set[0]for images in image_set[1:]:image_stack = np.vstack((image_stack, images))cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)cv2.imshow('RealSense', image_stack)cv2.waitKey(1)'''
# 老的,我要把它们全用自己的方式改写了!20191009while True:# Collect the new frames from all the connected devices# std::vector new_frames;new_frames = []for pipe in pipelines:# rs2::frameset fs;# 到底是用frame还是composite_frame还是frame_queue?# fs = rs.frame()if pipe.poll_for_frames():fs = pipe.poll_for_frames()new_frames.append(fs)# 自己编的 20191009# 思路:遍历new_frames,将复合帧拆分成深度帧和RGB帧,然后将他们堆叠起来显示。for frames in new_frames:depth_frame = frames.get_depth_frame()color_frame = frames = frames.get_color_frame()depth_image = np.asanyarray(depth_frame.get_data())color_image = np.asanyarray(color_frame.get_data())depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)images = np.hstack((color_image, depth_colormap))cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)cv2.imshow('RealSense', images)cv2.waitKey(1)# for f in fs:# print("开始打印")# print(pipe)# print(f)# new_frames.append(f)# 每个pipe输出一个帧地址,两个输出两个,遍历完后重新while True,new_frames清空。# print(new_frames)# # Convert the newly-arrived frames to render-friendly format# render_frames = []# for frame in new_frames:# # print(frame.get_profile().unique_id())# render_frames[frame.get_profile().unique_id()] = colorizer.process(frame)# print(render_frames)
'''
接两个摄像头,最后生成结果:
正常来说,无论多接几个摄像头,都会像上面那样垂直叠加,因为没有设置自适应屏幕,所以某些情况下画面过多有可能会超出屏幕范围之外而无法被肉眼正常看到。
Intel Realsense C/C++ 转 python (9)rs-multicam 多摄像头可视化窗体显示相关推荐
- Intel Realsense C/C++ 转 python rs-align 使用深度颜色映射介绍空间流对齐的概念(转不起来,缺少信息)
源网址:rs-align Overview This example introduces the concept of spatial stream alignment. For example u ...
- Intel Realsense C/C++ 转 python (1)rs-hello-realsense 获取摄像头正中心对应的深度数据 get_distance()
https://dev.intelrealsense.com/docs/code-samples Demonstrates the basics of connecting to a RealSens ...
- python调用海康网络摄像头,实时显示监控内容
用网线将海康威视摄像头与电脑连接在一起:(或者用交换机,在一个交换机下面) 海康摄像头的默认ip是192.168.1.64 效果:和通过海康摄像头网址效果一样 rtsp://用户名:密码@ip地址/S ...
- Intel RealSense L515 motion的计算与可视化
文章目录 前言 一.环境准备 二.具体步骤 1.示例下载 2.代码编译 3.填坑 前言 前面的文章介绍了将L515数据映射至UE当中,本篇文章将针对Intel RealSense SDK 2.0,进行 ...
- python如何拟合三维平面(拟合Intel Realsense D435深度数据点)
文章目录 拟合Intel Realsense D435深度数据点 参考文章:[MQ笔记]超简单的最小二乘法拟合平面(Python) import numpy as np import matplotl ...
- python Intel Realsense D435 多线程资源分配问题(卡住、卡死)
在使用python多线程调用Intel Realsense D435多个摄像头时,发现pyrealsense的例如pipeline.start().context.query_devices()函数会 ...
- python Intel Realsense udp协议 局域网传输实时视频流并通过窗口显示 (opencv压缩解码)
文章目录 发送端 接收端 执行结果 发送端 接收端 发送端 # -*- coding: utf-8 -*- """ @File : 200103_obstacle_det ...
- Intel Realsense D435 python (Python Wrapper)examples 官方案例汇总
From pypi/pyrealsense 1.Intel Realsense D435 python (Python Wrapper)example -1: quick start (快速开始) F ...
- Intel Realsense D435 python 从深度相机realsense生成pcl点云
引用文章:python 从深度相机realsense生成pcl点云 从深度相机realsense生成pcl点云 一.通过realsense取得深度信息和彩色信息 二.获取坐标和色彩信息 三.通过pcl ...
最新文章
- 解决训练不稳定性,何恺明团队新作来了!自监督学习+Transformer=MoCoV3
- 1万属性,100亿数据,每秒10万吞吐,架构如何设计?
- Delphi XE 使用 MySQL 数据库一个奇怪的问题
- P3159-[CQOI2012]交换棋子【费用流】
- php如何监听页面滚动,html5中在元素滚动条在滚动时触发的事件onscroll
- LESS vs SASS?选择哪种CSS样式编程语言?
- Mysql学习总结(84)—— Mysql的主从复制延迟问题总结
- 【调试手段】linux下valgrind内存泄露检查
- 编译安装postfix+sasl+mysql+dovecot+extmail构建完成的邮件系统(一)
- input输入框大小设置_Qualtrics调查问卷设计1-如何在输入框前后添加辅助文字
- 史上最全GIS相关软件(CAD、FME、Arcgis、ArcgisPro)
- 8queen(稍后补)
- 网站SEO过程中的死链处理
- POJ 1129 Channel Allocation(四色定理)
- excel自动填充脚本(awk)
- Linux 重新加载 nginx 配置命令
- 23岁IT男与女友分手,扔下200万元分手费走了。。。
- 示波器观察IIC通讯协议-STM32F4读写24C08EEPROM时序图-新人首更
- 30. 串联所有单词的子串
- 217 绿豆蛙的归宿(数学期望)