-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexploreIntrinsics.py
More file actions
95 lines (75 loc) · 2.72 KB
/
exploreIntrinsics.py
File metadata and controls
95 lines (75 loc) · 2.72 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# https://github.com/PerForm-Lab-RIT/pupil-core-pipeline/blob/7d9ad4591151fac4f2bc50b6e18491b7c96ff6b1/src/core/pupil_detection.py#L446
import logging
import sys
import numpy as np
sys.path.append("../../pupil/pupil_src/shared_modules")
sys.path.append("../../pupil")
# from pyglui import ui
#
# import file_methods as fm
# from pye3d.detector_3d import CameraModel, Detector3D, DetectorMode
#
# import data_changed
import os
CUSTOM_TOPIC = "custom_topic"
logger = logging.getLogger(__name__)
def load_intrinsics(intrinsics_loc, resolution=None): # (640, 480)):
import pupil_src.shared_modules.camera_models as cm
import pathlib
from pupil_src.shared_modules.file_methods import load_object
import ast
intrinsics_loc = pathlib.Path(intrinsics_loc)
intrinsics_dict = load_object(intrinsics_loc, allow_legacy=False)
if resolution is None:
for key in intrinsics_dict.keys():
if key != 'version':
res = ast.literal_eval(key)
if type(res) == type((1, 2)):
resolution = res
break
return cm.Camera_Model.from_file(
intrinsics_loc.parent, intrinsics_loc.stem, resolution
)
def save_intrinsics(directory: str, cam):
"""
Saves the current intrinsics to corresponding camera's intrinsics file. For each
unique camera name we maintain a single file containing all intrinsics
associated with this camera name.
:param directory: save location
:return:
"""
cam_name = cam.name
intrinsics = {
"camera_matrix": cam.K.tolist(),
"dist_coefs": cam.D.tolist(),
"resolution": cam.resolution,
"cam_type": cam.cam_type,
}
# Try to load previously recorded camera intrinsics
save_path = os.path.join(
directory, "{}.intrinsics".format(cam_name.replace(" ", "_"))
)
intrinsics_dict = {}
intrinsics_dict["version"] = 1
intrinsics_dict[str(cam.resolution)] = intrinsics
from pupil_src.shared_modules.file_methods import save_object
save_object(intrinsics_dict, save_path)
logger.debug(
f"Saved camera intrinsics for {cam_name} {cam.resolution} to {save_path}"
)
rootdir = './'
for subdir, dirs, files in os.walk(rootdir):
for file in files:
if file == 'world.intrinsics':
cam = load_intrinsics(os.path.join(subdir, file))
cam.resolution=(1,1)
cam.K = np.array([[0.,0.,0.],[0.,0.,0.],[0.,0.,0.]])
#print(vars(cam))
#exit()
#cam.K[1,1] = 375.5
print(subdir)
save_intrinsics(subdir,cam)
print(cam.K)
logger.debug(
f"**************** Adjusted world camera intrinsics ***************"
)