栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Intel RealSense2 D455 PYTHON环境配置总结

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Intel RealSense2 D455 PYTHON环境配置总结

Intel RealSense D455 是 Intel RealSense D435i 的升级版,于2020年6月17日发布。

目前CSDN相关技术文档都是关于D435的,但是都可以完美应用到D455型号上。

RealSense2的SDK是开源项目,通过RealSense官网:

Intel RealSense SDK 2.0 – Intel RealSense Depth and Tracking cameras

可以找到GitHub网址:

https://github.com/IntelRealSense/librealsense/releases/tag/v2.49.0

通过相关资料查询以及b站intelREALSENSE官方的视频学习:

Intel英特尔RealSense动手实践 系统集成测试和技术支持高级工程师 孙湘裕老师讲解_哔哩哔哩_bilibili

有三个工具比较有用:

Intel RealSense Viewer : 展示RGB图,深度图及相关显示配置的可视化工具

Depth Quality Tool for Intel RealSense Cameras : 深度信息质量调试工具

Intel.RealSense.SDK-WIN10-2.49.0.3474 (重要): SDK:软件开发工具包  这个包里自带python,c++等多种语言环境,需要注意的是,SDK运行后,会自动生成前两个工具,所以其实前两个工具不需要下载。

本文重点来啦! python 环境下 pyrealsense2 的配置

因为Viewer只能向我们展示深度图和保存深度图,如何获取到具体的深度数据,为之后的工作做准备,需要软件层面对pyrealsense2库进行调用。

import pyrealsense2 as rs
先说结论:

一句话搞定:

pip install pyrealsense2

我是在清华镜像源下载的:

pip install package==version -i https://pypi.tuna.tsinghua.edu.cn/simple

关于镜像源的配置文章可以见如下链接:

pip使用清华镜像源安装库 - 小Aer - 博客园

下面是试错过程(可以不看):

阅读大量文档后,我发现很多人提出的配置方法是 安装了SDK.exe后,找到Intel RealSense SDK 2.0 文件夹 将其中的…/Intel RealSense SDK 2.0/bin/x64/pyrealsense2.pyd 文件 复制到python环境的site-packages目录下,如我个人的路径为:D:ProgramDataAnaconda3envsenv-realsenseLibsite-packages,但是安装以后,运行测试程序提示 : DLLs not found importing pyrealsense2. 

于是我又尝试建立了一个pyrealsense文件夹,将…/Intel RealSense SDK 2.0/bin/x64 中的东西都放了进去,但是运行的时候会提示python module 'pyrealsense2' has no attribute 'pipeline',解决方法可能是在文件中加入__init__.py文件,但是SDK中的init文件太多了,我不知道是哪一个....

最后我选择试一下pip install pyrealsense2 的方法,结果最简单的往往最有效,直接运行成功...

测试代码

我参考了博主cherry_yu08的代码,非常感谢,在此附上原文链接:

Intel RealSense D435介绍、安装和使用_Well~-CSDN博客_realsense

显示彩色图和深度图代码:

(需要先通过USB线将RealSense相机和电脑连起来!!!)

(还需要安装opencv哦)

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_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()

运行结果见上述原博文。

                

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/423594.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号