AprilTag タグ追跡

ビデオ チュートリアル 11 - AprilTag タグの追跡: https://singtown.com/learn/49590/
ビデオ チュートリアル 21 - 他の物体を追いかける車: https://singtown.com/learn/50041/

AprilTag の紹介

情報: https://april.eecs.umich.edu/software/apriltag.html

AprilTag は、AR、ロボティクス、カメラ キャリブレーションなどのさまざまなタスクに使用できるビジュアル ベンチマーク システムです。タグはプリンタで直接印刷でき、AprilTag 検出プログラムはカメラを基準とした正確な 3D 位置、方向、ID を計算できます。 OpenMV の場合、これは特に便利です。 おそらく次のようになります。

簡単に言うと、ターゲットにタグが付いていれば、OpenMV上でそのタグの3次元位置とIDが特定できます。

Aprilタグの種類

AprilTagの種類はファミリーと呼ばれ、以下の種類があります。

TAG16H5→0~29\ TAG25H7→0~241\ TAG25H9→0~34\ TAG36H10 → 0~2319\ TAG36H11 → 0~586\ アートツールキット→0~511\ つまり、TAG16H5 には 30 のファミリーがあり、それぞれに 0 から 29 までの対応する ID があります。

それでは、さまざまな家族の違いは何でしょうか?

例えば、TAG16H5の有効エリアは4×4マスなので、TAG36H11よりも遠くまで見ることができます(6×6マスなので)。ただし、TAG36H11 の方が検証情報が多いため、TAG16H5 のエラー率は TAG36H11 よりもはるかに高くなります。そのため、他に理由がない場合は、TAG36H11** を使用することをお勧めします。

Aprilタグを作る

非常に簡単です。インターネットからダウンロードすることも、OpenMV IDE から直接生成することもできます。 Tools-Machine Vision-AprilTag Generateでファミリを選択します。TAG36H11を使用することをお勧めします。

次に、生成する必要がある数を入力します。たとえば、10 個必要な場合は、ID 0 ~ 9 の画像が生成されます。

次に、写真が保存されているフォルダーを選択するだけです。

すると、このフォルダー内に画像が生成されます。

最後に、プリンターで画像を印刷します(もちろん、画面を直接使用することもできますが、反射する可能性があります)。

プログラム

# 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(30)
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()

while(True):
    clock.tick()
    img = sensor.snapshot()
    for tag in img.find_apriltags(): # defaults to TAG36H11 without "families".
        img.draw_rectangle(tag.rect(), color = (255, 0, 0))
        img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
        degress = 180 * tag.rotation() / math.pi
        print(tag.id(),degress)

ご覧のとおり、ID が 0、回転角度、位置が識別できます。\

3Dポジショニング

AprilTag の最も素晴らしい点は、タグの空間位置を 3 つの位置と 3 つの角度で知ることができる 3D 位置決め機能です。

# 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(30)
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()

# 注意!与find_qrcodes不同,find_apriltags 不需要软件矫正畸变就可以工作。

# 注意,输出的姿态的单位是弧度,可以转换成角度,但是位置的单位是和你的大小有关,需要等比例换算

# f_x 是x的像素为单位的焦距。对于标准的OpenMV,应该等于2.8/3.984*656,这个值是用毫米为单位的焦距除以x方向的感光元件的长度,乘以x方向的感光元件的像素(OV7725)
# f_y 是y的像素为单位的焦距。对于标准的OpenMV,应该等于2.8/2.952*488,这个值是用毫米为单位的焦距除以y方向的感光元件的长度,乘以y方向的感光元件的像素(OV7725)

# c_x 是图像的x中心位置
# c_y 是图像的y中心位置

f_x = (2.8 / 3.984) * 160 # 默认值
f_y = (2.8 / 2.952) * 120 # 默认值
c_x = 160 * 0.5 # 默认值(image.w * 0.5)
c_y = 120 * 0.5 # 默认值(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): # 默认为TAG36H11
        img.draw_rectangle(tag.rect(), color = (255, 0, 0))
        img.draw_cross(tag.cx(), tag.cy(), color = (0, 255, 0))
        print_args = (tag.x_translation(), tag.y_translation(), tag.z_translation(), \
            degrees(tag.x_rotation()), degrees(tag.y_rotation()), degrees(tag.z_rotation()))
        # 位置的单位是未知的,旋转的单位是角度
        print("Tx: %f, Ty %f, Tz %f, Rx %f, Ry %f, Rz %f" % print_args)
    print(clock.fps())

シリアル ポート出力は 6 変数で、Tx、Ty、Tz は空間内の 3 つの位置量、Rx、Ry、Rz は 3 つの回転量です。

さらに読む:

  • Xingtong Lab APP より: 認識中に Apriltag を特定/範囲設定するにはどうすればよいですか?出力tx ty tzの単位は何ですか?実際の距離はどうやって知るのですか? https://forum.singtown.com/topic/52

results matching ""

    No results matching ""