使用iai_kinect2标定kinectV2相机
實驗背景:因為需要制作bundlefusion需要的數據集,所以需要使用kinectV2相機獲取rgbd圖像,年前的時候在我的筆記本上安裝了libfreenect2庫和iai_kinect2,標定過一次kinecv2相機,然后使用kinectv2相機實時獲取的圖像實現elasticfusion稠密重建.但是由于當時時間緊迫,很多東西都沒有搞明白,所以趁這次機會將一些問題整理一下,記錄一下.
環境搭建:
1. 安裝了ROS的kinetic版本
libfreenect2和iai_kinect2的安裝參考文章: https://www.cnblogs.com/li-yao7758258/p/7445429.html
2. 下載libfreenect2
$ cd Downloads $ git clone https://github.com/OpenKinect/libfreenect2.git3.安裝libfreenect2的依賴
sudo apt-get install build-essential cmake pkg-config libturbojpeg libjpeg-turbo8-dev mesa-common-dev freeglut3-dev libxrandr-dev libxi-dev安裝libusb sudo apt-add-repository ppa:floe/libusb sudo apt-get update sudo apt-get install libusb-1.0-0-dev安裝GLFW3 cd libfreenect2/depends sh install_ubuntu.sh sudo dpkg -i libglfw3*_3.0.4-1_*.deb4.? 繼續安裝libfreenect2庫
$ cd libfreenect2 $ mkdir build $ cmake ../ $ make -j4 $ sudo make install5. 使用lsusb指令測試kinectv2相機有沒有鏈接成功.
6. 編譯iai_kinect2
$ cd ~/ROS #在/home/yunlei下創建了一個ROS文件夾,專門盛放ros的工程 $ mkdir -r ./iai_kinect2_ws/src/ $ cd ./iai_kinect2/src $ git clone https://github.com/code-iai/iai_kinect2.git $ cd iai_kinect2 $ rosdep install -r --from-paths . $ cd ~/ROS/iai_kinect2 $ catkin_make -DCMAKE_BUILD_TYPE="Release" $ rospack profile7. 測試kinectv2相機是否鏈接成功
$ cd Download $ cd libfreenect $ cd build/bin $ ./Protonect如果一切正常的話,相機拍攝的畫面將映入眼簾.?
?8. 測試kinectv2圖像數據
$ cd ~/ROS/iai_kinect2_ws $ source ./devel/setup.bash $ roslaunch kinect2_bridge kinect2_bridge.launch# open a new terminal $ rosrun kinect2_viewer kinect2_viewer(但是我這里執行失敗)9. 查看此時發布的與kinect相關的topics
/kinect2/bond /kinect2/hd/camera_info /kinect2/hd/image_color /kinect2/hd/image_color/compressed /kinect2/hd/image_color_rect /kinect2/hd/image_color_rect/compressed /kinect2/hd/image_depth_rect /kinect2/hd/image_depth_rect/compressed /kinect2/hd/image_mono /kinect2/hd/image_mono/compressed /kinect2/hd/image_mono_rect /kinect2/hd/image_mono_rect/compressed /kinect2/hd/points /kinect2/qhd/camera_info /kinect2/qhd/image_color /kinect2/qhd/image_color/compressed /kinect2/qhd/image_color_rect /kinect2/qhd/image_color_rect/compressed /kinect2/qhd/image_depth_rect /kinect2/qhd/image_depth_rect/compressed /kinect2/qhd/image_mono /kinect2/qhd/image_mono/compressed /kinect2/qhd/image_mono_rect /kinect2/qhd/image_mono_rect/compressed /kinect2/qhd/points /kinect2/sd/camera_info /kinect2/sd/image_color_rect /kinect2/sd/image_color_rect/compressed /kinect2/sd/image_depth /kinect2/sd/image_depth/compressed /kinect2/sd/image_depth_rect /kinect2/sd/image_depth_rect/compressed /kinect2/sd/image_ir /kinect2/sd/image_ir/compressed /kinect2/sd/image_ir_rect /kinect2/sd/image_ir_rect/compressed /kinect2/sd/points10. 打開/home/yunlei/ROS/iai_kinect2_ws/src/iai_kinect2/kinect2_bridge/launch/kinect2_bridge.launch查看kinect相機的分辨率
<!-- sd point cloud (512 x 424) --><node pkg="nodelet" type="nodelet" name="$(arg base_name)_points_xyzrgb_sd" machine="$(arg machine)"args="load depth_image_proc/point_cloud_xyzrgb $(arg nodelet_manager)" respawn="$(arg respawn)"><remap from="rgb/camera_info" to="$(arg base_name)/sd/camera_info"/><remap from="rgb/image_rect_color" to="$(arg base_name)/sd/image_color_rect"/><remap from="depth_registered/image_rect" to="$(arg base_name)/sd/image_depth_rect"/><remap from="depth_registered/points" to="$(arg base_name)/sd/points"/><param name="queue_size" type="int" value="$(arg queue_size)"/></node><!-- qhd point cloud (960 x 540) --><node pkg="nodelet" type="nodelet" name="$(arg base_name)_points_xyzrgb_qhd" machine="$(arg machine)"args="load depth_image_proc/point_cloud_xyzrgb $(arg nodelet_manager)" respawn="$(arg respawn)"><remap from="rgb/camera_info" to="$(arg base_name)/qhd/camera_info"/><remap from="rgb/image_rect_color" to="$(arg base_name)/qhd/image_color_rect"/><remap from="depth_registered/image_rect" to="$(arg base_name)/qhd/image_depth_rect"/><remap from="depth_registered/points" to="$(arg base_name)/qhd/points"/><param name="queue_size" type="int" value="$(arg queue_size)"/></node><!-- hd point cloud (1920 x 1080) --><node pkg="nodelet" type="nodelet" name="$(arg base_name)_points_xyzrgb_hd" machine="$(arg machine)"args="load depth_image_proc/point_cloud_xyzrgb $(arg nodelet_manager)" respawn="$(arg respawn)"><remap from="rgb/camera_info" to="$(arg base_name)/hd/camera_info"/><remap from="rgb/image_rect_color" to="$(arg base_name)/hd/image_color_rect"/><remap from="depth_registered/image_rect" to="$(arg base_name)/hd/image_depth_rect"/><remap from="depth_registered/points" to="$(arg base_name)/hd/points"/><param name="queue_size" type="int" value="$(arg queue_size)"/>可以發現kinecv2相機可以直接獲取的圖像的分辨率有三個,分別是:hd(1920x1080), qhd(960x540), sd(512x424),每一種分辨率又對應了彩色圖,灰度圖,深度圖,以及是否是經過去畸變處理的,深度圖是否和彩色圖配準.
11. 如果你想獲取rect圖像,那么你需要給定相應分辨率的相機內參數,而此時使用的是默認/iai_kinect2/kinect2_bridge/data下的相機參數,所以你需要標定你需要的分辨率的相機參數.
12.關于數據獲取,如果我標定了960x540的相機內參數,獲取了去畸變后的而圖像,我直接使用rosbag record指令,錄制相應的topic就可以了.所以現在最關鍵的是標定相機
13. iai_kinect2中也提供了標定工具,在/home/yunlei/ROS/iai_kinect2_ws/src/iai_kinect2/kinect2_calibration中,不過此時在/home/yunlei/ROS/iai_kinect2_ws/src/iai_kinect2/kinect2_calibration/src/kinect2_calibration.cpp文件中默認是標定1920x1080的圖像,如果想要標定960x540的相機內參數,則需要將文件1349行中的HD改為QHD
將原來的
std::string topicColor = "/" + ns + K2_TOPIC_HD + K2_TOPIC_IMAGE_MONO; std::string topicIr = "/" + ns + K2_TOPIC_SD + K2_TOPIC_IMAGE_IR; std::string topicDepth = "/" + ns + K2_TOPIC_SD + K2_TOPIC_IMAGE_DEPTH;改為?
std::string topicColor = "/" + ns + K2_TOPIC_QHD + K2_TOPIC_IMAGE_MONO; std::string topicIr = "/" + ns + K2_TOPIC_SD + K2_TOPIC_IMAGE_IR; std::string topicDepth = "/" + ns + K2_TOPIC_SD + K2_TOPIC_IMAGE_DEPTH;我剛開始改成了SD但是這種情況下,當你執行rosrun kinect2_calibration kinect2_calibration chess5x7x0.03 record color指令時,沒有彈出圖像窗口,無法保存圖像,并且提示
[ERROR] Tried to advertise a service that is already advertised in this node [/kinect2_calib_1591865100768222736/compressed/set_parameters] [ERROR] Tried to advertise a service that is already advertised in this node [/kinect2_calib_1591865100768222736/compressed/set_parameters]我剛開始根據這個錯誤提示去搜索出了什么問題,但是有網友說這個不影響標定,(https://blog.csdn.net/weixin_30536513/article/details/94969881)但是我這里確實影響了.我折騰了好久,但是還是沒有解決這個問題,當我想放棄的時候,突然想起來,我可以把上面的SD改為QHD試試.果然,當我改成了QHD后發現,雖然還是會有上面的錯誤的提示,但是此時彈出了圖像窗口,當我拿著標定板進入相機的視野時,他可以檢測到標定板子上的特征點,哇,我好開心.
總結
以上是生活随笔為你收集整理的使用iai_kinect2标定kinectV2相机的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在ASP.NET Core使用Middl
- 下一篇: 动感标题文字快闪(闪白特效)开场PR模板