1. ROS1 用的是 USB_CAM, ROS2用的是 v4l2_camera
-
sudo apt install ros-rolling-v4l2-camera ros-rolling-vision-opencv ros-rolling-image-transport-plugins ros-rolling-image-transport ros-rolling-image-common
-
sudo apt install python3-polled-camera polled-camera-tool libpolled-camera0d
-
sudo apt install libtheora-dev libogg-dev libboost-python-dev
-
sudo apt-get install -y libssl-dev libusb-1.0-0-dev pkg-config libgtk-3-dev
sudo apt-get install -y libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev
-
也可考虑源码安装, 这样可以保证更新
-
git clone https://github.com/ros-perception/image_pipeline.git
-
cd image_pipeline;
-
git checkout ros2
-
colcon build --symlink-install
-
source 安装目录/setup.bash
-
## Wiki 参考 https://index.ros.org/r/v4l2_camera/#foxy
-
-
ros2 run v4l2_camera v4l2_camera_node --ros-args -p video_device:="/dev/video2" -p image_size=[1280,720]
-
-
出现
-
[INFO] [1597918407.198064148] [v4l2_camera]: Starting camera
-
[INFO] [1597918407.839159913] [v4l2_camera]: using default calibration URL
-
[INFO] [1597918407.839354370] [v4l2_camera]: camera calibration URL: file:///home/iibull/.ros/camera_info/sunplusit_inc:_pc_camera.yaml
-
[ERROR] [1597918407.839576699] [camera_calibration_parsers]: Unable to open camera calibration file [/home/iibull/.ros/camera_info/sunplusit_inc:_pc_camera.yaml]
-
[WARN] [1597918407.839643757] [v4l2_camera]: Camera calibration file /home/iibull/.ros/camera_info/sunplusit_inc:_pc_camera.yaml not found
-
发布话题
-
iibull@BIG:/$ ros2 topic list
-
/camera_info
-
/image_raw
-
/image_raw/compressed
-
/image_raw/compressedDepth
-
/image_raw/theora
-
/parameter_events
-
/rosout
/image_raw/compressed 是不能被 Rviz2 or showimage 看的, 所以 image_transport 的 republish 节点可以做此转换。
ros2 run rqt_image_view rqt_image_view 使用 /image_raw 以及 /image_raw/compressed 话题可以看到图像.
-
ros2 run image_transport republish compressed --ros-args --remap in/compressed:=image_raw/compressed --ros-args --remap out:=image_raw/uncompressed
-
-
compressed - the transport to use for input, in this case 'compressed'. Alternative: raw, to republish the raw /image_raw topic
-
in/compressed:=image_raw/compressed - by default, republish uses the topics in and out, or in/compressed for example if the input transport is 'compressed'. This parameter is a ROS remapping rule to map those names to the actual topic to use.
-
raw - the transport to use for output. If omitted, all available transports are provided.
-
out:=image_raw/uncompressed - remapping of the output topic.
-
打开 rviz2. fixed frame 改成 camera, 然后添加 /image_raw/uncompressed 的topic 显示。 则可以看到图像了。
//现在进行校准。
参考
-
执行 ros2 run camera_calibration cameracalibrator
-
出现错误
-
RuntimeError: FATAL: module compiled as little endian, but detected different endianness at runtime
-
...
-
...
-
SystemError: initialization of cv_bridge_boost raised unreported exception
-
cv_bridge是OpenCV与ROS之间的格式转换桥梁。 higer 版本编译器中应当移除 boost endian APIs, 目前官网github上有改好的,ubuntu仓库还没有更新,需要手动编译。 (害得我查了很久)
解决方法: 参考
-
下载地址:https://github.com/ros-perception/vision_opencv
-
-
(这个仓库中包含多个包,下载之后只需要把cv_bridge拷贝到指定目录即可)
-
-
OK, 那么在自己的工作空间内。 git clone https://github.com/ros-perception/vision_opencv.git
-
cd vision_opencv/
-
git checkout ros2
-
colcon build --symlink-install
-
-
sudo apt install python3-numpy
-
pip3 install opencv-python
-
source 自己的安装目录/install/setup.bash
-
再次执行 cameracalibration 就没有问题了。
ros2 run camera_calibration cameracalibrator --size 7x9 --square 0.02 image:=/image_raw camera:=/custom_camera 命令成功后就会出现一个摄像头窗口
-
摄像头参数
-
Camera Name:
-
-c, --camera_name
-
name of the camera to appear in the calibration file ##校准文件中,摄像头的名字
-
-
棋盘参数
-
Chessboard Options:
-
You must specify one or more chessboards as pairs of --size and--square options.
-
-
-p PATTERN, --pattern=PATTERN
-
calibration pattern to detect - 'chessboard','circles', 'acircles','charuco'
-
-s SIZE, --size=SIZE
-
chessboard size as NxM, counting interior corners (e.g. a standard chessboard is 7x7)
-
-q SQUARE, --square=SQUARE
-
chessboard square size in meters
-
-
ROS 选项
-
ROS Communication Options:
-
--approximate=APPROXIMATE
-
allow specified slop (in seconds) when pairing images from unsynchronized stereo cameras
-
--no-service-check
-
disable check for set_camera_info services at startup
-
-
Calibration Optimizer Options:
-
-
--fix-principal-point
-
fix the principal point at the image center
-
--fix-aspect-ratio
-
enforce focal lengths (fx, fy) are equal
-
--zero-tangent-dist
-
set tangential distortion coefficients (p1, p2) to
-
zero
-
-k NUM_COEFFS, --k-coefficients=NUM_COEFFS
-
number of radial distortion coefficients to use (up to
-
6, default 2)
-
--disable_calib_cb_fast_check
-
uses the CALIB_CB_FAST_CHECK flag for findChessboardCorners
去 生成自己的 校准图片打印, 7x9要做8行10列的图
calib.pdf。直接放在屏幕上, 100%显示也是可以
前后左右上下移动, 同时各个方向上倾斜, 最终得到calibrate按钮可用并点击(
1分钟计算时间), 然后点击保存, 获得
“/tmp/calibrationdata.tar.gz”
tar -xvf calibration.tar.gz
-
iibull@BIG:/tmp$ tar -xvf calibrationdata.tar.gz
-
left-0000.png
-
left-0001.png
-
left-0002.png
-
left-0003.png
-
left-0004.png
-
left-0005.png
-
left-0006.png
-
left-0007.png
-
left-0008.png
-
left-0009.png
-
left-0010.png
-
left-0011.png
-
left-0012.png
-
left-0013.png
-
left-0014.png
-
left-0015.png
-
left-0016.png
-
left-0017.png
-
left-0018.png
-
left-0019.png
-
left-0020.png
-
left-0021.png
-
left-0022.png
-
left-0023.png
-
left-0024.png
-
left-0025.png
-
left-0026.png
-
left-0027.png
-
left-0028.png
-
left-0029.png
-
left-0030.png
-
left-0031.png
-
left-0032.png
-
left-0033.png
-
left-0034.png
-
left-0035.png
-
left-0036.png
-
left-0037.png
-
left-0038.png
-
left-0039.png
-
left-0040.png
-
left-0041.png
-
ost.yaml
-
ost.txt
ost.yaml 就是我们最终想要的校准文件。
修改 ost.yaml 文件中 的内存 camera_name: sunplusit_inc:_pc_camera
cp ost.yaml /home/iibull/.ros/camera_info/sunplusit_inc:_pc_camera.yaml
然后重启 v4l2
ros2 run v4l2_camera v4l2_camera_node --ros-args -p video_device:="/dev/video2" -r image_raw:=/my_camera/image_raw -r camera_info:=/
my_camera/camera_info -p camera_info_url:=file:///home/iibull/.ros/camera_info/mycamera.yaml
这里
mycamera.yaml是我自己的配置文件。
通过 ros2 topic echo /
my_camera/camera_info 看到输出的内容和
mycamera.yaml 内容是一样的。
-
目前官方的代码有些问题, 不支持 camera_info_url的导入。 只能自己修改一下。
-
git clone https://gitlab.com/boldhearts/ros2_v4l2_camera.git
-
-
-
vi src/ros2_v4l2_camera/src/v4l2_camera.cpp
-
添加
-
void V4L2Camera::createParameters()
-
{
-
// Node parameters
-
output_encoding_ = declare_parameter("output_encoding", std::string{"rgb8"});
-
declare_parameter("camera_info_url");
-
...
-
...
-
...
-
-
-
colcon build --symlink-install
-
source install/setup.bash
-
-
//删除旧的
-
sudo apt remove ros-rolling-v4l2-camera
阅读(3971) | 评论(0) | 转发(0) |