python 调用 Intel realsense D415i摄像头

1、搭建python3开发环境(wind10 )

安装Intel.RealSense.SDK.exe后,在安装目录…/Intel RealSense SDK 2.0/bin/x64目录下有两个.pyd文件,根据文件名可以知道,其中一个对应python2.7版本,另一个对应python3.6。将python3.6对应的.pyd文件复制到python环境的site-packages目录下,我的目录是…/Anaconda3/envs/ycc01/Lib/site-packages。即可完成环境搭建。

这里用python调用的版本一定时python3.6,不然会报错:ImportError:DLL load failed:找不到指定模块

2.显示深度图与彩色图

import pyrealsense2 as rs
import numpy as np
import cv2
 
# 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 把图像转换为numpy data
        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))
 
        cv2.namedWindow('RealSense', cv2.WINDOW_AUTOSIZE)
        cv2.imshow('RealSense', images)
 
        key = cv2.waitKey(1)
        if key & 0xFF == ord('q') or key == 27:
            cv2.destroyAllWindows()
            break
 
 
finally:
 
    # Stop streaming
    pipeline.stop()

参考:(53条消息) python 调用 Intel realsense D415摄像头_weixin_44576543的博客-CSDN博客_python realsense 

  • 0
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值