日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Intel Realsense C/C++ 转 python (9)rs-multicam 多摄像头可视化窗体显示

發(fā)布時間:2025/3/19 python 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Intel Realsense C/C++ 转 python (9)rs-multicam 多摄像头可视化窗体显示 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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來同時流式傳輸和渲染多個設(shè)備的能力。

C/C++源碼:

代碼概述
與任何SDK應(yīng)用程序一樣,我們包括英特爾實感跨平臺API:

#include // Include RealSense Cross Platform API

在此示例中,我們還將使用以下輔助庫example.hpp:

#include "example.hpp" // Include short list of convenience functions for rendering

examples.hpp 讓我們輕松地打開一個新窗口并準(zhǔn)備要渲染的紋理。

我們使用的第一個對象是window,它將用于顯示所有攝像機(jī)的圖像。

// Create a simple OpenGL window for rendering: window app(1280, 960, "CPP Multi-Camera Example");

本window類駐留在example.hpp,讓我們輕松地打開一個新的窗口,為渲染準(zhǔn)備紋理。

接下來,我們定義示例中要使用的對象。

rs2::context ctx; // Create librealsense context for managing devicesrs2::colorizer colorizer; // Utility class to convert depth data RGBstd::vector pipelines;

該rs2::context封裝封裝了所有設(shè)備和傳感器,并提供了一些其他功能。我們使用rs2::colorizer將深度數(shù)據(jù)轉(zhuǎn)換為RGB格式。
在示例中,我們使用多個rs2::pipeline對象,每個對象控制單個硬件設(shè)備的壽命。

該示例的流程從列出并激活所有連接的英特爾?實感?設(shè)備開始:

// 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為每個識別的設(shè)備分配對象。請注意,我們rs2::context在所有rs2::pipeline實例之間共享對象。

rs2::pipeline pipe(ctx);

要將特定設(shè)備映射到新分配的管道,我們定義rs2::config對象,并為其分配設(shè)備的序列號。
然后,我們請求rs::pipeline開始流式傳輸并產(chǎn)生幀。

pipe.start(cfg);

由于我們未指定明確的流請求,因此在內(nèi)部將每個設(shè)備配置為運(yùn)行針對該特定設(shè)備推薦的一組預(yù)定義流配置文件。

添加設(shè)備后,我們開始應(yīng)用程序的主循環(huán):

while (app)

在每個應(yīng)用周期中,我們遍歷已注冊的設(shè)備并檢索所有可用的幀:

// 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一個都針對為其分配的設(shè)備配置的所有流產(chǎn)生同步的幀集合。這些都包含在rs2::frameset對象中。
的rs2::frameset本身為一個包裝composite_frame,它可以保存比單個類型的幀的更多。

為了最大程度地減少對UI的影響,我們使用非阻塞幀輪詢方法:

if (pipe.poll_for_frames(&fs))

為了簡化演示,我們將這些rs2::frameset容器分成單獨的幀集,并將它們存儲在標(biāo)準(zhǔn)C ++容器中,以備后用:

for (rs2::frame& f : fs)new_frames.emplace_back(f);

深度數(shù)據(jù)以uint16_t類型傳送,無法直接渲染,因此我們rs2::colorizer將深度表示轉(zhuǎn)換為人類可讀的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); }

最后發(fā)送收集的幀以更新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; # 創(chuàng)建存放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攝像頭,因為是在循環(huán)內(nèi),第一次打印了一個元素,第二次打印了兩個元素:# [ < 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)''' # 老的,我要把它們?nèi)米约旱姆绞礁膶懥?#xff01;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,將復(fù)合幀拆分成深度幀和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) '''

接兩個攝像頭,最后生成結(jié)果:

正常來說,無論多接幾個攝像頭,都會像上面那樣垂直疊加,因為沒有設(shè)置自適應(yīng)屏幕,所以某些情況下畫面過多有可能會超出屏幕范圍之外而無法被肉眼正常看到。

總結(jié)

以上是生活随笔為你收集整理的Intel Realsense C/C++ 转 python (9)rs-multicam 多摄像头可视化窗体显示的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。