Skip to content

Commit 98638be

Browse files
committed
updated formating
1 parent 05623fd commit 98638be

68 files changed

Lines changed: 1374 additions & 1168 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openptv_python/calibration.py

Lines changed: 77 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ def rotation_matrix(ext: np.ndarray) -> None:
2121
https://doi.org/10.1007/BF00190953
2222
2323
"""
24-
omega, phi, kappa = ext['omega'], ext['phi'], ext['kappa']
25-
24+
omega, phi, kappa = ext["omega"], ext["phi"], ext["kappa"]
2625

2726
co = np.cos(omega)
2827
so = np.sin(omega)
@@ -34,7 +33,7 @@ def rotation_matrix(ext: np.ndarray) -> None:
3433
sk = np.sin(kappa)
3534

3635
# dm = np.zeros((3, 3), dtype=np.float64)
37-
dm = ext['dm'] # shortcut to the dm field of the first element of the array
36+
dm = ext["dm"] # shortcut to the dm field of the first element of the array
3837

3938
dm[0, 0] = cp * ck
4039
dm[0, 1] = -cp * sk
@@ -50,25 +49,26 @@ def rotation_matrix(ext: np.ndarray) -> None:
5049

5150
return None
5251

53-
exterior_dtype = np.dtype([
54-
('x0', np.float64),
55-
('y0', np.float64),
56-
('z0', np.float64),
57-
('omega', np.float64),
58-
('phi', np.float64),
59-
('kappa', np.float64),
60-
('dm', np.float64, (3, 3))
61-
])
62-
Exterior = np.array((0, 0, 0, 0, 0, 0, np.eye(3)), dtype = exterior_dtype).view(np.recarray)
63-
rotation_matrix(Exterior) # rotation should be a unit matrix
64-
assert np.allclose(np.eye(3), Exterior['dm'])
65-
66-
interior_dtype = np.dtype([
67-
('xh', np.float64),
68-
('yh', np.float64),
69-
('cc', np.float64)
70-
])
71-
Interior = np.array( (0, 0, 0), dtype = interior_dtype).view(np.recarray)
52+
53+
exterior_dtype = np.dtype(
54+
[
55+
("x0", np.float64),
56+
("y0", np.float64),
57+
("z0", np.float64),
58+
("omega", np.float64),
59+
("phi", np.float64),
60+
("kappa", np.float64),
61+
("dm", np.float64, (3, 3)),
62+
]
63+
)
64+
Exterior = np.array((0, 0, 0, 0, 0, 0, np.eye(3)), dtype=exterior_dtype).view(
65+
np.recarray
66+
)
67+
rotation_matrix(Exterior) # rotation should be a unit matrix
68+
assert np.allclose(np.eye(3), Exterior["dm"])
69+
70+
interior_dtype = np.dtype([("xh", np.float64), ("yh", np.float64), ("cc", np.float64)])
71+
Interior = np.array((0, 0, 0), dtype=interior_dtype).view(np.recarray)
7272

7373

7474
# ap52_dtype = np.dtype([
@@ -80,52 +80,54 @@ def rotation_matrix(ext: np.ndarray) -> None:
8080
# ('scx', np.float64),
8181
# ('she', np.float64)
8282
# ])
83-
ap_52 = np.array((0, 0, 0, 0, 0, 1, 0), dtype = np.float64)
83+
ap_52 = np.array((0, 0, 0, 0, 0, 1, 0), dtype=np.float64)
8484
# ap_52 = np.array((0, 0, 0, 0, 0, 1, 0), dtype = ap52_dtype).view(np.recarray)
8585

86-
mmlut_dtype = np.dtype([
87-
('origin', np.float64, 3),
88-
('nr', np.int32),
89-
('nz', np.int32),
90-
('rw', np.int32),
91-
])
86+
mmlut_dtype = np.dtype(
87+
[
88+
("origin", np.float64, 3),
89+
("nr", np.int32),
90+
("nz", np.int32),
91+
("rw", np.int32),
92+
]
93+
)
9294

93-
mm_lut = np.array((np.zeros(3), 0, 0, 0), dtype = mmlut_dtype).view(np.recarray)
94-
mm_lut_data = np.empty((mm_lut['nr'], mm_lut['nz']), dtype=np.float64)
95+
mm_lut = np.array((np.zeros(3), 0, 0, 0), dtype=mmlut_dtype).view(np.recarray)
96+
mm_lut_data = np.empty((mm_lut["nr"], mm_lut["nz"]), dtype=np.float64)
9597

9698

9799
class Calibration:
98100
"""Calibration data structure."""
99101

100-
def __init__(self,
101-
ext_par=None,
102-
int_par=None,
103-
glass_par=None,
104-
added_par=None,
105-
mmlut=None,
106-
mmlut_data=None):
102+
def __init__(
103+
self,
104+
ext_par=None,
105+
int_par=None,
106+
glass_par=None,
107+
added_par=None,
108+
mmlut=None,
109+
mmlut_data=None,
110+
):
107111
if ext_par is None:
108112
ext_par = copy.deepcopy(Exterior)
109113
if int_par is None:
110114
int_par = copy.deepcopy(Interior)
111115
if glass_par is None:
112116
glass_par = np.array([0.0, 0.0, 1.0])
113117
if added_par is None:
114-
added_par = np.array((0, 0, 0, 0, 0, 1, 0), dtype = np.float64)
118+
added_par = np.array((0, 0, 0, 0, 0, 1, 0), dtype=np.float64)
115119
if mmlut is None:
116-
mmlut = copy.deepcopy(mm_lut) # (np.zeros(3), 0, 0, 0)
120+
mmlut = copy.deepcopy(mm_lut) # (np.zeros(3), 0, 0, 0)
117121
if mmlut_data is None:
118122
mmlut_data = np.zeros((mmlut.nr, mmlut.nz), dtype=np.float64)
119123

120-
121124
self.ext_par = ext_par
122125
self.int_par = int_par
123126
self.glass_par = glass_par
124127
self.added_par = added_par
125128
self.mmlut = mmlut
126129
self.mmlut_data = mmlut_data
127130

128-
129131
@classmethod
130132
def from_file(cls, ori_file: Path, add_file: Path | None):
131133
"""
@@ -147,7 +149,7 @@ def from_file(cls, ori_file: Path, add_file: Path | None):
147149
ret = cls()
148150

149151
with open(ori_file, "r", encoding="utf-8") as fp:
150-
tmp = fp.read()
152+
tmp = fp.read()
151153

152154
data = np.fromstring(tmp, dtype=float, sep=" ")
153155
# print(data)
@@ -156,17 +158,16 @@ def from_file(cls, ori_file: Path, add_file: Path | None):
156158
ret.set_angles(data[3:6])
157159
# no need. set_angles updates rotation matrix automatically
158160
# ret.set_rotation_matrix(data[6:15].reshape(3, 3))
159-
ret.set_primary_point(data[15:18]) # xh, yh, cc
160-
ret.glass_par = data[18:] # glass position vector from the water side
161-
161+
ret.set_primary_point(data[15:18]) # xh, yh, cc
162+
ret.glass_par = data[18:] # glass position vector from the water side
162163

163164
# double-check that we have the correct rotation matrix
164165
# self.ext_par.rotation_matrix()
165166

166167
# this is anyhow default
167168
# self.mmlut.data = None # no multimedia data yet
168169

169-
ret.added_par = np.array([0,0,0,0,0,1,0], dtype=np.float64)
170+
ret.added_par = np.array([0, 0, 0, 0, 0, 1, 0], dtype=np.float64)
170171

171172
# Additional parameters
172173
if add_file is not None:
@@ -198,15 +199,20 @@ def write(self, ori_file: str, addpar_file: str):
198199
if not success:
199200
raise IOError("Failed to write ori file")
200201

201-
202202
def increment_attribute(self, attr_name, increment_value):
203203
"""Update the value of an attribute by increment_value."""
204204
if hasattr(self.ext_par, attr_name):
205-
setattr(self.ext_par, attr_name, getattr(
206-
self.ext_par, attr_name) + increment_value)
205+
setattr(
206+
self.ext_par,
207+
attr_name,
208+
getattr(self.ext_par, attr_name) + increment_value,
209+
)
207210
if hasattr(self.int_par, attr_name):
208-
setattr(self.int_par, attr_name, getattr(
209-
self.int_par, attr_name) + increment_value)
211+
setattr(
212+
self.int_par,
213+
attr_name,
214+
getattr(self.int_par, attr_name) + increment_value,
215+
)
210216

211217
def update_rotation_matrix(self) -> None:
212218
"""Update the rotation matrix of the exterior orientation."""
@@ -216,27 +222,27 @@ def set_rotation_matrix(self, dm: np.ndarray) -> None:
216222
"""Set exterior rotation matrix."""
217223
if dm.shape != (3, 3):
218224
raise ValueError("Illegal argument for exterior rotation matrix")
219-
self.ext_par[0]['dm'] = dm
225+
self.ext_par[0]["dm"] = dm
220226

221227
def set_pos(self, pos: np.ndarray) -> None:
222228
"""
223229
Set exterior position.
224230
225231
Parameter: x_y_z_np - numpy array of 3 elements for x, y, z.
226232
"""
227-
pos = np.array(pos, dtype = np.float64)
233+
pos = np.array(pos, dtype=np.float64)
228234

229235
if pos.shape != (3,):
230236
raise ValueError(
231237
"Illegal array argument "
232238
+ str(pos)
233239
+ " for x, y, z. Expected array/list of 3 numbers"
234240
)
235-
self.ext_par['x0'], self.ext_par['y0'], self.ext_par['z0'] = pos
241+
self.ext_par["x0"], self.ext_par["y0"], self.ext_par["z0"] = pos
236242

237243
def get_pos(self) -> np.ndarray:
238244
"""Return array of 3 elements representing exterior's x, y, z."""
239-
return np.r_[self.ext_par['x0'], self.ext_par['y0'], self.ext_par['z0']]
245+
return np.r_[self.ext_par["x0"], self.ext_par["y0"], self.ext_par["z0"]]
240246

241247
def set_angles(self, o_p_k_np: np.ndarray) -> None:
242248
"""
@@ -251,16 +257,16 @@ def set_angles(self, o_p_k_np: np.ndarray) -> None:
251257
f"Illegal array argument {o_p_k_np} for "
252258
"omega, phi, kappa. Expected array or list of 3 float"
253259
)
254-
self.ext_par['omega'], self.ext_par['phi'], self.ext_par['kappa'] = o_p_k_np
260+
self.ext_par["omega"], self.ext_par["phi"], self.ext_par["kappa"] = o_p_k_np
255261
self.update_rotation_matrix()
256262

257263
def get_angles(self) -> np.ndarray:
258264
"""Return an array of 3 elements representing omega, phi, kappa."""
259-
return np.r_[self.ext_par['omega'], self.ext_par['phi'], self.ext_par['kappa']]
265+
return np.r_[self.ext_par["omega"], self.ext_par["phi"], self.ext_par["kappa"]]
260266

261267
def get_rotation_matrix(self) -> np.ndarray:
262268
"""Return a 3x3 numpy array that represents Exterior's rotation matrix."""
263-
return self.ext_par['dm'].copy()
269+
return self.ext_par["dm"].copy()
264270

265271
def set_primary_point(self, prim_point_pos: np.ndarray) -> None:
266272
"""
@@ -305,7 +311,6 @@ def set_radial_distortion(self, dist_coeffs: np.ndarray) -> None:
305311

306312
# self.added_par.k1, self.added_par.k2, self.added_par.k3 = dist_coeffs
307313

308-
309314
def get_radial_distortion(self):
310315
"""
311316
Return the radial distortion polynomial coefficients as a 3 element.
@@ -402,12 +407,13 @@ def write_ori(
402407

403408
with open(filename, "w", encoding="utf-8") as fp:
404409
fp.write(f"{ext_par['x0']:.8f} {ext_par['y0']:.8f} {ext_par['z0']:.8f}\n")
405-
fp.write(f"{ext_par['omega']:.8f} {ext_par['phi']:.8f} {ext_par['kappa']:.8f}\n\n")
406-
for row in ext_par['dm']:
410+
fp.write(
411+
f"{ext_par['omega']:.8f} {ext_par['phi']:.8f} {ext_par['kappa']:.8f}\n\n"
412+
)
413+
for row in ext_par["dm"]:
407414
fp.write(f"{row[0]:.7f} {row[1]:.7f} {row[2]:.7f}\n")
408415
fp.write(f"\n{int_par.xh:.4f} {int_par.yh:.4f}\n{int_par.cc:.4f}\n")
409-
fp.write(
410-
f"\n{glass[0]:.15f} {glass[1]:.15f} {glass[2]:.15f}\n")
416+
fp.write(f"\n{glass[0]:.15f} {glass[1]:.15f} {glass[2]:.15f}\n")
411417

412418
if add_file is None:
413419
return success
@@ -445,13 +451,13 @@ def read_ori(ori_file: Path, add_file: Path) -> Calibration:
445451
def compare_exterior(e1: np.recarray, e2: np.recarray) -> bool:
446452
"""Compare exterior orientation parameters."""
447453
return (
448-
np.allclose(e1['dm'], e2['dm'], atol=1e-6)
449-
and (e1['x0'] == e2['x0'])
450-
and (e1['y0'] == e2['y0'])
451-
and (e1['z0'] == e2['z0'])
452-
and (e1['omega'] == e2['omega'])
453-
and (e1['phi'] == e2['phi'])
454-
and (e1['kappa'] == e2['kappa'])
454+
np.allclose(e1["dm"], e2["dm"], atol=1e-6)
455+
and (e1["x0"] == e2["x0"])
456+
and (e1["y0"] == e2["y0"])
457+
and (e1["z0"] == e2["z0"])
458+
and (e1["omega"] == e2["omega"])
459+
and (e1["phi"] == e2["phi"])
460+
and (e1["kappa"] == e2["kappa"])
455461
)
456462

457463

openptv_python/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Constants used in the Python version of OpenPTV."""
2+
23
NMAX = 10000 # correspondences
34
MAXCAND = 40 # assuming a maximum capacity of MAXCAND candidates
45
PT_UNUSED = -999

0 commit comments

Comments
 (0)