ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to access apriltag_ros, tag_id pixel position

asked 2020-12-08 14:54:50 -0500

Hamid Osooli gravatar image

updated 2022-07-02 08:18:35 -0500

lucasw gravatar image

Im using this repo for my simulation. It uses apriltag_ros package and works fine in tracking. My question is, how to find the pixel position for the tag_id highlighted in /tag_detections_image. In other words, I want to find the central point of the tag in images (in pixel unit) that is similar to the marked location in /tag_detections_image with tag id.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-12-30 13:18:16 -0500

Hamid Osooli gravatar image

Let me answer my question. The tag 3D position w.r.t. camera is available in /tag_detections topic. Then I use image_geometry.PinholeCameraModel to project 3D point into 2D pixel location as shown here. My python piece of code for the mentioned repository is shown below.

from apriltag_ros.msg import AprilTagDetectionArray
from image_geometry import PinholeCameraModel
from sensor_msgs.msg import CameraInfo

class TagPixel:
    def __init__(self):
        rospy.Subscriber('tag_detections', AprilTagDetectionArray, self.TagPoseCallback)
        rospy.Subscriber('cgo3_camera/camera_info', CameraInfo, self.TagePixelCallback)
        self.pos_x = 0.0
        self.pos_y = 0.0
        self.pos_z = 0.0

    def TagPoseCallback(self, msg):
        valid = False
        if len(msg.detections) > 0:
            valid = True
        if valid:
            self.pos_x = -msg.detections[0].pose.pose.pose.position.y
            self.pos_y = -msg.detections[0].pose.pose.pose.position.z
            self.pos_z = msg.detections[0].pose.pose.pose.position.x

    def TagePixelCallback(self, msg):
        self.pcm = PinholeCameraModel()
        self.p_image = self.pcm.project3dToPixel((self.pos_x, self.pos_y, self.pos_z))
        rospy.loginfo("Pixel position is u = %s, v = %s", self.p_image[0], self.p_image[1])
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-12-08 14:54:50 -0500

Seen: 202 times

Last updated: Dec 30 '20