-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
43 lines (37 loc) · 1.39 KB
/
util.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
import json
import cv2
import numpy as np
#some parameters for lighting etc.
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_5X5_50)
detectorParams = cv2.aruco.DetectorParameters_create()
#detectorParams.doCornerRefinement = True
#detectorParams.cornerRefinementMaxIterations = 500
# detectorParams.cornerRefinementWinSize = 1
#detectorParams.cornerRefinementMinAccuracy = 0.001
# detectorParams.minMarkerPerimeterRate = 0.05
# detectorParams.maxMarkerPerimeterRate = 0.2
#detectorParams.adaptiveThreshWinSizeMin = 10
# detectorParams.adaptiveThreshWinSizeStep = 3
#detectorParams.adaptiveThreshWinSizeMax = 10
#function to save data to a file
def saveJSON(filename, data):
print('Saving to file:', filename)
out = json.dumps(data)
with open(filename, 'w') as f:
f.write(out)
#function to load a file into a data variable
def loadJSON(filename):
print('Loading from file:', filename)
with open(filename, 'r') as f:
data = json.loads(f.read())
return data
#function to detect an arucocode
def detectAruco(gray):
markerCorners, markerIds, rejected = cv2.aruco.detectMarkers(gray, dictionary)
return markerCorners, markerIds
#function that finds the center and up direction of an arucocode.
def centerAndUp(corners):
corners = np.squeeze(corners)
center = (corners[0] + corners[1] + corners[2] + corners[3]) / 4.0
up = (corners[0] + corners[1]) / 2.0
return center, up