Intel Realsense C/C++ 转 python (1)rs-hello-realsense 获取摄像头正中心对应的深度数据 get_distance()
生活随笔
收集整理的這篇文章主要介紹了
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 RealSense device and using depth data
演示連接到RealSense設備和使用深度數據的基礎知識
C/C++源碼:
代碼概述
首先,我們包括英特爾?實感?跨平臺API。
除高級功能外,所有功能都通過單個標頭提供:
接下來,我們創建并啟動RealSense管道。管道是控制攝像機枚舉和流式傳輸的主要高級基本命令。
// Create a Pipeline - this serves as a top-level API for streaming and processing frames rs2::pipeline p;// Configure and start the pipeline p.start();一旦管道配置完成,我們就可以循環等待新幀。
RealSense攝像機通常提供多個視頻,運動或姿勢流。wait_for_frames功能將阻塞,直到來自各種已配置流的下一組相干幀為止。
// Block program until frames arrive rs2::frameset frames = p.wait_for_frames();要從深度數據流中獲取第一幀,可以使用get_depth_frame輔助函數:
// Try to get a frame of a depth image rs2::depth_frame depth = frames.get_depth_frame();接下來,我們查詢默認的深度框架尺寸(每個傳感器的深度尺寸可能有所不同):
// Get the depth frame's dimensions float width = depth.get_width(); float height = depth.get_height();要獲取特定像素(幀中心)的距離,可以使用get_distance函數:
// Query the distance from the camera to the object in the center of the image float dist_to_center = depth.get_distance(width / 2, height / 2);剩下的唯一一件事就是將所得的距離打印到屏幕上:
// Print the distance std::cout << "The camera is facing an object " << dist_to_center << " meters away \r";python:
# Include RealSense Cross Platform API import pyrealsense2 as rs# Create a Pipeline - this serves as a top-level API for streaming and processing frames p = rs.pipeline()# Configure and start the pipeline p.start()# Block program until frames arrive frames = p.wait_for_frames()# Try to get a frame of a depth image depth = frames.get_depth_frame()# Get the depth frame's dimensions width = depth.get_width() height = depth.get_height()print(width, " ", height)# Query the distance from the camera to the object in the center of the image dist_to_center = depth.get_distance(int(width / 2), int(height / 2))# Print the distance print("The camera is facing an object ", dist_to_center, " meters away \r")# 640 480 # The camera is facing an object 65.53500366210938 meters away# 輸出不是0就是65.53500366210938,不知道啥情況 # 原因:usb2.0不行,換成usb3.0就能正常獲取深度了。注意不要太近,太近(<30cm)也不能獲取深度(值為0)。注:get_distance()函數有可能把窗口搞奔潰,不建議使用!!!!
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的Intel Realsense C/C++ 转 python (1)rs-hello-realsense 获取摄像头正中心对应的深度数据 get_distance()的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何查看电脑显卡参数? gpuZ
- 下一篇: Intel Realsense C/C+