用python开启相机_如何用Python打开realsenseD435相机并获取相机参数
如何用Python打开realsenseD435相机
import pyrealsense2 as rs
import numpy as np
import cv2
if __name__ == "__main__":
# Configure depth and color streams
pipeline = rs.pipeline()
config = rs.config()
config.enable_device_from_file("666.bag")#这是打开相机录制的视频
# config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)这是打开相机
#config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
# Start streaming
pipeline.start(config)
try:
while True:
# Wait for a coherent pair of frames: depth and color
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
color_frame = frames.get_color_frame()
if not depth_frame or not color_frame:
continue
# Convert images to numpy arrays
depth_image = np.asanyarray(depth_frame.get_data())
color_image = np.asanyarray(color_frame.get_data())
# Apply colormap on depth image (image must be converted to 8-bit per pixel first)
depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
# Stack both images horizontally
images = np.hstack((color_image, depth_colormap))
# Show images
cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
cv2.imshow('RealSense', images)
key = cv2.waitKey(1)
# Press esc or 'q' to close the image window
if key & 0xFF == ord('q') or key == 27:
cv2.destroyAllWindows()
break
finally:
# Stop streaming
pipeline.stop()
如何用Python获取深度相机参数
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)
pipeline.start(config)
# 创建对齐对象(深度对齐颜色)
align = rs.align(rs.stream.color)
try:
while True:
frames = pipeline.wait_for_frames()
# 获取对齐帧集
aligned_frames = align.process(frames)
# 获取对齐后的深度帧和彩色帧
aligned_depth_frame = aligned_frames.get_depth_frame()
color_frame = aligned_frames.get_color_frame()
# 获取颜色帧内参
color_profile = color_frame.get_profile()
cvsprofile = rs.video_stream_profile(color_profile)
color_intrin = cvsprofile.get_intrinsics()
color_intrin_part = [color_intrin.ppx, color_intrin.ppy, color_intrin.fx, color_intrin.fy]
print(color_intrin_part)
# [318.48199462890625, 241.16720581054688, 616.5906372070312, 616.7650146484375]
if not aligned_depth_frame or not color_frame:
continue
finally:
pipeline.stop()
用python开启相机_如何用Python打开realsenseD435相机并获取相机参数相关推荐
- python 英语分词_如何用Python做中文分词?
打算绘制中文词云图?那你得先学会如何做中文文本分词.跟着我们的教程,一步步用Python来动手实践吧. 需求 在<如何用Python做词云>一文中,我们介绍了英文文本的词云制作方法.大家玩 ...
- python三门问题_如何用 Python 解读著名的“三门问题”?
原标题:如何用 Python 解读著名的"三门问题"? 作者 | 小詹 责编 | 郭芮 本文我们用Python分析著名的"三门问题". 不过在这之前 ,可以先来 ...
- python怎么读_如何用Python读写文件
前面我们已经介绍了很多Python相关的基础知识,大家是不是对Python已经有了进一步认识了呢?作为人工智能时代的热门编程语言,开始接触并学习Python的孩子越来越多,家长们都不想让自己的孩子落于 ...
- python旅游推荐系统_如何用Python搭建一个简单的推荐系统?
推荐系统的相关知识我们已在前文中提到,在这篇文章中,我们会介绍如何用Python来搭建一个简单的推荐系统. 本文使用的数据集是MovieLens数据集,该数据集由明尼苏达大学的Grouplens研究小 ...
- python读取二进制文件_如何用python读取二进制文件?
我发现用Python读取二进制文件特别困难.你能帮我一把吗?我需要读取这个文件,在Fortran 90中,该文件很容易被int*4 n_particles, n_groups real*4 group ...
- python md5加密_如何用python“优雅”的调用有道翻译?
前言 其实在以前就盯上有道翻译了的,但是由于时间问题一直没有研究(我的骚操作还在后面,记得关注),本文主要讲解如何用python调用有道翻译,讲解这个爬虫与有道翻译的js"斗争"的 ...
- python求平均值_如何用python求平均值
学习了Python相关数据类型,函数的知识后,利用字符串的分割实现了输入任意多个数据,并计算其平均值的小程序.思路是接收输入的字符串,以空格为分隔符,将分割的数据存入列表(lst1)中,将lst1中的 ...
- python小助手_如何用python写个人专属群聊提醒小助手?
前言 大家还记得教会父母玩微信是什么时候吗?父母学会后,我们的生活就发生了「质」的变化,父母也许会吐槽你的微信头像不好,要你换一个头像. 最近 pk哥 又被母后大人吐槽了,原因是亲戚微信群里某个亲戚生 ...
- 如何用python计算圆周率_如何用python计算圆周率?
如何用python计算圆周率? python计算圆周率的方法: 圆周率没有精确的计算公式,所以只能用近似的方式计算它的近似值. 我们运用蒙特卡罗方法,思路很简单,在下面图形中随机抛置大量的点, 计算落 ...
最新文章
- android edittext 默认不获取焦点
- OAuth 2 实现单点登录,通俗易懂!
- 10 个免费的服务器监控工具推荐
- [python opencv 计算机视觉零基础到实战] 十六、用opencv画画
- android 分享到豆瓣,Android项目总结之社会化分享
- 老男孩教育每日一题-2017-04-25:怎样产生一个子shell?
- Android学习笔记(24):进度条组件ProgressBar及其子类
- magento如何在首页显示产品
- Python开源微博工具:Twitter
- 零基础学python大概要多久-零基础自学python要多久?
- java和C#的区别汇总
- oracle 同时更新多表,在Oracle数据库中同时更新两张表的简单方法
- 微型计算机硬盘接口种类,硬盘接口类型
- 计算机硬件仿真实验软件,计算机硬件实验虚拟仿真平台的设计
- 【报告分享】 2020-2021年数字内容产业趋势报告-企鹅智库 (附下载)
- 《孙悟空大战白骨精》小游戏
- mybatis中sql语句中大于小于号的两种解决方法
- 苹果手机!!!全民K歌如何下载发布的歌曲
- MLT教程:从BXL文件导入Altium Designer原理图封装和PCB封装
- Android自动化测试