视频流识别Tag码

        在许多竞赛中,我们常常使用Tag码为比赛场地打上标签,参赛机器需要识别Tag码获取

下一步的指令,因此这期我们来介绍如何在opencv中识别Tag码。

一、环境

安装所需库;

pip install pupil_apriltag

识别tag码前我们需要了解所识别的tag码属于哪个家族;

正方形tag有以下三个家族:tag16h5,tag25h9,tag36h11

二、识别

以下是调用摄像头识别tag25h9家族的代码

import cv2
import pupil_apriltags as pl  # 在 windows 下引入该库


cap = cv2.VideoCapture(0)  # 获取摄像头
options = pl.Detector(families='tag25h9',debug=True)

while True:
    ret, image1 = cap.read()
    gray = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)#转灰度图
    tags = options.detect(gray)
    for tag in tags:
        id = tag.tag_id  # 获取id
        # 获取4个角点的坐标
        b = tuple(tag.corners[0].astype(int))
        c = tuple(tag.corners[1].astype(int))
        d = tuple(tag.corners[2].astype(int))
        a = tuple(tag.corners[3].astype(int))
        # 绘制检测到的AprilTag的框
        cv2.line(image1, a, b, (255, 0, 255), 5, lineType=cv2.LINE_AA)
        cv2.line(image1, b, c, (255, 0, 255), 5, lineType=cv2.LINE_AA)
        cv2.line(image1, c, d, (255, 0, 255), 5, lineType=cv2.LINE_AA)
        cv2.line(image1, d, a, (255, 0, 255), 5, lineType=cv2.LINE_AA)
        # 绘制 AprilTag 的中心坐标
        (cX, cY) = (int(tag.center[0]), int(tag.center[1]))
        cv2.circle(image1, (cX, cY), 5, (0, 0, 255), -1)  # 画出中心坐标点
        # 在图像上绘制标文本
        cv2.putText(image1, str(id), (cX, cY), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
        tagFamily = tag.tag_family.decode("utf-8")
        cv2.putText(image1, tagFamily + " id:" + str(id), (a[0], a[1] - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0),
                    2)  # 画出家族名和id


    cv2.imshow("Apriltags", image1)
    # 检测按键
    k=cv2.waitKey(1)#按'esc'退出
    if k==27:
        break
cv2.destroyAllWindows()

运行视频录制;

链接:https://pan.baidu.com/s/17NUhQWDoHosXi9QqVtZnKQ?pwd=lerg 
提取码:lerg

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值