Skip to content

Commit 4d02712

Browse files
authored
Merge pull request #71 from uaarg/fawwaz/precision-hover
Created Aruco marker detection
2 parents 81f9092 + 77f8cd2 commit 4d02712

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/modules/imaging/detector.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from PIL import Image
55
import numpy as np
66
import cv2
7+
from cv2 import aruco
78

89

910
@dataclass
@@ -112,3 +113,33 @@ def predict(self, image: Image.Image) -> Optional[BoundingBox]:
112113
x, y, w, h = cv2.boundingRect(cnt)
113114

114115
return BoundingBox(Vec2(x, y), Vec2(w, h))
116+
117+
118+
class ArucoDetector():
119+
120+
def predict(self, image: Image.Image) -> Optional[BoundingBox]:
121+
img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
122+
123+
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50)
124+
125+
params = cv2.aruco.DetectorParemeters()
126+
127+
corners, ids, rejected = cv2.aruco.detectMarkers(img, aruco_dict, parameters=params)
128+
129+
if ids:
130+
for c in zip(corners, ids):
131+
132+
pts = c[0]
133+
134+
x_min = pts[:, 0].min()
135+
x_max = pts[:, 0].max()
136+
y_min = pts[:, 1].min()
137+
y_max = pts[:, 1].max()
138+
139+
x = (x_min + x_max) / 2
140+
y = (y_min + y_max) / 2
141+
w = (x_max - x_min)
142+
h = (y_max - y_min)
143+
144+
return BoundingBox(Vec2(x, y), Vec2(w, h))
145+

0 commit comments

Comments
 (0)