1、dso编译(参照https://blog.csdn.net/heyijia0327/article/details/53173146)
2、跑dso_ros
2.1、安装usb_cam
查看相机设备:
znkz@znkz:~/slam/rosbuild_ws4$ ls /dev/video*
/dev/video0 /dev/video1
修改launch文件, <param name="video_device" value="/dev/video0" />改为video1
2.2、安装camera_calibration出错:
znkz@znkz:~/slam/rosbuild_ws4$ rosdep install camera_calibration
ERROR: Rosdep cannot find all required resources to answer your query
Missing resource camera_calibration
ROS path [0]=/opt/ros/indigo/share/ros
ROS path [1]=/home/znkz/slam/rosbuild_ws4/src
ROS path [2]=/opt/ros/indigo/share
ROS path [3]=/opt/ros/indigo/stacks
从github上下载之后安装包,然后编译:
znkz@znkz:~/slam/rosbuild_ws4$ catkin_make -DCATKIN_WHITELIST_PACKAGES="camera_calibration"
2.3、执行相机矫正py文件:
znkz@znkz:~/slam/rosbuild_ws4$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.028 image:=/usb_cam/image_raw camera:=/usb_cam
Waiting for service /usb_cam/set_camera_info ...
OK
...
File "/home/znkz/slam/rosbuild_ws4/src/cv_bridge/python/cv_bridge/core.py", line 91, in encoding_to_cvtype2
from cv_bridge.boost.cv_bridge_boost import getCvType
ImportError: libopencv_imgproc.so.2.4: 无法打开共享对象文件: 没有那个文件或目录
但是在/usr/local/lib中有libopencv_imgproc.so.3.4,应该是ros-cv-bridge默认安装2.4版本的
当我们需要用到OpenCV时,通常都需要运用cv_bridge或者image_pipeline或者image_transport包来转换传输图片,而这两个包又是依赖于OpenCV 2.4.8来编译的,所以每当同时需要用到OpenCV3和cv_bridge的时候,便会产生错误,
解决方法参照:error:cv_bridge---opencv和ros连接起来的桥
/************************************************链接原文部分*******************************************************************/
1.必须要先把旧版本的cv_bridge卸载掉:
sudo apt-get remove ros-indigo-cv-bridge
2.然后下载新版本的cv_bridge:
git clone https://github.com/ros-perception/vision_opencv.git
3.修改cv_bridge中的cmakelists.txt
find_package(OpenCV 3.1 REQUIRED) //将opencv的版本指定为3.1
4.将里面的cv_bridge包拿出来,放到工作空间中,重新编译:
catkin_make --pkg cv_bridge //catkin_make --pkg[package包],单独编译工作空间catkin_ws中的包;catkin_make编译所有的
也可以通过cmake编译
cd ~/catkin_ws/src/cv_bridge
mkdir build
cd build
cmake ..
make
sudo make install
结束之后你就可以更改你的其他代码了,由于以前的cv_bridge不见了,所以要在其他代码的cmakelists.txt添加一句话,后面的路径是自己的路径,查找cv_bridge.config.cmake所在的路径即可
set(cv_bridge_DIR /usr/local/share/cv_bridge/cmake) //在find_package前面
/*****************************************************************************************************************************************************/
进入cv_bridge配置文件所在目录(/usr/local/share/cv_bridge/cmake),查看libraries部分是否为opencv3的;
set(libraries "cv_bridge;/usr/local/lib/libopencv_calib3d.so.3.4.0;/usr/local/lib/libopencv_imgproc.so.3.4.0;/usr/local/lib/libopencv_core.so.3.4.0;/usr/local/lib/libopencv_highgui.so.3.4.0")
znkz@znkz:~/slam/rosbuild_ws4$ catkin_make -DCATKIN_WHITELIST_PACKAGES="dso_ros-master"
标定板为8*6,一格为0.028
得到相机(笔记本摄像头)参数如下:
[image]
width
640
height
480
[narrow_stereo]
camera matrix
840.368748 0.000000 303.258759
0.000000 839.758614 231.840186
0.000000 0.000000 1.000000
distortion
0.144840 -0.636233 -0.005295 0.005811 0.000000
rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
projection
847.711914 0.000000 305.181127 0.000000
0.000000 848.496094 230.518076 0.000000
0.000000 0.000000 1.000000 0.000000
点击COMMIT按钮将结果保存到默认文件夹,在usb_cam窗口中可以看到如下信息,说明标定结果已经保存在相应文件夹下下次启动usb_cam节点时,会自动调用。
[ INFO] [1566264521.636638681]: writing calibration data to /home/znkz/.ros/camera_info/head_camera.yaml
至此,相机标定部分已经完成
2.4、编译dso_ros-master:
下载dso_ros-master(catkin版)包放在空间中,然后添加变量,采用catkin_make编译
znkz@znkz:~/slam/rosbuild_ws4$ export DSO_PATH=/home/znkz/slam/dso-master
编译:
znkz@znkz:~/slam/rosbuild_ws4$ catkin_make -DCATKIN_WHITELIST_PACKAGES="dso_ros-master"
2.5、运行
自己的camera.txt如下(第一行分别为fx,fy,cx,cy,distort前四个参数):
840.368748 839.758614 303.258759 231.840186 0.144840 -0.636233 -0.005295 0.005811
640 480
crop
640 480
运行节点:
znkz@znkz:~/slam/rosbuild_ws4$ rosrun dso_ros dso_live image:=/usb_cam/image_raw calib=/home/znkz/slam/dso-master/camera.txt mode=1
其余问题:
1、roslaunch Tab补不全:
znkz@znkz:~/slam/rosbuild_ws4$ source devel/setup.bash
znkz@znkz:~/slam/rosbuild_ws4$ roslaunch us[rospack] Warning: error while crawling /home/znkz: boost::filesystem::status: Permission denied: "/home/znkz/.gvfs"
b_cam ^C
办法:
znkz@znkz:~/slam/rosbuild_ws4$ sudo umount /home/znkz/.gvfs
znkz@znkz:~/slam/rosbuild_ws4$ rm -rf .gvfs/
znkz@znkz:~/slam/rosbuild_ws4$ roslaunch usb_cam
参考文献: