回答編集履歴
9
補足
answer
CHANGED
@@ -29,4 +29,61 @@
|
|
29
29
|
print("ID{} のマーカー=(x: {}, y: {}, z: {}, roll: {}, pitch: {}, yaw: {})".format(
|
30
30
|
ids[i], str(tvec[0]), str(tvec[1]), str(tvec[2]), str(euler_angle[0]), str(euler_angle[1]), str(euler_angle[2])))
|
31
31
|
```
|
32
|
-
とすれば、検知した各マーカーのID番号とそのIDに対応する座標・方向データが正しくprint出力されます。
|
32
|
+
とすれば、検知した各マーカーのID番号とそのIDに対応する座標・方向データが正しくprint出力されます。
|
33
|
+
|
34
|
+
## 補足
|
35
|
+
**[1度の処理ループの中で例えばID1とID2のマーカが同時に見えているときに、それぞれの座標、方向データをprintする方法]**
|
36
|
+
|
37
|
+
[参照:自作サンプルコードのリンク](https://gist.github.com/taizan-hokuto/6d3df5cf7c5fbf7d8c98933c3acae8f1)
|
38
|
+
|
39
|
+
まず、取得した画像フレーム中に認識されているすべてのマーカーを一度辞書(markers)に格納します。
|
40
|
+
(サンプルコードの48行目から56行目)
|
41
|
+
(辞書のキー:マーカーID、値:各マーカーの座標・方向データ)
|
42
|
+
```lang-python
|
43
|
+
if len(corners) > 0:
|
44
|
+
# マーカーごとに処理
|
45
|
+
for i, corner in enumerate(corners)
|
46
|
+
(略)
|
47
|
+
euler_angle = cv2.decomposeProjectionMatrix(proj_matrix)[6] # [deg]
|
48
|
+
# マーカーIDをキーにして、マーカーID毎の座標・方向を辞書に格納:
|
49
|
+
markers[ids[i][0]] = {
|
50
|
+
"x": str(tvec[0]),
|
51
|
+
"y": str(tvec[1]),
|
52
|
+
"z": str(tvec[2]),
|
53
|
+
"roll": str(euler_angle[0]),
|
54
|
+
"pitch": str(euler_angle[1]),
|
55
|
+
"yaw": str(euler_angle[2])
|
56
|
+
}
|
57
|
+
```
|
58
|
+
|
59
|
+
そして、forループが終わった後(=1画像中に認識されている複数のマーカー全部の座標・方向データを取得し終わった後)に、
|
60
|
+
座標/方向データを格納した辞書markersの内容を一括してprint出力します。
|
61
|
+
(これが「1度の処理ループの中で複数のマーカが同時に認識されているときに、それぞれの座標、方向データをprintする」ということに相当します)
|
62
|
+
|
63
|
+
```lang-python
|
64
|
+
# 1フレーム内にある複数マーカーの座標・方向を出力する。
|
65
|
+
if len(markers.keys()) > 0:
|
66
|
+
print('='*20)
|
67
|
+
for mid in markers.keys(): # マーカーIDを列挙
|
68
|
+
print("ID%s のマーカー=(x: %s, y: %s, z: %s, roll: %s, pitch: %s, yaw: %s)" % (
|
69
|
+
mid, markers[mid]["x"], markers[mid]["y"], markers[mid]["z"], markers[mid]["roll"], markers[mid]["pitch"], markers[mid]["yaw"]))
|
70
|
+
sys.stdout.flush()
|
71
|
+
time.sleep(0.01)
|
72
|
+
print('='*20)
|
73
|
+
```
|
74
|
+
|
75
|
+
```lang-
|
76
|
+
<出力結果例>
|
77
|
+
====================
|
78
|
+
ID33 のマーカー=(x: 0.37299620897877683, y: 0.27564137297074015, z: 1.110049767074254, roll: [-179.21082782], pitch: [12.49320262], yaw: [-30.8981787])
|
79
|
+
ID303 のマーカー=(x: 0.06045913651229322, y: 0.09409733040784415, z: 0.37885871558283024, roll: [165.96844965], pitch: [11.57957246], yaw: [-32.58198751])
|
80
|
+
====================
|
81
|
+
====================
|
82
|
+
ID33 のマーカー=(x: 0.3782612414418004, y: 0.2739673617455094, z: 1.117224765870064, roll: [141.8837889], pitch: [8.68655973], yaw: [-30.71523192])
|
83
|
+
ID303 のマーカー=(x: 0.059853849602700245, y: 0.09263841265615678, z: 0.37457827584934494, roll: [166.37149935], pitch: [13.71420176], yaw: [-33.21705198])
|
84
|
+
====================
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
出力結果例で、「============」で囲まれている範囲それぞれが、各々の時点で同時に認識されているマーカーのデータになります。
|
89
|
+
(上記の出力結果では、ID33とID303のマーカーが同時に認識されていることを示しています)
|
8
修正
answer
CHANGED
@@ -5,12 +5,12 @@
|
|
5
5
|
```
|
6
6
|
corners, ids, rejectedImgPoints = aruco.detectMarkers(img, dictionary)
|
7
7
|
```
|
8
|
-
の行について、corners配列内のデータ順序は、ids配列内に格納され
|
8
|
+
の行について、(この関数を呼び出したときに返ってくる)corners配列内のデータ順序は、同ids配列内に格納されているマーカーIDの順序と対応しているものと思われます。
|
9
9
|
|
10
|
-
具体的には、
|
10
|
+
具体的には、この関数を呼び出す毎に返ってくる
|
11
11
|
ids[0,1,2,...n] と
|
12
12
|
corners[0,1,2,...n]
|
13
|
-
について
|
13
|
+
について、常に
|
14
14
|
|
15
15
|
マーカーID:ids[0] の 頂点データは corners[0]
|
16
16
|
マーカーID:ids[1] の 頂点データは corners[1]
|
@@ -29,4 +29,4 @@
|
|
29
29
|
print("ID{} のマーカー=(x: {}, y: {}, z: {}, roll: {}, pitch: {}, yaw: {})".format(
|
30
30
|
ids[i], str(tvec[0]), str(tvec[1]), str(tvec[2]), str(euler_angle[0]), str(euler_angle[1]), str(euler_angle[2])))
|
31
31
|
```
|
32
|
-
とすれば、検知した各マーカーのID番号とそのIDに対応する座標・
|
32
|
+
とすれば、検知した各マーカーのID番号とそのIDに対応する座標・方向データが正しくprint出力されます。
|
7
修正
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[公式ドキュメント](https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa)で
|
1
|
+
detectMarkers関数について、[公式ドキュメント](https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa)で
|
2
2
|
> For each detected marker, it returns the 2D position of its corner in the image and its corresponding identifier.
|
3
3
|
|
4
4
|
と説明されていることから、
|
6
修正
answer
CHANGED
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
という風に格納されていると思われます。
|
22
22
|
|
23
|
-
よって、
|
23
|
+
よって、たとえば
|
24
24
|
```
|
25
25
|
for i, corner in enumerate(corners):
|
26
26
|
(略)
|
@@ -29,4 +29,4 @@
|
|
29
29
|
print("ID{} のマーカー=(x: {}, y: {}, z: {}, roll: {}, pitch: {}, yaw: {})".format(
|
30
30
|
ids[i], str(tvec[0]), str(tvec[1]), str(tvec[2]), str(euler_angle[0]), str(euler_angle[1]), str(euler_angle[2])))
|
31
31
|
```
|
32
|
-
とすれば
|
32
|
+
とすれば、検知した各マーカーのID番号とそのIDに対応する座標・位置データがprint出力されます。
|
5
修正
answer
CHANGED
@@ -1,21 +1,24 @@
|
|
1
|
-
[公式ドキュメント](https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa)
|
1
|
+
[公式ドキュメント](https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa)で
|
2
2
|
> For each detected marker, it returns the 2D position of its corner in the image and its corresponding identifier.
|
3
3
|
|
4
|
-
と
|
4
|
+
と説明されていることから、
|
5
5
|
```
|
6
6
|
corners, ids, rejectedImgPoints = aruco.detectMarkers(img, dictionary)
|
7
7
|
```
|
8
|
-
に
|
8
|
+
の行について、corners配列内のデータ順序は、ids配列内に格納されたマーカーIDの順序と対応しているものと思われます。
|
9
9
|
|
10
10
|
具体的には、
|
11
|
+
ids[0,1,2,...n] と
|
11
12
|
corners[0,1,2,...n]
|
12
13
|
について
|
14
|
+
|
13
|
-
マーカーID:ids[0] の 頂点データはcorners[0]
|
15
|
+
マーカーID:ids[0] の 頂点データは corners[0]
|
14
|
-
マーカーID:ids[1] の 頂点データはcorners[1]
|
16
|
+
マーカーID:ids[1] の 頂点データは corners[1]
|
15
17
|
・・・
|
18
|
+
・・・
|
16
19
|
マーカーID:ids[n] の 頂点データはcorners[n]
|
17
20
|
|
18
|
-
に格納されていると思われます。
|
21
|
+
という風に格納されていると思われます。
|
19
22
|
|
20
23
|
よって、
|
21
24
|
```
|
4
リンク修正
answer
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
[公式ドキュメント](
|
1
|
+
[公式ドキュメント](https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa)にある
|
2
|
-
にある
|
3
2
|
> For each detected marker, it returns the 2D position of its corner in the image and its corresponding identifier.
|
4
3
|
|
5
4
|
という説明から推察するに
|
3
参考文献を追記
answer
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
[公式ドキュメント]( https://docs.opencv.org/master/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa)
|
2
|
+
にある
|
3
|
+
> For each detected marker, it returns the 2D position of its corner in the image and its corresponding identifier.
|
4
|
+
|
5
|
+
という説明から推察するに
|
1
6
|
```
|
2
7
|
corners, ids, rejectedImgPoints = aruco.detectMarkers(img, dictionary)
|
3
8
|
```
|
4
|
-
|
9
|
+
に於いて、corners配列内のデータ順序は、ids配列内に格納されたマーカーIDの順序と対応しているものと思われます。
|
5
10
|
|
6
11
|
具体的には、
|
7
12
|
corners[0,1,2,...n]
|
2
修正
answer
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
```
|
2
2
|
corners, ids, rejectedImgPoints = aruco.detectMarkers(img, dictionary)
|
3
3
|
```
|
4
|
-
ここに、cornersの
|
4
|
+
ここに、corners配列内のデータ順序は、ids配列内に格納されたマーカーIDの順序と対応しているものと思われます。
|
5
5
|
|
6
6
|
具体的には、
|
7
7
|
corners[0,1,2,...n]
|
8
8
|
について
|
9
|
-
ids[0] の 頂点データはcorners[0]
|
9
|
+
マーカーID:ids[0] の 頂点データはcorners[0]
|
10
|
-
ids[1] の 頂点データはcorners[1]
|
10
|
+
マーカーID:ids[1] の 頂点データはcorners[1]
|
11
11
|
・・・
|
12
|
-
ids[n] の 頂点データはcorners[n]
|
12
|
+
マーカーID:ids[n] の 頂点データはcorners[n]
|
13
13
|
|
14
14
|
に格納されていると思われます。
|
15
15
|
|
1
修正
answer
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
```
|
4
4
|
ここに、cornersの中身とids配列内のidの順序は対応しているものと思われます。
|
5
5
|
|
6
|
-
具体的には、
|
6
|
+
具体的には、
|
7
7
|
corners[0,1,2,...n]
|
8
8
|
について
|
9
9
|
ids[0] の 頂点データはcorners[0]
|