orb_slam2 + 语义分割 + 八叉树地图,
github地址:https://github.com/floatlazer/semantic_slam
根据github上环境的版本要求,选择在ubuntu16.04的docker容器中搭建
首先pull了一个ubuntu16.04 + python2.7 + opencv3.3.0的镜像,在这个基础上搭建环境
1.download semantic slam的code
在$HOME下
$ mkdir catkin_ws
$ cd catkin_ws
$ mkdir src
$ cd src
$ git clone https://github.com/floatlazer/semantic_slam.git
2.安装orb slam2的环境
参考了https://www.jianshu.com/p/dbf39b9e4617
这中间涉及到ros, pangolin, eigen等的安装
进入sematic_slam文件夹中的ORB_SLAM2文件夹,build成功即可
3.安装语义分割相关
按照semantic slam的github中的要求
$ sudo apt-get install ros-kinetic-openni2-launch
4.安装八叉树地图相关
sudo apt-get install ros-kinetic-octomap-ros
sudo apt-get install ros-kinetic-octomap-msgs
sudo apt-get install ros-kinetic-octomap-server
sudo apt-get install ros-kinetic-octomap-rviz-plugins
5.安装语义分割相关
pip install torch-0.4.0-cp27-cp27mu-linux_x86_64.whl #1.0之前的版本要在官网上下载
pip install torchvision==0.2.0
pip install numpy
pip install future
pip install matplotlib
然后github上说依赖pytorch-semseg
打开pytorch-semseg中的requirements.txt, 看到里面还有一些依赖要安装
pip install scikit-image
pip install opencv-python==3.3.0.10
pip install tqdm==4.11.2
pip install cython
pip install pydensecrf
pip install tensorboardX
pip install scipy==0.19.0
pip install imgaug
然后安装semantic_slam包
$ rosdep install semantic_slam
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
semantic_slam: Cannot locate rosdep definition for [catkin]
这一步会报找不到相关依赖的错误
命令改为:
$ rosdep install --from-paths semantic_slam --ignore-src --rosdistro=kinetic -r -y
#All required rosdeps installed successfully
这些都安装好之后,到~/catkin_ws下catkin_make
开始启动launch:
roslaunch semantic_slam semantic_mapping.launch
会报如下错误:
ImportError: No module named google.protobuf.internal
解决方法:
pip install protobuf
再启动launch:
会报错:AttributeError: ‘module’ object has no attribute ‘_cuda_getDevice’
Traceback (most recent call last):
File “/home/xx/catkin_ws/src/semantic_slam/semantic_cloud/src/semantic_cloud.py”, line 295, in
main(sys.argv)
File “/home/xx/catkin_ws/src/semantic_slam/semantic_cloud/src/semantic_cloud.py”, line 288, in main
seg_cnn = SemanticCloud(gen_pcl = True)
File “/home/xx/catkin_ws/src/semantic_slam/semantic_cloud/src/semantic_cloud.py”, line 123, in init
state = torch.load(model_path)
这是因为它的weight, 也就是pth文件,是用GPU训练出来的,
而docker里面没有GPU, 要把这个pth转为cpu模式:
把这个 state = torch.load(model_path)
改为:
state = torch.load(model_path, map_location={'cuda:0': 'cpu'})
到~/catkin_ws下
$ rm -rf build devel
$ catkin_make
再试一次
$ roslaunch semantic_slam semantic_mapping.launch
[ INFO] [1655366319.121127159]: Semantic octomap generator [max fusion]
Generate semantic point cloud [max fusion].
Setting up CNN model...
Setting up ROS...
Ready.
另起一个窗口
$ rosbag play demo.bag
图建出来了