AprilTag_ros的使用

本文详细介绍了在Ubuntu 20.04和ROS noetic环境下,如何使用USB摄像头、安装及标定AprilTag_ros,包括摄像头安装、依赖库安装、单目摄像机标定过程,以及AprilTag_ros的配置和标签检测的实现,旨在提供一个完整的AprilTag_ros使用流程。
摘要由CSDN通过智能技术生成

目录

前言

一、 usb摄像头的安装和使用

​ 二、AprilTag_ros包的安装

三、单目摄像机的标定

四、AprilTag_ros的使用

五、其他


前言

平台:VM虚拟机

ROS版本:noetic

Ubuntu:20.04LTS

一、 usb摄像头的安装和使用

1. 下载源码

cd catkin_ws/src  #安装在一个ROS工作空间上
git clone https://github.com/bosch-ros-pkg/usb_cam.git  #下载源码

在这里插入图片描述

2.编译工作空间

cd ..  #回到工作空间
ctakin_make   #进行编译

在这里插入图片描述

3. 添加usb_cam属性文件(用于终端窗口可检索到usb_cam功能包)

source ./devel/setup.bash  #每打开一次工作空间窗口都要

4. 编译usb_cam源码

回到工作空间的src文件中,再去usb_cam中进行编译

cd usb_cam
mkdir build
cd build
cmake ..  ##注意后面的两点

make    #####

 5.测试USB摄像头

    1)运行ROS

roscore

    2) 回到usb_cam的launch文件夹中,运行usb_cam的功能包

cd launch
roslaunch usb_cam usb_cam-test.launch

 二、AprilTag_ros包的安装

    1. 安装依赖库apriltag

        安装方法如下。这个注意不要把它放到ROS的工作空间里,看你自己放在哪吧。

git clone https://github.com/AprilRobotics/apriltag.git      # 这个不是ros的功能包

 2.  编译依赖库apriltag 

        进入apriltag 文件夹中,然后新建文件夹build

mkdir build
cd build
cmake ..  ## 注意两点
make
sudo make install  #安装到ros中

3. 安装AprilTag_ros包

        将源码拷贝到你的工作空间中的src工作目录下

git clone https://github.com/AprilRobotics/apriltag_ros.git  #在src文件夹内

4. 回到工作空间进行编译

catkin_make

三、单目摄像机的标定

        摄像机标定是通过寻找对象在图像与现实世界的转换数学关系,找出其定量的联系,从而实现从图像中测量出现实中实际数据的目的,基于此才能实现后面的位姿检测。

   1. 安装标定功能包

sudo apt-get install ros-melodic-camera-calibration

  2. 打开摄像头进行标定

roslaunch usb_cam usb_cam-test.launch  #启动摄像头
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.024 image:=/usb_cam/image_raw camera:=/usb_cam

第二条命令参数说明:
size:棋盘内

Apriltag is a popular library for detecting and identifying visual fiducial markers called tags. The `apriltag_ros` package is a ROS wrapper for the Apriltag library, allowing you to use Apriltag functionalities within a ROS environment. It provides ROS nodes that can subscribe to image topics, detect Apriltags in the images, and publish the detected tag poses. To use `apriltag_ros` in Python, you can follow these steps: 1. Install the `apriltag_ros` package: ```bash sudo apt-get install ros-<distro>-apriltag-ros ``` Replace `<distro>` with your ROS distribution (e.g., melodic, noetic). 2. Create a ROS package (if you haven't already) where you'll write your Python code: ```bash cd ~/catkin_ws/src catkin_create_pkg my_apriltag_pkg rospy apriltag_ros ``` Replace `my_apriltag_pkg` with your desired package name. 3. In your Python script, import the necessary modules: ```python #!/usr/bin/env python import rospy from sensor_msgs.msg import Image from cv_bridge import CvBridge from apriltag_ros.msg import AprilTagDetectionArray ``` 4. Initialize the ROS node and create a subscriber to the image topic: ```python rospy.init_node('apriltag_detector') bridge = CvBridge() def image_callback(msg): cv_image = bridge.imgmsg_to_cv2(msg, desired_encoding='passthrough') # Perform Apriltag detection using cv_image image_sub = rospy.Subscriber('/camera/image_raw', Image, image_callback) ``` Replace `/camera/image_raw` with the appropriate image topic for your setup. 5. Process the received image in the callback function and publish the detected tag poses: ```python def image_callback(msg): cv_image = bridge.imgmsg_to_cv2(msg, desired_encoding='passthrough') # Perform Apriltag detection using cv_image # Publish the detected tag poses detection_array = AprilTagDetectionArray() # Populate detection_array with detected tag poses pub = rospy.Publisher('/apriltag/detections', AprilTagDetectionArray, queue_size=10) pub.publish(detection_array) ``` Replace `/apriltag/detections` with the desired topic to publish the detected tag poses. 6. Finally, run your ROS node: ```bash rosrun my_apriltag_pkg my_apriltag_node.py ``` Remember to replace `my_apriltag_pkg` and `my_apriltag_node.py` with your actual package and node names. This is a basic example to get you started with `apriltag_ros` in Python. You can find more information about the package and its functionalities in the official ROS documentation and the `apriltag_ros` GitHub repository.
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值