使用realsense T265得到深度图
研究realsense 的github发现了其在librealsense中已经放好了wrapper,该wrapper中的python部分已经做好了使用T265获得深度图的例程:t265_stereo.py,下面给出获得深度图的过程。
所需条件
系统为ubuntu16.04,需要realsenseT265相机,python3,opencv(这里默认大家安装好了realsense的SDK,如果未安装,可以查看https://blog.csdn.net/weixin_44386661/article/details/100699985)
首先配置环境(一步步的来)
1.安装python3的虚拟环境支持
apt-get install python3-venv
2.创建一个虚拟环境
python3 -m venv py3librs
3. 进入虚拟环境
source py3librs/bin/activate
4. 安装python虚拟环境下的opencv(这个不大,很快就下载完成)
pip install opencv-python
5.安装pyrealsense2
pip install pyrealsense2
获取深度图
重新开启一个终端
1.进入虚拟环境
source py3librs/bin/activate
2.获取深度图
python3 t265_stereo.py
这里可能会报错如下:
这是由于安装了ROS导致系统会默认去找ros中的python的cv2库
所以我们需要在.bashrc中自己设置python3.5中库的路径,
首先在一个终端输入:
sudo gedit .bashrc
然后在.bashrc文件的最后一行加入:
export PYTHONPATH="/home/wyt/py3librs/lib/python3.5/site-packages":$PYTHONPATH
这里的路径需要自己去查,每个人的都不一样.只要找到自己的py3librs/lib/python3.5/site-packages的路径,替换掉我的那个即可.
最后可得到深度图如下:
将t265_stereo.py保存到home下即可,也可以随便改名字.
t265_stereo的程序如下:
#!/usr/bin/python
# -*- coding: utf-8 -*-
## License: Apache 2.0. See LICENSE file in root directory.
## Copyright(c) 2019 Intel Corporation. All Rights Reserved.
# Python 2/3 compatibility
from __future__ import print_function
"""
This example shows how to use T265 intrinsics and extrinsics in OpenCV to
asynchronously compute depth maps from T265 fisheye images on the host.
T265 is not a depth camera and the quality of passive-only depth options will
always be limited compared to (e.g.) the D4XX series cameras. However, T265 does
have two global shutter cameras in a stereo configuration, and in this example
we show how to set up OpenCV to undistort the images and compute stereo depth
from them.
Getting started with python3, OpenCV and T265 on Ubuntu 16.04:
First, set up the virtual enviroment:
$ apt-get install python3-venv # install python3 built in venv support
$ python3 -m venv py3librs # create a virtual environment in pylibrs
$ source py3librs/bi