-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharuco_salt.py
executable file
·52 lines (37 loc) · 1.24 KB
/
aruco_salt.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import pickle
import cv2
#from object_detector import *
import numpy as np
# Load Aruco detector
#parameters = cv2.aruco.DetectorParameters_create()
#aruco_dict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50)
parameters = cv2.aruco.DetectorParameters()
aruco_dict = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_250)
with open('caminfo.pickle', 'rb') as f:
caminfo = pickle.load(f)
mtx = caminfo['cam_mtx']
dist = caminfo['distortion']
# Load Cap
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
while True:
_, img = cap.read()
# Get Aruco marker
corners, ids, rejected = cv2.aruco.detectMarkers(img, aruco_dict, parameters=parameters)
if corners:
print(ids)
# Draw polygon around the marker
int_corners = np.intp(corners)
cv2.polylines(img, int_corners, True, (0, 255, 0), 1)
# Aruco Perimeter
aruco_perimeter = cv2.arcLength(corners[0], True)
# Pixel to cm ratio
pixel_cm_ratio = aruco_perimeter / 3
cv2.imshow("Image", img)
key = cv2.waitKey(1)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()