-
Notifications
You must be signed in to change notification settings - Fork 0
/
aruco_aug
32 lines (24 loc) · 848 Bytes
/
aruco_aug
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#pip install opencv-contrib-python (include numpy)
#don't install opencv-python!
import cv2
import cv2.aruco as aruco
import numpy as np
def findArucoMarkers(img, markerSize=6, totalMarkers=250, draw=True):
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
key = getattr(aruco,f'DICT_{markerSize}X{markerSize}_{totalMarkers}')
arucoDict = aruco.Dictionary_get(key)
arucoParam = aruco.DetectorParameters_create()
bboxs, ids, rejected = aruco.detectMarkers(imgGray, arucoDict, parameters=arucoParam)
#print(ids)
if draw:
aruco.drawDetectedMarkers(img, bboxs, ids)
return [bboxs, ids]
def main():
cap = cv2.VideoCapture(0)
while True:
success, img = cap.read()
findArucoMarkers(img)
cv2.imshow("image", img)
cv2.waitKey(1)
if __name__ == "__main__":
main()