• openmv之ApriTag


    AprilTag是一个视觉基准系统,可用于各种任务,包括AR,机器人和相机校准。这个tag可以直接用打印机打印出来,而AprilTag检测程序可以计算相对于相机的精确3D位置,方向和id。对于OpenMV来说,这个特别有用! 它大概长这个样子:

    AprilTag的种类

    AprilTag的种类叫家族(family),有下面的几种:

    TAG16H5 → 0 to 29
    TAG25H7 → 0 to 241
    TAG25H9 → 0 to 34
    TAG36H10 → 0 to 2319
    TAG36H11 → 0 to 586
    ARTOOLKIT → 0 to 511
    也就是说TAG16H5的家族(family)有30个,每一个都有对应的id,从0~29。

    那么不同的家族,有什么区别呢?

    比如说TAG16H5的有效区域是4 x 4的方块,那么它比TAG36H11看的更远(因为他有6 x 6个方块)。但是TAG16H5的错误率比TAG36H11高很多,因为TAG36H11的校验信息多,所以,如果没有别的理由,推荐用TAG36H11。

    这些图像可以在网络下载也可以在openmv的IDE中生成

     1 # AprilTags Example
     2 #
     3 # This example shows the power of the OpenMV Cam to detect April Tags
     4 # on the OpenMV Cam M7. The M4 versions cannot detect April Tags.
     5 
     6 import sensor, image, time, math
     7 
     8 sensor.reset()
     9 sensor.set_pixformat(sensor.RGB565)
    10 sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
    11 sensor.skip_frames(30)
    12 sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
    13 sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
    14 clock = time.clock()
    15 
    16 while(True):
    17     clock.tick()
    18     img = sensor.snapshot()
    19     for tag in img.find_apriltags(): # defaults to TAG36H11 without "families".
    20         img.draw_rectangle(tag.rect(), color = (255, 0, 0))
    21         img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
    22         degress = 180 * tag.rotation() / math.pi
    23         print(tag.id(),degress)

    第8行初始化摄像头

    第9行设置图像格式为RGB565

    第10行时QQVGA图像的格式

    第11行跳过30秒,使新设置生效

    第12行关闭自动增益。默认开启的,在颜色时别中一定要关闭

    第13行关闭白平衡,默认开启,在颜色时别中一定要关闭

    第14行追踪帧率

    第18行从感光芯片获得一张图像

    第19行在图片中找到家族中的图像

    第20行画方框,draw_rectangle((x,y,w,h) , color = White)该函数的参数,x,y是方框的左上角的坐标,w,h是宽和高

      tag.rect()

      apriltag.rect()方法

      返回一个矩形元组(x, y, w, h),用于如AprilTag边界框的 image.draw_rectangle 等其他的 image 方法。

      color为方框的颜色

    第21行draw_cross(x,y,size = 5,color = White) 画十字先,x,y是十字的中心,size是两侧的尺寸,color是颜色

      tag.cx  ,  tag.cy是ApriTag的中心位置,

    第22行是弧度制转角度制

    第23行打印ApriTag的id号 和旋转的角度

    右上角为所检测到的ApriTag

    左下角为id号

  • 相关阅读:
    PHP定时任务实现(计划任务 vs node.js)
    第三方支付,代支付接口调用
    iframe调用页面中的局部部分
    树状数据删除(TP5)
    PHP 代码编写注意事项总结归纳
    MySQL 存储过程与事物
    radio与checkbox的选中事件
    简单十步让你全面理解SQL
    生成条形码
    使2个div 在一行上显示
  • 原文地址:https://www.cnblogs.com/miaorn/p/12238207.html
Copyright © 2020-2023  润新知