天天看點

ros使用usb攝像頭追蹤ArUco markers

ros使用usb攝像頭追蹤ArUco markers

先上效果圖

ros使用usb攝像頭追蹤ArUco markers

知識點

ArUco:基于OpenCV的增強現實程式使用的最小庫

增強現實技術(Augmented Reality,簡稱 AR)

ros wiki上是這樣說的:

http://wiki.ros.org/aruco_ros

The ARUCO Library has been developed by the Ava group of the Univeristy of Cordoba(Spain). It provides real-time marker based 3D pose estimation using AR markers.

aruco庫由科爾多瓦大學(西班牙)的AVA組開發。它使用AR标記,提供了基于三維位姿實時估計的标記。

Uco 是Univeristy of Cordoba縮寫,當然了解為Utility Compiler 實用編譯程式也很有意思

官方的連結

http://www.uco.es/investiga/grupos/ava/node/26

ArUco markers可了解為視覺識别程式使用的标記

标記類似二維碼

如下圖

ros使用usb攝像頭追蹤ArUco markers

在ros中可以利用它實作機器人視覺導航,但首先得用攝像頭識别這種标記,如何實作?

具體步驟這篇文章有介紹:

原文連結

http://sauravag.com/2015/03/how-to-tracking-aruco-marker-using-a-usb-webcam-and-ro/

引用過來翻譯一下,并做一些注意點的說明。

How To: Tracking ArUco markers using a USB Webcam and ROS

ros如何使用usb攝像頭追蹤ArUco markers

For my research I needed to setup ROS to use ArUco so that I could track these ArUco markers placed randomly in the environment and localize my robot.

Assuming that you have your catkin workspace setup, here are the steps:

經我研究,需要設定ROS使用aruco才能讓我追蹤這些随機放置在環境中的aruco标記并定位機器人。

假設你有你的工作空間,這裡的步驟:

1.  $cd ~/catkin_ws/src/

2. $git clone https://github.com/pal-robotics/aruco_ros.git

3. $cd ..

4. $catkin_make install

5. $sudo apt-get install ros-indigo-usb-cam

6. $source install/setup.bash

7. $cd src/aruco_ros/aruco_ros/launch/

Now you need to modify the single.launch file so that you remap the image and camera info to the topics published by usb_cam node.

現在你需要修改single.launch檔案,重新映射 通過usb_cam節點釋出的image和camera_info主題。

<launch>

<arg name=”markerId” default=”582″/>
<arg name=”markerSize” default=”0.034″/> <!– in m –>
<arg name=”eye” default=”left”/>
<arg name=”marker_frame” default=”aruco_marker_frame”/>
<arg name=”ref_frame” default=””/> <!– leave empty and the pose will be published wrt param parent_name –>
<node pkg=”aruco_ros” type=”single” name=”aruco_single”>

<!-- 注意這裡 -->
<remap from=”/camera_info” to=”/usb_cam/camera_info” />
<remap from=”/image” to=”/usb_cam/image_raw” />



<param name=”image_is_rectified” value=”True”/>
<param name=”marker_size” value=”$(arg markerSize)”/>
<param name=”marker_id” value=”$(arg markerId)”/>
<param name=”reference_frame” value=”$(arg ref_frame)”/> <!– frame in which the marker pose will be refered –>
<param name=”camera_frame” value=”stereo_gazebo_$(arg eye)_camera_optical_frame”/>
<param name=”marker_frame” value=”$(arg marker_frame)” />
</node>

</launch>
           

8. Open 4 terminal windows:

開四個終端分别運作指令:

Terminal 1: $roscore

Terminal 2: $roslaunch usb_cam-stream.launch

First paste this into a new file named usb_cam-stream.launch:

先要把下面的代碼粘貼到usb_cam-stream.launch檔案。

<launch>
<node name=”usb_cam” pkg=”usb_cam” type=”usb_cam_node” output=”screen” >
<param name=”video_device” value=”/dev/video0″ />
<param name=”image_width” value=”640″ />
<param name=”image_height” value=”480″ />
<param name=”pixel_format” value=”mjpeg” />
<param name=”camera_frame_id” value=”usb_cam” />
<param name=”io_method” value=”mmap”/>
</node>
</launch>
           

注意

參數要根據自己攝像頭硬體做更改,我的如下:

<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video0" />
    <param name="image_width" value="640" />
    <param name="image_height" value="480" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap"/>
  </node>
           

Terminal 3:

$cd ~/catkin_ws/src/aruco_ros/aruco_ros/launch/

$roslaunch single.launch

Terminal 4: $rosrun image_view image_view image:=/aruco_single/result

怎樣制作一個ArUco marker?

這個網頁實作了一個線上的生成器,效果不錯。

http://terpconnect.umd.edu/~jwelsh12/enes100/markergen.html

ArUco markers Generator

ArUco markers 生成器

This form will create an HTML page containing a marker that is compatible with the Aruco marker detection algorithm.

Marker Id: the unique id that will be encoded in the marker image.

Marker Size: the edge size of the black box containing the marker.

Marker Padding: the thickness of the white border surrounding the marker.

這個表單将建立包含标記的一個html頁面,其算法與aruco标記檢測算法相容。

Marker Id:标記圖像編碼的唯一id。

Marker Size:包含标記黑框邊的尺寸。

Marker Padding:标記填充一圈白色邊框的厚度。

這裡需要根據上文提到的single.launch檔案裡的參數來制作這個ArUco marker

<arg name=”markerId” default=”582″/>
<arg name=”markerSize” default=”0.034″/> <!– in m –>
           

送出表單後你就會在頁面中看到一個mark圖,可以列印出來了。

同時在這個launch檔案設定自己usb camera 标定參數。

缺少标定會有transform的錯誤出現

設定标定參數的代碼

<param name="camera_info_url" value="package://usb_cam/launch/calibration_webcam.yaml"/>
           

此時打開終端launch一下,你就能看到開篇的圖了。

其他參考

How to create markers for ARUCO?

http://iplimage.com/blog/create-markers-aruco/

[OpenCV] aruco Markers識别

http://blog.csdn.net/ZJU_fish1996/article/details/72312514?locationNum=7&fps=1

基于arucoTag的簡單slam

http://blog.csdn.net/u010566411/article/details/54692254