1.系统准备
硬件
:笔记本电脑自带摄像头或者通过usb接口连接的相机
软件
:虚拟机+ubuntu18.04+ROS1 melodic(针对ubuntu18.04对应的ROS版本)
2.下载源码
- 首先确保在主目录下,创建ROS工程
cd ~
mkdir catkin_ws
cd catkin_ws
mkdir src
cd src
- 克隆代码
git clone https://github.com/ros-drivers/usb_cam
- 编译代码
cd ~/catkin_ws
catkin_make
# 设置环境变量
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc
这个地方我报错了
– No package ‘libv4l2’ found
CMake Error at /usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:419 (message):
A required package was not found
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:597 (_pkg_check_modules_internal)
usb_cam/CMakeLists.txt:10 (pkg_check_modules)
– Configuring incomplete, errors occurred!
See also “/home/zg/Project/camera_calibration/build/CMakeFiles/CMakeOutput.log”.
See also “/home/zg/Project/camera_calibration/build/CMakeFiles/CMakeError.log”.
Invoking “cmake” failed
表示我的电脑没有libv4l2包,执行以下命令安装:
sudo apt-get update
sudo apt-get install libv4l-dev
重新编译即可
- 安装usb_cam
安装相机标定包camera_calibration,若使用别的ros版本,把melodic改成自己的ros版本即可。
sudo apt-get install ros-melodic-usb-cam
- 运行launch文件启动相机
roslaunch usb_cam usb_cam-test.launch
这个地方出现错误
Opening streaming device /dev/video0
Cannot identify device by name ‘/dev/video0’ (2)
[ERROR] [1703747669.095275685]: Error starting device
表示相机没有被虚拟机检测到。
解决方案:
参考博客:win10上虚拟机上的linux(ubuntu16.04)找不到/dev/video0
我的是将usb2.0换成usb3.0,然后在虚拟机->可移动设备中看到了我的电脑自带摄像头和usb连接的摄像头,然后选择对应摄像头,点击“连接”,如下几幅图所示操作即可。
6. 新建终端,启动相机标定包
rosrun camera_calibration cameracalibrator.py --size 8x5 --square 0.04 image:=/usb_cam/image_raw camera:=/usb_cam
size
:表示内角点的size,若标定板棋盘格是9*6,则设置为8*5
;square
:指定方格的尺寸,我们使用的是A4纸打印的黑白格,尺寸为40 mm=0.04 m;image
:表示使用的是来哪个Topic的图像数据,默认即可。
- 移动标定板,使得
CALIBRATE
按钮由灰色变为深绿色 - 标定结果展示
**** Calibrating ****
mono pinhole calibration...
*** Added sample 59, p_x = 0.906, p_y = 0.919, p_size = 0.241, skew = 0.867
*** Added sample 60, p_x = 0.847, p_y = 0.925, p_size = 0.251, skew = 0.381
*** Added sample 61, p_x = 0.799, p_y = 0.958, p_size = 0.261, skew = 0.074
*** Added sample 62, p_x = 0.751, p_y = 0.903, p_size = 0.236, skew = 0.659
D = [0.012435656227578315, 0.04264352721087082, -0.0006149057700244186, 0.0019732357183862405, 0.0]
K = [512.4084342578259, 0.0, 325.79542039669184, 0.0, 512.9461154918142, 247.35931901475354, 0.0, 0.0, 1.0]
R = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P = [524.1615600585938, 0.0, 326.8240686944737, 0.0, 0.0, 524.8475341796875, 246.89098901609395, 0.0, 0.0, 0.0, 1.0, 0.0]
None
# oST version 5.0 parameters
[image]
width
640
height
480
[narrow_stereo]
camera matrix
512.408434 0.000000 325.795420
0.000000 512.946115 247.359319
0.000000 0.000000 1.000000
distortion
0.012436 0.042644 -0.000615 0.001973 0.000000
rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
projection
524.161560 0.000000 326.824069 0.000000
0.000000 524.847534 246.890989 0.000000
0.000000 0.000000 1.000000 0.000000
('Wrote calibration data to', '/tmp/calibrationdata.tar.gz')
('Wrote calibration data to', '/tmp/calibrationdata.tar.gz')
D = [0.012435656227578315, 0.04264352721087082, -0.0006149057700244186, 0.0019732357183862405, 0.0]
K = [512.4084342578259, 0.0, 325.79542039669184, 0.0, 512.9461154918142, 247.35931901475354, 0.0, 0.0, 1.0]
R = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
P = [524.1615600585938, 0.0, 326.8240686944737, 0.0, 0.0, 524.8475341796875, 246.89098901609395, 0.0, 0.0, 0.0, 1.0, 0.0]
# oST version 5.0 parameters
[image]
width
640
height
480
[narrow_stereo]
camera matrix
512.408434 0.000000 325.795420
0.000000 512.946115 247.359319
0.000000 0.000000 1.000000
distortion
0.012436 0.042644 -0.000615 0.001973 0.000000
rectification
1.000000 0.000000 0.000000
0.000000 1.000000 0.000000
0.000000 0.000000 1.000000
projection
524.161560 0.000000 326.824069 0.000000
0.000000 524.847534 246.890989 0.000000
0.000000 0.000000 1.000000 0.000000