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()函数有可能把窗口搞奔溃,不建议使用!!!!
Intel Realsense C/C++ 转 python (1)rs-hello-realsense 获取摄像头正中心对应的深度数据 get_distance()相关推荐
- Intel Realsense C/C++ 转 python (9)rs-multicam 多摄像头可视化窗体显示
https://dev.intelrealsense.com/docs/code-samples The multicam sample demonstrates the ability to use ...
- python Intel Real Sense D435 异常检测与抛出(获取/打印异常详细信息 traceback.print_exc())
文章目录 背景描述 首先熟悉一下python异常处理的几个关键字 摄像头USB断开异常 获取异常详细信息 背景描述 在摄像头运行的时候,有时候会遇到一些错误,比如帧传输错误引起的程序结束, 但更为严重 ...
- Intel Realsense D435 如何获取摄像头的内参?get_profile() video_stream_profile() get_intrinsics()
# 获取摄像头的内参是为了将像素坐标转化成实际坐标 import pyrealsense2 as rspipeline = rs.pipeline() config = rs.config() con ...
- python使用matplotlib可视化3D线框图、线框图可以将数据投影到指定的三维表面上,并输出可视化程度较高的三维效果图
python使用matplotlib可视化3D线框图.线框图可以将数据投影到指定的三维表面上,并输出可视化程度较高的三维效果图 目录
- Python中pandas检查dataframe中是否包含某个字段、或者数据列实战、检查dataframe中是否包含某个字段集合
Python中pandas检查dataframe中是否包含某个字段.或者数据列(column)实战 目录 Python中pandas检查dataframe中是否包含某个字段.或者数据列(column) ...
- python使用pandas通过聚合获取时序数据的最后一个指标数据(例如长度指标、时间指标)生成标签并与原表连接(join)进行不同标签特征的可视化分析
python使用pandas通过聚合获取时序数据的最后一个指标数据(例如长度指标.时间指标)生成标签并与原表连接(join)进行不同标签特征的可视化分析 目录
- python代码根据当前时间获取下一周的日期
python代码根据当前时间获取下一周的日期 #使用python代码根据当前日期计算下一周的日期范围 import datetime,calendar import pandas as pddef g ...
- 从python中的列表中获取唯一值[重复]
本文翻译自:Get unique values from a list in python [duplicate] This question already has an answer here: ...
- 使用Python在Selenium WebDriver中获取WebElement的HTML源代码
我正在使用Python绑定来运行Selenium WebDriver. from selenium import webdriver wd = webdriver.Firefox() 我知道我可以抓住 ...
最新文章
- C/C++得到系统启动项
- [NewLife.XCode]增量累加
- 面试常考的数据结构Java实现
- android 日期对话框,Android日期选择器对话框DatePickerDialog使用详解
- [PATCH] UBUNTU: SAUCE: (no-up) apparmor: Sync to apparmor3 - RC1(v3.4.x kernel)
- python 保证所有数据能够显示,而不是用省略号表示,不以科学计数显示
- eclipse汉化版的问题
- 你程序员,996这就是你的命
- Premiere 关键帧缩放
- 实验5、D/A转换实验
- 论文写作课程收获总结
- 鸿蒙系统如何设置字体,图解鸿蒙OS独特的字体系统!
- 用户之间imp的问题
- vue3 setup中获取地址栏参数
- 行业资讯 | 做到这几点,Revit建模效率提升,实用.
- 同一个路由重复点击报错的解决方法
- -XX:+UseCompressedOops 与 -XX:-UseCompressedOops
- 【精品】Thymeleaf 语法基础
- python 灰度共生矩阵进行特征提取(代码)
- 好听的计算机软件名称,好听的组合名字大全
热门文章
- 【实用】ABAP ALV单元格修改信息提示
- 【温故知新】CSS学习笔记(开发者工具介绍)
- ABAP ALV 颜色设置(行,列,单元格)
- abap submit 的使用方法
- ERP兵法——从案例透视方法(实施篇上)
- 没有PARAMETER ID,想 call TRANSACTION
- 我的世界服务器端口文件夹,我的世界手机版服务器ip端口地址大全
- java 重写方法 访问权限_为何Java中子类重写方法的访问权限不能低于父类中权限(内含里氏替换原则)...
- .net core dll 套壳加密_BCVP开发者说第4期:Remember.Core
- ubuntu安装mysql远程_Ubuntu18.04下远程安装MySQL