2020.12.20
暂时Ubuntu20.04的ROS Melodic不支持相机标定。
Ubuntu20.04 需要安装ROS Noetic,注意在Python3下进行安装,否则会产生一系列报错。
参考:http://wiki.ros.org/UsingPython3
设置NTP,使服务器和PC的时间误差最小。
$ sudo apt-get install -y chrony ntpdate
$ sudo ntpdate -q ntp.ubuntu.com
$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
连接很慢或者连不上,可以用清华TUNA源
$ sudo sh -c '. /etc/lsb-release && echo "d{2d3b390d-f615-41d0-a830-7bbdcedbd397}eb http://mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
$ sudo apt-get update && sudo apt-get upgrade
系统为ubuntu20.04,安装ROS Noetic 版本
$ sudo apt install ros-noetic-desktop-full -y
sudo apt install ros-kinetic-desktop-full -y
安装rqt相关功能包
$ sudo apt-get install ros-noetic-rqt
$ sudo rosdep init
sudo: rosdep: command not found
解决
$ sudo apt install python3-rosdep2
由于ubuntu20.04不支持python-rosdep2
报错需要下载python3-rosdep2
需要安装好依赖项,否则会会卸载ros相关的包(在python2.7环境下使用)
依赖项下载
$ sudo apt install python3-catkin-pkg
$ sudo apt install python3-rosdistro
$ sudo apt install python3-rospkg
$ sudo apt install python3-yaml
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
解决
$ sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
因为国内防火墙的问题,修改hosts文件
$ sudo gedit /etc/hosts
完成初始化后显示
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run
rosdep update
后运行
$ rosdep update
*报错1
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: error loading sources list:
The read operation timed out
unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
(https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
最后科学上网才解决了
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/chan/.ros/rosdep/sources.cache
$ sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential
$ source /opt/ros/noetic/setup.bash
自动添加环境变量
$ echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
$ source ~/.bashrc
创建工作目录并初始化
$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src
$ catkin_init_workspace
$ cd ~/catkin_ws/
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash
启动
$ roscore
新终端安装和打开小乌龟
$ sudo apt install ros-noetic-turtlesim
$ rosrun turtlesim turtlesim_node
另一个键盘控制小乌龟
$ rosrun turtlesim turtle_teleop_key
Resource not found: roslaunch
ROS path [0]=/opt/ros/noetic/share/ros
ROS path [1]=/home/chan/catkin_ws/src
ROS path [2]=/opt/ros/noetic/share
The traceback for the exception was written to the log file
解决
$ sudo apt install ros-noetic-rosbash
$ sudo apt install ros-noetic-roslaunch
$ cd catkin_ws/src
$ git clone https://github.com/bosch-ros-pkg/usb_cam.git
$ cd ..
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash
Could NOT find image_transport
下载
$ sudo apt-get install ros-noetic-image-transport
Could NOT find camera_info_manager
下载
$ sudo apt install ros-noetic-camera-info-manager
$ cd ~/catkin_ws/src/usb_cam
$ mkdir build
$ cd build
$ cmake ..
$ make
打开新终端,运行ROS
$ roscore
回到原终端运行launch文件
$ cd ~/catkin_ws/src/usb_cam/launch
$ roslaunch usb_cam usb_cam-test.launch
RLException: [usb_cam-test.launch] is neither a launch file in package [usb_cam] nor is [usb_cam] a launch file name
The traceback for the exception was written to the log file
$ source ~/catkin_ws/devel/setup.bash
ERROR: cannot launch node of type [image_view/image_view]: image_view
ROS path [0]=/opt/ros/noetic/share/ros
ROS path [1]=/home/chan/catkin_ws/src
ROS path [2]=/opt/ros/noetic/share
事实上输入命令roscd image_view
和roscd cv_bridge
都找不到相应的包,是cv_bridge
缺失。
下载
git clone https://github.com/ros-perception/vision_opencv
找到cv_bridge
文件夹,修改cmakelists.txt
,改为系统自己安装的opencv版本
find_package(OpenCV 3.4 REQUIRED
将文件夹复制到工作空间~/catkin_ws/src
通过cmake编译
$ cd ~/catkin_ws/src/cv_bridge
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
同理下载编译image_view
git clone https://github.com/ros-perception/image_pipeline
复制image_view
进行编译
打开image_view
中的CmakeLists.txt文件进行修改
在find_package前面添加
set(cv_bridge_DIR /usr/local/share/cv_bridge/cmake)
Launch文件video_device设置中,笔记本电脑自带摄像头为video0,更换为usb摄像头需要更改,一般为video1。
可运行以下命令查看类型
$ ls /dev/video*
正常情况可打开摄像头
使用OpenCV进行图像处理,需要对相机进行校准。镜头和图像传感器在组装时可能有偏离,包括图像中心(image center)与主点(principal point)的偏差和传感器的倾斜度等。校准(calibration)的目的是查找相机的固有参数。
Matlab官方相机标定黑白棋盘格网址:
http://www.vision.caltech.edu/bouguetj/calib_doc/htmls/pattern.pdf
打印在A4上,每个棋盘格的边长为0.028m。
黑白棋盘格是由9×7的黑白格组成,使用的是内部交点即8×6的角点。
原本用ubuntu16.04可以安装uvc_camera软件包,但是现在还没有noetic版本的包
https://index.ros.org/p/uvc_camera/github-ros-drivers-camera_umd/
因此采用usb_camera作为节点。
$ sudo apt install ros-noetic-usb-cam
安装相机校准软件包
$ sudo apt install ros-noetic-camera-calibration
(3)运行ROS
$ roscore
(4)打开新终端,启动usb_camera节点
$ rosrun usb_camera usb_camera_node
这里只能看到摄像头打开并不会看到图像,如果想要看下当前的图像可以使用 image_view
,因为 usb_cam
默认发布 /usb_cam/image_raw
这样的 topic,topic查看命令为rostopic list
启动usb_camera可视节点
$ rosrun image_view image_view image:=/usb_cam/image_raw
可看到没有检测到相机校准配置文件。
[ WARN] [1605509617.183192743]: Camera calibration file /home/chan/.ros/camera_info/head_camera.yaml not found.
查看默认的相机信息,显示为默认值
$ rostopic echo /camera_info
WARNING: topic [/camera_info] does not appear to be published yet
(5)打开新的终端,启动GUI
$ rosrun camera_calibration cameracalibrator.py –size 8×6 –square 0.028 image:=/image_raw
标定过程中左右,上下,前后,对角方向前后倾斜标定板,这样使得右边X,Y, Size, Skew变成绿色后,CALIBRATE按钮变为蓝色,然后点击。等待三个按钮都可以点击,依次点击SAVE(保存)和COMMIT(提交)到相机配置文件中。即可将标定结果保存至本地。
点击SAVE之后:(‘Wrote calibration data to’, ‘/tmp/calibrationdata.tar.gz’)
https://answers.ros.org/question/363942/camera_calibration-does-not-work-ros-noetic/
(6)若点击COMMIT出现:
raise ServiceException(“service [%s] unavailable”%self.resolved_name)
rospy.service.ServiceException: service [/camera/set_camera_info] unavailable
需要自行将标定参数移动至:
~/.ros/camera_info
$ cd /tmp
$ tar -zxvf calibrationdata.tar.gz
$ mkdir /.ros/camera_info
$ sudo cp ost.yaml ~/.ros/camera_info
$ cd ~/.ros/camera_info
$ sudo mv ./ost.yaml ./head_camera.yaml
(7)打开head_camera.yaml文件,将camera_name改成head_camera
(4)重新运行usb摄像头
打开新终端,运行ROS
$ roscore
回到原终端运行launch文件
$ cd launch
$ roslaunch usb_cam usb_cam-test.launch
[ WARN] [1605509617.528102354]: unknown control 'focus_auto'
显示unknown control 'focus_auto'
,原因是相机不可以自动对焦,可以忽略
$ cd ~/ORB_SLAM2/Thirdparty/g2o
$ mkdir build
$ cmake ..
$ make
$ cd ~/ORB_SLAM2/Thirdparty/ DBoW2
$ mkdir build
$ cmake ..
$ make
$ cd ~/ORB_SLAM2
$ cd build // 由于已经新建build文件夹,若无,则mkdir build
$ cmake ..
$ make
$ cd ~/ORB_SLAM2/Examples/ROS/ORB_SLAM2
$ mkdir build
$ cd build
$ cmake ..
$ make
(1)打开第一个终端,运行roscore
$ roscore
(2)打开第二个终端,运行usb_cam
$ cd catkin_ws/src/usb_cam/launch
$ source ~/catkin_ws/devel/setup.bash
$ roslaunch usb_cam usb_cam-test.launch
(3)打开第三个终端,运行Mono文件
格式如下:
$ rosrun ORB_SLAM2 Mono PATH_TO_VOCABULARY PATH_TO_SETTINGS_FILE
运行:
$ rosrun ORB_SLAM2 Mono /home/chan/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/chan/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml /camera/image_raw:=/usb_cam/image_raw
第一次运行后,创建82个地图点,后初始化出错。
重置后,检测到110地图点。
第二次运行后检测到70个地图点,移动摄像机后显示TRACK LOST,需要重定位。重定位后检测到130个地图点。实时运行的响应度较低
-----------------
参考:
[https://blog.csdn.net/pengrui18/article/details/88958487](https://blog.csdn.net/pengrui18/article/details/88958487)
[https://blog.csdn.net/fb_941219/article/details/105705759](https://blog.csdn.net/fb_941219/article/details/105705759)
[https://answers.ros.org/question/359998/camera-calibration-on-ros-noetic-calibration-display-with-video-is-flickering/](https://answers.ros.org/question/359998/camera-calibration-on-ros-noetic-calibration-display-with-video-is-flickering/)