Apriltag码坐标系方向可视化

通过下面的脚本可以可视化tag_id为11的Apriltag码的坐标系个坐标轴的朝向:

import numpy as np
import apriltag
import cv2

img = cv2.imread('color_1.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
at_detector = apriltag.Detector(apriltag.DetectorOptions(families='tag16h5'))
tags = at_detector.detect(gray)
print("tags: {}".format(tags))

fx, fy, cx, cy = 593.0, 588.0, 311.0, 243.0 #相机内参
cam_params = [fx, fy, cx, cy]
K = np.array([[fx, 0, cx], [0, fy, cy], [0, 0, 1]])
for tag in tags:
    if tag.tag_id==11 :
        for i in range(4):
            cv2.circle(img, tuple(tag.corners[i].astype(int)), 4, (2, 180, 200), 2) #标记apriltag码角点
        cv2.circle(img, tuple(tag.center.astype(int)), 4, (2, 180, 200), 4) #标记apriltag码中心点
        M, e1, e2 = at_detector.detection_pose(tag, cam_params)
        P = M[:3,:4] #相机投影矩阵
        P = np.matmul(K,P)
        x = np.matmul(P,np.array([[1],[0],[0],[1]]))
        x = x / x[2]
        y = np.matmul(P,np.array([[0],[1],[0],[1]]))
        y = y / y[2]
        z = np.matmul(P,np.array([[0],[0],[1],[1]]))
        z = z / z[2]
        cv2.line(img, tuple(tag.center.astype(int)), tuple(x[:2].reshape(-1).astype(int)), (0,0,255), 2) #x轴红色
        cv2.line(img, tuple(tag.center.astype(int)), tuple(y[:2].reshape(-1).astype(int)), (0,255,0), 2) #y轴绿色
        cv2.line(img, tuple(tag.center.astype(int)), tuple(z[:2].reshape(-1).astype(int)), (255,0,0), 2) #z轴蓝色
        cv2.imwrite("mark.png",img)

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

给算法爸爸上香

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值