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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Intel Realsense C/C++ 转 python (1)rs-hello-realsense 获取摄像头正中心对应的深度数据 get_distance()

發布時間:2025/3/19 python 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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。
除高級功能外,所有功能都通過單個標頭提供:

#include // Include RealSense Cross Platform 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()的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。