4
4

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 5 years have passed since last update.

OpenCVのarucoの四角

Last updated at Posted at 2019-02-01

opencvのarucoで角の対応関係をよく忘れるので備忘録


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

img = cv2.imread('sample.png')
corners, ids, _ = aruco.detectMarkers(frame, dic)

idsには検出したマーカーのidが入っている。
このリストの順に、cornersに四角の位置が格納されている。

例えば、0番のマーカーの四角を知りたければ

corners[list(ids.flatten()).index(0)][0] #マーカー0番の四角

で取得できる

四角は左上から時計回りに格納されている。
名称未設定-1.png

つまり、

# マーカー0番の左上
corners[list(ids.flatten()).index(0)][0][0]
# マーカー0番の右上
corners[list(ids.flatten()).index(0)][0][1]
# マーカー0番の右下
corners[list(ids.flatten()).index(0)][0][2]
# マーカー0番の左下
corners[list(ids.flatten()).index(0)][0][3]

そして、これで取得できる位置は[x, y]の順で格納されている。
名称未設定-1.png

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?