2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TouchDesignerでArUcoマーカーのコーナーを可視化する

Last updated at Posted at 2020-12-20

はじめに

困っている人がいたので数か月前にやってみたやつです。

開発環境

  • Touch Designer
  • OpenCV
  • Python

導入

始め方はこちらを参考にします。

マーカーの生成

arucoマーカーを30種類生成します。

import cv2
aruco = cv2.aruco
dictionary = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)

def arGenerator():
    for i in range(30):
        fileName = "{}.png".format(i)
        generator = aruco.drawMarker(dictionary, i, 100)
        cv2.imwrite(fileName, generator)
    cv2.waitKey(0)
arGenerator()

image.png

可視化

検出されたcornersをscript1で可視化します。

import cv2
import numpy as np


def onPostCook(changeOp):
    image = changeOp.numpyArray(delayed=True)
    image = np.array(image)
    image = np.uint8(image * 255.0)
    image = np.flipud(image)
    image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGR)

    out = op('script1')
    out.clear()

    aruco = cv2.aruco
    dictionary = aruco.getPredefinedDictionary(aruco.DICT_4X4_50)
    corners, ids, rejectedImgPoints = aruco.detectMarkers(image, dictionary)
    aruco.drawDetectedMarkers(image, corners, ids, (255, 0, 0))

    if len(corners) > 0:
        out.numSamples = len(corners)
    else:
        out.numSamples = 1

    x0 = out.appendChan('x0')
    y0 = out.appendChan('y0')
    x1 = out.appendChan('x1')
    y1 = out.appendChan('y1')
    x2 = out.appendChan('x2')
    y2 = out.appendChan('y2')
    x3 = out.appendChan('x3')
    y3 = out.appendChan('y3')

    if len(corners) > 0:
        for index, corner in enumerate(corners):
            x0[index] = corner[0][0][0]
            y0[index] = corner[0][0][1]
            x1[index] = corner[0][1][0]
            y1[index] = corner[0][1][1]
            x2[index] = corner[0][2][0]
            y2[index] = corner[0][2][1]
            x3[index] = corner[0][3][0]
            y3[index] = corner[0][3][1]
    else:
        x0[0] = 0.
        y0[0] = 0.
        x1[0] = 0.
        y1[0] = 0.
        x2[0] = 0.
        y2[0] = 0.
        x3[0] = 0.
        y3[0] = 0.

    return

実行 

マーカーが1個の時の結果です。
image.png

マーカーが複数の時の結果です。
image.png

お疲れ様でした。

参考

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?