系统:vmware虚拟机,Ubuntu18.04
运行平台:CPU,因为电脑没有N卡,所以在CPU运行
sudo apt-get install cmake sudo apt-get install gcc g++ sudo apt-get install git sudo apt-get install python3-pip
sudo apt-get install vim
sudo apt-get install libeigen3-dev
sudo apt-get install libglew-dev libpython2.7-dev
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
在这个网址下载v0.5版本,然后解压缩得到文件夹,按下面的方式安装:
Release v0.5 · stevenlovegrove/Pangolin · GitHub
cd Pangolin
mkdir build
cd build
cmake ..
make
sudo make install
如果出现彩色立方块而且可以查看,就说明好了
cd ~/Pangolin/build/examples/HelloPangolin
./HelloPangolin
gui方式参考教程:在ubuntu18.04中安装opencv_contrib-3.2.0采坑教程 - 小虎哥哥爱学习 - 博客园
要安装一些依赖项,关于cmake、gcc、g++上面已经安装过。然后综合一下各个地方看的教程,最后可以用下面这个
sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff5-dev libdc1394-22-dev # 处理图像所需的包
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev
sudo apt-get install libxvidcore-dev libx264-dev # 处理视频所需的包
sudo apt-get install libatlas-base-dev gfortran # 优化opencv功能
sudo apt-get install ffmpeg
sudo apt-get install libopenexr-dev
sudo apt-get install libopenblas-dev #在编译过程中会遇到undefined reference to 'cblas_zgemm'的问题,主要就是这个依赖项出的bug
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
如果上面命令执行报错,错误说libjaster-dev无法安装,解决办法如下
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
然后编译安装(官网教程:OpenCV: Install OpenCV-Python in Ubuntu):
cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
make -j8 #后面
sudo make install
(3.1)BUG1
在过程中大概率会提示缺少boostdesc_bgm.i文件的问题,解决方案:
参考:安装OpenCV时提示缺少boostdesc_bgm.i文件的问题解决方案(附带百度云资源)_AlexWang30的博客-CSDN博客_boostdesc_bgm.i
将boostdesc_bgm.i等文件拷贝到opencv_contrib/modules/xfeatures2d/src/目录下,下载地址:
百度云链接:百度网盘 请输入提取码
提取码:e1wc
(3.2)BUG2
在编译过程中出现问题,对‘cv::String::deallocate()’未定义的引用,下面是解决方案
ununtu 调用openCV编译不通过 - 代码天地
g++ main.cpp `pkg-config --cflags --libs opencv` -o test
先在任意文件夹(如桌面)建立一个cpp文件(如hello_opencv.cpp),在这个里面写入
#include
#include
using namespace cv;
using namespace std;
int main()
{
cout<<"hello"<
然后终端输入,如果输出了hello,那么说明编译成功
cd Desktop
ls
gedit hello_opencv.cpp
g++ hello_opencv.cpp `pkg-config --cflags --libs opencv` -o test
./test
下载安装包,离线pip安装
https://download.pytorch.org/whl/torch_stable.html
这是关于下载torch的whl源,直接离线安装,寻找CPU版本,下载torch-1.4.0+cpu-cp36-cp36m-linux_x86_64.whl,并安装torchvision、libtorch
pip install torch-1.4.0+cpu-cp36-cp36m-linux_x86_64.whl
pip install torchvision==0.5.0
wget https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-1.4.0%2Bcpu.zip
验证安装成功
python #进入python 交互环境
#若与下列内容类似,说明pytorch安装成功
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> import torchvision
>>> print(torch.cuda.is_available())
False
>>>
git clone https://github.com/jiexiong2016/GCNv2_SLAM.git
//99行
//原
std::shared_ptr module;
//改为
torch::jit::script::Module module;
//270行
//原
auto output = module->forward(inputs).toTuple();
//改为
auto output = module.forward(inputs).toTuple();
//218改为
torch::DeviceType device_type;
device_type = torch::kCPU;
torch::Device device(device_type);
const char *net_fn = getenv("GCN_PATH");
net_fn = (net_fn == nullptr) ? "gcn2.pt" : net_fn;
module = torch::jit::load(net_fn, device);
//使用全局搜索,将torch::kCUDA替换为torch::kCPU,事实上我只搜到第220行需要这么做
//在if( TORCH_PATH ) 前加 给一个libtorch的路径
set(TORCH_PATH "/home/chan/libtorch/share/cmake/Torch")
双击打开gcn2_320x240.pt (其他pt文件同理)(无需解压)/gcn/code/'下找到 ‘gcn.py’
# 原 这是因为1.3以前默认true 1.3以后默认false
_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0))
# 改为
_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0, True))
# 所有的cuda:0替换为cpu
cd GCNv2_SLAM
./build.sh
下载地址:Computer Vision Group - Dataset Download
随便选一个,我下载的是fr3/long_office_household,将其解压缩到/home/chan/GCNv2_SLAM/datasets/TUM中(就是自己建个TUN文件夹,这个路径很重要,之后需要用到)
参考链接:GCN-SLAM编译pytorch以及运行TUM数据集时遇到的问题_HyperZhu的博客-CSDN博客
解压后里面包含一个depth.txt和一个rgb.txt两个用来保存filename的文件,代码是通过filename从文件夹里读取的图像。但是在GCN的run.sh启动文件里,启动参数传入的是association.txt,经过翻看了一下ORB的一些传入参数,发现这里传入的association.txt应该是上面rgb.txt与depth.txt合并的结果,所以用一个函数来完成
创建一个associate.py,其内容如下
def split_line(f_rgbd):
rgbd_split = f_rgbd.read().split()
index_to_delete = []
for i in range(len(rgbd_split)):
if i%2:
index_to_delete.append(i)
count = 0
for index in index_to_delete:
index = index - count
rgbd_split.pop(index)
count += 1
return rgbd_split
def near_time_stamp(rgb_time_stamp, depth_time_stamp):
"""
假设len(rgb_time_stamp) > len(depth_time_stamp)
只需在rgb_time_stamp中取出len(depth_time_stamp)个元素即可
"""
near_rgb_stamp = []
for index in depth_time_stamp:
min_value = 1000000000
min_jndex = ''
depth_float = float(index)
for jndex in rgb_time_stamp:
rgb_float = float(jndex)
if abs(depth_float - rgb_float) < min_value:
min_value = abs(depth_float - rgb_float)
min_jndex = jndex
near_rgb_stamp.append(min_jndex)
return near_rgb_stamp
if __name__ == '__main__':
f_rgb = open("rgb.txt","r")
f_depth = open("depth.txt","r")
f_association = open('associations.txt','w',encoding='utf-8')
data_depth = f_depth.readlines()
f_depth.seek(0,0)
# 切分出时间戳
rgb_time_stamp = split_line(f_rgb)
depth_time_stamp = split_line(f_depth)
# 寻找最近时间戳
rgb_time_stamp = near_time_stamp(rgb_time_stamp, depth_time_stamp)
# 将rgb_time_stamp与depth_time_stamp对应行拼接起来
for i in range(len(rgb_time_stamp)):
str_association = rgb_time_stamp[i] + " " \
+ "rgb/" + rgb_time_stamp[i] + ".png" + " " \
+ data_depth[i]
f_association.write(str_association)
f_rgb.close()
f_depth.close()
f_association.close()
代码里按照filename读取文件的时候,没有考虑到这txt前三行的注释,所以也会有问题。故必须将传入的txt文件的前面三行的注释删掉,也就是rgb.txt与depth.txt按时间戳拼接后的.txt文件不要加前面的注释
python3 associate.py rgb.txt depth.txt > associations.txt
cd /GCNv2_SLAM/GCN2
GCN_PATH=gcn2_320x240.pt ./rgbd_gcn ../Vocabulary/GCNvoc.bin TUM3_small.yaml /home/chan/GCNv2_SLAM/datasets/TUM/rgbd_dataset_freiburg3_long_office_household /home/chan/GCNv2_SLAM/datasets/TUM/rgbd_dataset_freiburg3_long_office_household/associations.txt
结果如下: