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

本文主要是介绍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 F6E65AC044F831AC80A06380C8B3A55A6F3EFCDEsudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main" -usudo 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 = Truebreak
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 depthframes = pipeline.wait_for_frames()# frames.get_depth_frame() is a 640x360 depth image# Align the depth frame to color framealigned_frames = align.process(frames)# Get aligned framesaligned_depth_frame = aligned_frames.get_depth_frame() # aligned_depth_frame is a 640x480 depth imagecolor_frame = aligned_frames.get_color_frame()# Validate that both frames are validif not aligned_depth_frame or not color_frame:continuedepth_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 greygrey_color = 153depth_image_3d = np.dstack((depth_image,depth_image,depth_image)) #depth image is 1 channel, color is 3 channelsbg_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 rightdepth_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 windowif key & 0xFF == ord('q') or key == 27:cv2.destroyAllWindows()break
finally:pipeline.stop()

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

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

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

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

 切换为2D

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

这篇关于ubutu的Realsense摄像头的环境配置的报错解决(个人认为官方文档存在问题)以及官方视频流样例测试(无需摄像头)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/532490

相关文章

Nginx设置连接超时并进行测试的方法步骤

《Nginx设置连接超时并进行测试的方法步骤》在高并发场景下,如果客户端与服务器的连接长时间未响应,会占用大量的系统资源,影响其他正常请求的处理效率,为了解决这个问题,可以通过设置Nginx的连接... 目录设置连接超时目的操作步骤测试连接超时测试方法:总结:设置连接超时目的设置客户端与服务器之间的连接

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

mybatis和mybatis-plus设置值为null不起作用问题及解决

《mybatis和mybatis-plus设置值为null不起作用问题及解决》Mybatis-Plus的FieldStrategy主要用于控制新增、更新和查询时对空值的处理策略,通过配置不同的策略类型... 目录MyBATis-plusFieldStrategy作用FieldStrategy类型每种策略的作

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

使用Python快速实现链接转word文档

《使用Python快速实现链接转word文档》这篇文章主要为大家详细介绍了如何使用Python快速实现链接转word文档功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 演示代码展示from newspaper import Articlefrom docx import

Python Jupyter Notebook导包报错问题及解决

《PythonJupyterNotebook导包报错问题及解决》在conda环境中安装包后,JupyterNotebook导入时出现ImportError,可能是由于包版本不对应或版本太高,解决方... 目录问题解决方法重新安装Jupyter NoteBook 更改Kernel总结问题在conda上安装了

pip install jupyterlab失败的原因问题及探索

《pipinstalljupyterlab失败的原因问题及探索》在学习Yolo模型时,尝试安装JupyterLab但遇到错误,错误提示缺少Rust和Cargo编译环境,因为pywinpty包需要它... 目录背景问题解决方案总结背景最近在学习Yolo模型,然后其中要下载jupyter(有点LSVmu像一个

Goland debug失效详细解决步骤(合集)

《Golanddebug失效详细解决步骤(合集)》今天用Goland开发时,打断点,以debug方式运行,发现程序并没有断住,程序跳过了断点,直接运行结束,网上搜寻了大量文章,最后得以解决,特此在这... 目录Bug:Goland debug失效详细解决步骤【合集】情况一:Go或Goland架构不对情况二:

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为

解决jupyterLab打开后出现Config option `template_path`not recognized by `ExporterCollapsibleHeadings`问题

《解决jupyterLab打开后出现Configoption`template_path`notrecognizedby`ExporterCollapsibleHeadings`问题》在Ju... 目录jupyterLab打开后出现“templandroidate_path”相关问题这是 tensorflo