基本配置信息:Pycharm(IDE)-anaconda-Python3.6-numpy-opencv-pyrealsense2
1.在conda终端创建Python3.6虚拟环境,使用命令:
#创建python3.6环境
conda create -n python3.6 python=3.6
#激活使用python3.6
activate python3.6
2.安装Intel.RealSense.SDK.exe后,在安装目录…/Intel RealSense SDK 2.0/bin/x64目录下有两个.pyd文件。将python3.6对应的.pyd文件复制到python环境的/Anaconda3/envs/Python36/Lib/site-packages。
3.新建项目,在pycharm编辑器中选择python3.6的环境,安装pyrealsense2、opencv、numpy库 (可参考本文help)
测试代码如下:
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()
链接相机,运行代码,显示结果如下:?
?help:
Anaconda常用命令及其与pycharm配合使用方法_行秋的博客-CSDN博客_anaconda怎么和pycharm配合使用准备工作Anaconda下载与安装官网:Anaconda | Individual EditionPycharm下载与安装官网:PyCharm: the Python IDE for Professional Developers by JetBrains都安装好后------一、Anaconda命令显示已经安装的包名和版本号condal list创建自己的虚拟环境conda create -n python37python=3.7n是name的简写,pytho..https://blog.csdn.net/weixin_43042683/article/details/121051607pip安装pyrealsense2_行秋的博客-CSDN博客开始直接安装,报错PackagesNotFoundError.之后考虑用pip命令安装。有报错ERROR: Could not find a version that satisfies the requirement pyrealsense2网上查询现这个问题的原因是python国内网络不稳定,直接导致报错。因此使用常用镜像源来解决此问题。如下 :pip install pyrealsense2 -i http://pypi.douban.com/simple/ --trustehttps://blog.csdn.net/weixin_43042683/article/details/124439378?spm=1001.2014.3001.5501
更多例子:
librealsense/wrappers/python/examples at master · IntelRealSense/librealsense · GitHubIntel? RealSense? SDK. Contribute to IntelRealSense/librealsense development by creating an account on GitHub.https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python/examples?
|