ubutu的Realsense摄像头的环境配置的报错解决(个人认为官方文档存在问题)以及官方视频流样例测试(无需摄像头)

Realsense支持多种语言进行开发,因为之前学过python,所以计划使用Pycharm进行相关的项目开发,由于没带摄像头回家,所以使用了官方的视频流进行测试,以下是Realsense的环境配置及Pycharm相关的库函数安装说记录

Realsense SDK的下载

1、首先要在Real Sense官网上下载SDK的安装包

 点击DEVELOPERS,然后点击SDK2.0

 下载SDK

滑到最下方 ,Linux系统要点击这个源码包进行编译,Windows系统下载上面的exe就好

下载完成后,将其拖动到虚拟机页面中,点击提取到此处,然后可以将解压过后的文件放入其他路径中,这个看个人习惯。

2、右击该文件,在终端打开

2、 按照官方说明进行编译

注意:官方说明存在漏洞,有几个驱动包的安装命令没有写在上面,如果直接按照官方命令的话会报错,所以需要在该文件终端输入以下命令,再按照官方文档来。

sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils
sudo apt-get install librealsense2-dev
sudo apt-get install librealsense2-dbg

如果嫌看起来麻烦的话,可以复制后在word文档中将其翻译为中文副本,方便查看

注意:要看清楚每个命令前的说明,有很多都是其他版本或者内核的命令,顺序很重要,不要跳着来,前面如果报错要先解决它,不然到关键步骤的时候会因为缺少依赖项而报一些很莫名其妙的错误。

比如这里,我用的是Ubuntu18.04,如果有其他版本的话就使用其他的命令就好

 还有这里也是,看清楚自己的版本和内核

 至于CMake的话可以在ubuntu的软件商店上下载,或者直接到CMake官网上下载,网上教程很多,可以自行参考。

以下是我的Ubuntu18.04使用的全部命令

#记得先右击该文件打开终端

sudo apt-key adv --keyserver keys.gnupg.net --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key F6E65AC044F831AC80A06380C8B3A55A6F3EFCDE

sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main" -u

sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils
sudo apt-get install librealsense2-dev
sudo apt-get install librealsense2-dbg
sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade
sudo update-grub && sudo reboot
sudo apt-get install git libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev
sudo apt-get install libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger
./scripts/patch-realsense-ubuntu-lts.sh
mkdir build && cd build
cmake ../
DCMAKE_BUILD_TYPE=Release
cmake ../ -DBUILD_EXAMPLES=true
sudo make uninstall && make clean && make && sudo make install
realsense-viewer

如果上面命令出现问题,也可以参考这个文档

3、pycharm专业版的下载

Pycharm官网上下载安装包,然后同样将其拖入虚拟机页面中,右键提取到此处。

具体操作可以参考此教程注意:配置环境变量时自己的路径和教程中的路径是不一样的,先打开终端,输入pwd查看下自己的路径再配置。以及如果想激活pycharm又不想掏100块的话,可以直接去淘宝上买一个破解插件,教程很简单,而且只要7块钱,不需要去修改host文件,当然也可以去网上找激活码,不过个人感觉用网上的激活码太麻烦,所以这里不推荐。

4、Pycharm开发Reslsense的常用库下载

配置完路径之后在命令行输入Pycharm.sh,即可打开Pycharm

新建一个项目后,点击左上角文件中的设置

 然后点击项目python project中的python解释器

 点这个加号,然后搜索自己需要的软件包,python开发Real Sense常用的软件包有,pyrealsense2;numpy;CV2以及open3d;这些都可以提前下载到项目中,在下载open3d的时候可能会报错,可以升级一些pip软件包,(直接搜索pip,然后在指定版本那里勾选更高的版本下载),不过这么做可能会造成python的pip命令与当前版本不适配,后面调回来就好。

官方代码测试

1.还是在DEVEOPLERS下方,点击code samples

 然后下拉选择自己想要用于开发的语言,这里我选的是python

 每个例子都有对应的作用解释,点击后可以看到代码,上面都有英文注释

 

 插上设备后在pycharm中输入测试代码

注意:要先下载pyrealsense2;numpy;cv2三个软件包,否则将会报错

## License: Apache 2.0. See LICENSE file in root directory.
## Copyright(c) 2017 Intel Corporation. All Rights Reserved.

#####################################################
##              Align Depth to Color               ##
#####################################################

# First import the library
import pyrealsense2 as rs
# Import Numpy for easy array manipulation
import numpy as np
# Import OpenCV for easy image rendering
import cv2

# Create a pipeline
pipeline = rs.pipeline()

# Create a config and configure the pipeline to stream
#  different resolutions of color and depth streams
config = rs.config()

# Get device product line for setting a supporting resolution
pipeline_wrapper = rs.pipeline_wrapper(pipeline)
pipeline_profile = config.resolve(pipeline_wrapper)
device = pipeline_profile.get_device()
device_product_line = str(device.get_info(rs.camera_info.product_line))

found_rgb = False
for s in device.sensors:
    if s.get_info(rs.camera_info.name) == 'RGB Camera':
        found_rgb = True
        break
if not found_rgb:
    print("The demo requires Depth camera with Color sensor")
    exit(0)

config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)

if device_product_line == 'L500':
    config.enable_stream(rs.stream.color, 960, 540, rs.format.bgr8, 30)
else:
    config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30)

# Start streaming
profile = pipeline.start(config)

# Getting the depth sensor's depth scale (see rs-align example for explanation)
depth_sensor = profile.get_device().first_depth_sensor()
depth_scale = depth_sensor.get_depth_scale()
print("Depth Scale is: " , depth_scale)

# We will be removing the background of objects more than
#  clipping_distance_in_meters meters away
clipping_distance_in_meters = 1 #1 meter
clipping_distance = clipping_distance_in_meters / depth_scale

# Create an align object
# rs.align allows us to perform alignment of depth frames to others frames
# The "align_to" is the stream type to which we plan to align depth frames.
align_to = rs.stream.color
align = rs.align(align_to)

# Streaming loop
try:
    while True:
        # Get frameset of color and depth
        frames = pipeline.wait_for_frames()
        # frames.get_depth_frame() is a 640x360 depth image

        # Align the depth frame to color frame
        aligned_frames = align.process(frames)

        # Get aligned frames
        aligned_depth_frame = aligned_frames.get_depth_frame() # aligned_depth_frame is a 640x480 depth image
        color_frame = aligned_frames.get_color_frame()

        # Validate that both frames are valid
        if not aligned_depth_frame or not color_frame:
            continue

        depth_image = np.asanyarray(aligned_depth_frame.get_data())
        color_image = np.asanyarray(color_frame.get_data())

        # Remove background - Set pixels further than clipping_distance to grey
        grey_color = 153
        depth_image_3d = np.dstack((depth_image,depth_image,depth_image)) #depth image is 1 channel, color is 3 channels
        bg_removed = np.where((depth_image_3d > clipping_distance) | (depth_image_3d <= 0), grey_color, color_image)

        # Render images:
        #   depth align to color on left
        #   depth on right
        depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha=0.03), cv2.COLORMAP_JET)
        images = np.hstack((bg_removed, depth_colormap))

        cv2.namedWindow('Align Example', cv2.WINDOW_NORMAL)
        cv2.imshow('Align Example', 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:
    pipeline.stop()

此示例展示通过将深度图像对准到彩色图像并执行简单的计算来表明通过对彩色图像进行简单的计算来执行背景移除的方法。

如果没带摄像头也可以采用realsense官方录好的视频进行测试,看看自己配置的环境是否正确,这里我选的是第二个,

首先在官网上下载样例,可以任选,点击对应的图片下载,然后将其拖入虚拟机页面中,右键提取到此处

然后打开命令行,输入realsense-viewer,出现如下页面,将上面解压好的文件拖入realsense-viewer的页面中,即可播放深度视频流,以下是实际效果

 切换为2D

并且当鼠标移到任意一个像素点上时,它都可以显示对应的三维坐标

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

念980

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值