logo

AprilTag测距准确性问题,是否需要做相机参数校准标定?

2020-09-05 17:35
2
rchx

使用find_apriltags_3d_pose例程来获取AprilTag相对于相机的6-DOF位姿,但是当相机保持固定,在和相机距离恒定的墙面上移动AprilTag(从视野到边缘)却发现Z方向位移值一直有变化,理论上这不应该呀,这个误差是由什么造成的呢?是和镜头畸变有关吗?但是例程注释里说识别AprilTag不需要对相机做校准呀。

2020-09-07 13:40
I
网红小智智 星瞳科技

z方向是标签和OpenMV的距离轴。这个是通过画面中的大小计算的。

I
网红小智智 星瞳科技

你提供一下具体的代码,误差数据,

和实际场景的照片,和OpenMV画面里标签的大小的照片。

2020-09-14 03:23
2
rchx

代码就是IDE中AprilTag定位的例程(位移乘了个k换算成了实际距离):

# AprilTags Example
#
# This example shows the power of the OpenMV Cam to detect April Tags
# on the OpenMV Cam M7. The M4 versions cannot detect April Tags.

import sensor, image, time, math

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger...
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False)  # must turn this off to prevent image washout...
sensor.set_auto_whitebal(False)  # must turn this off to prevent image washout...
clock = time.clock()

tag_families = 0
tag_families |= image.TAG16H5 # comment out to disable this family
tag_families |= image.TAG25H7 # comment out to disable this family
tag_families |= image.TAG25H9 # comment out to disable this family
tag_families |= image.TAG36H10 # comment out to disable this family
tag_families |= image.TAG36H11 # comment out to disable this family (default family)
tag_families |= image.ARTOOLKIT # comment out to disable this family

# What's the difference between tag families? Well, for example, the TAG16H5 family is effectively
# a 4x4 square tag. So, this means it can be seen at a longer distance than a TAG36H11 tag which
# is a 6x6 square tag. However, the lower H value (H5 versus H11) means that the false positve
# rate for the 4x4 tag is much, much, much, higher than the 6x6 tag. So, unless you have a
# reason to use the other tags families just use TAG36H11 which is the default family.

def family_name(tag):
    if(tag.family() == image.TAG16H5):
        return "TAG16H5"
    if(tag.family() == image.TAG25H7):
        return "TAG25H7"
    if(tag.family() == image.TAG25H9):
        return "TAG25H9"
    if(tag.family() == image.TAG36H10):
        return "TAG36H10"
    if(tag.family() == image.TAG36H11):
        return "TAG36H11"
    if(tag.family() == image.ARTOOLKIT):
        return "ARTOOLKIT"

# Note! Unlike find_qrcodes the find_apriltags method does not need lens correction on the image to work.

# What's the difference between tag families? Well, for example, the TAG16H5 family is effectively
# a 4x4 square tag. So, this means it can be seen at a longer distance than a TAG36H11 tag which
# is a 6x6 square tag. However, the lower H value (H5 versus H11) means that the false positve
# rate for the 4x4 tag is much, much, much, higher than the 6x6 tag. So, unless you have a
# reason to use the other tags families just use TAG36H11 which is the default family.

# The AprilTags library outputs the pose information for tags. This is the x/y/z translation and
# x/y/z rotation. The x/y/z rotation is in radians and can be converted to degrees. As for
# translation the units are dimensionless and you must apply a conversion function.

# f_x is the x focal length of the camera. It should be equal to the lens focal length in mm
# divided by the x sensor size in mm times the number of pixels in the image.
# The below values are for the OV7725 camera with a 2.8 mm lens.

# f_y is the y focal length of the camera. It should be equal to the lens focal length in mm
# divided by the y sensor size in mm times the number of pixels in the image.
# The below values are for the OV7725 camera with a 2.8 mm lens.

# c_x is the image x center position in pixels.
# c_y is the image y center position in pixels.

f_x = (2.8 / 3.984) * 160 # find_apriltags defaults to this if not set
f_y = (2.8 / 2.952) * 120 # find_apriltags defaults to this if not set
c_x = 160 * 0.5 # find_apriltags defaults to this if not set (the image.w * 0.5)
c_y = 120 * 0.5 # find_apriltags defaults to this if not set (the image.h * 0.5)

def degrees(radians):
    return (180 * radians) / math.pi

while(True):
    clock.tick()
    img = sensor.snapshot()
    for tag in img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y): # defaults to TAG36H11
        img.draw_rectangle(tag.rect(), color = (255, 0, 0))
        img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
        print_args = (family_name(tag), tag.id(), tag.x_translation()*4.317, tag.y_translation()*4.317, tag.z_translation()*4.317, \
            degrees(tag.x_rotation()), degrees(tag.y_rotation()), degrees(tag.z_rotation()))
        # Translation units are unknown. Rotation units are in degrees.
        print("Tag Family %s, Tag ID %d, Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args)
    print(clock.fps())
image
48fc0526-9b0c-4a23-9f37-e9eff6ac0197.png
6014bff6-ab86-4f96-b7f0-302e65b51afa.png
844a7f1b-cf0e-479b-8319-6a4204d3c660.png
2084692d-f6a6-4314-a8ff-6b308bd4cc25.png

场景和结果如图,AprilTag紧贴墙平移,OpenMV固定在和墙平移距墙恒定的位置,按说Ty Tz应该在平移过程中保持不变,但尤其Z方向,有一个0.5cm左右的误差

2020-09-14 03:31
2
rchx

@kidswong999 代码和图片如上,场景图片显示失败,就是AprilTag靠墙平移,摄像头粘在盒子上固定在和墙平行且距离恒定的位置。

那请问X和Y方向是怎么实现定位的呢?可以提供底层代码吗?

2020-09-14 14:09
I
网红小智智 星瞳科技

apriltag算法源码:

https://github.com/openmv/openmv/blob/master/src/omv/img/apriltag.c

2020-09-14 17:39
2
rchx

@kidswong999

那请问对如图的Y和Z方向的误差的原因,有什么见解呢?