@@ -63,77 +63,80 @@ def rotation_matrix(ext: np.ndarray) -> None:
6363rotation_matrix (Exterior ) # rotation should be a unit matrix
6464assert np .allclose (np .eye (3 ), Exterior ['dm' ])
6565
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 )
72+
73+ # def set_primary_point(point: np.ndarray) -> None:
74+ # """Set the primary point of the camera."""
75+ # self.xh, self.yh, self.cc = point
76+
77+ # def set_back_focal_distance(self, cc: float) -> None:
78+ # """Set the back focal distance of the camera."""
79+ # self.cc = cc
80+
81+ ap52_dtype = np .dtype ([
82+ ('k1' , np .float64 ),
83+ ('k2' , np .float64 ),
84+ ('k3' , np .float64 ),
85+ ('p1' , np .float64 ),
86+ ('p2' , np .float64 ),
87+ ('scx' , np .float64 ),
88+ ('she' , np .float64 )
89+ ])
90+ ap_52 = np .array ((0 , 0 , 0 , 0 , 0 , 1 , 0 ), dtype = ap52_dtype ).view (np .recarray )
91+
92+
93+ # class ap_52:
94+ # """Additional parameters for distortion correction."""
95+
96+ # def __init__(self, k1=0.0, k2=0.0, k3=0.0, p1=0.0, p2=0.0, scx=1.0, she=0.0):
97+ # self.k1 = k1
98+ # self.k2 = k2
99+ # self.k3 = k3
100+ # self.p1 = p1
101+ # self.p2 = p2
102+ # self.scx = scx
103+ # self.she = she
104+
105+ # def set_radial_distortion(self, dist_array: np.ndarray) -> None:
106+ # """Set the radial distortion parameters k1, k2, k3."""
107+ # self.k1, self.k2, self.k3 = dist_array
108+
109+ # def set_decentering(self, decent: np.ndarray) -> None:
110+ # """Set the decentring parameters p1 and p2."""
111+ # self.p1, self.p2 = decent
112+
113+ # def set_affine_distortion(self, affine: np.ndarray) -> None:
114+ # """Set the affine distortion parameters scx and she."""
115+ # self.scx, self.she = affine
116+
117+ mmlut_dtype = np .dtype ([
118+ ('origin' , np .float64 , 3 ),
119+ ('nr' , np .int32 ),
120+ ('nz' , np .int32 ),
121+ ('rw' , np .int32 ),
122+ ('data' , np .float64 , (3 , 3 ))
123+ ])
66124
67- # rotation_matrix(exterior) # inplace update of the rotation matrix
68-
69-
70- # def increment_attribute(self, attr_name, increment_value):
71- # """Update the value of an attribute by increment_value."""
72- # if hasattr(self, attr_name):
73- # setattr(self, attr_name, getattr(
74- # self, attr_name) + increment_value)
75-
76- # def __repr__(self) -> str:
77- # """Return a string representation of the Exterior object."""
78- # output = f"Exterior: x0={self['x0']}, y0={self['y0']}, z0={self['z0']}\n"
79- # output += f"omega={self['omega']}, phi={self['phi']}, kappa={self['kappa']}\n"
80- # return output
81-
82-
83- class Interior :
84- """Interior orientation data structure."""
85-
86- def __init__ (self , xh = 0.0 , yh = 0.0 , cc = 0.0 ):
87- self .xh = xh
88- self .yh = yh
89- self .cc = cc
90-
91- def set_primary_point (self , point : np .ndarray ) -> None :
92- """Set the primary point of the camera."""
93- self .xh , self .yh , self .cc = point
94-
95- def set_back_focal_distance (self , cc : float ) -> None :
96- """Set the back focal distance of the camera."""
97- self .cc = cc
98-
99- class ap_52 :
100- """Additional parameters for distortion correction."""
101-
102- def __init__ (self , k1 = 0.0 , k2 = 0.0 , k3 = 0.0 , p1 = 0.0 , p2 = 0.0 , scx = 1.0 , she = 0.0 ):
103- self .k1 = k1
104- self .k2 = k2
105- self .k3 = k3
106- self .p1 = p1
107- self .p2 = p2
108- self .scx = scx
109- self .she = she
110-
111- def set_radial_distortion (self , dist_array : np .ndarray ) -> None :
112- """Set the radial distortion parameters k1, k2, k3."""
113- self .k1 , self .k2 , self .k3 = dist_array
114-
115- def set_decentering (self , decent : np .ndarray ) -> None :
116- """Set the decentring parameters p1 and p2."""
117- self .p1 , self .p2 = decent
118-
119- def set_affine_distortion (self , affine : np .ndarray ) -> None :
120- """Set the affine distortion parameters scx and she."""
121- self .scx , self .she = affine
122-
125+ mm_lut = np .array ((np .zeros (3 ), 0 , 0 , 0 , np .zeros ((3 , 3 ))), dtype = mmlut_dtype ).view (np .recarray )
123126
124- class mm_lut :
125- """Multimedia lookup table data structure."""
127+ # class mm_lut:
128+ # """Multimedia lookup table data structure."""
126129
127- def __init__ (self , origin = None , nr = 3 , nz = 3 , rw = 0 , data = None ):
128- if origin is None :
129- origin = np .zeros (3 , dtype = np .float32 )
130- # if data is None:
131- # data = np.zeros((nr, nz), dtype=np.float32) # Assuming data is a 2D array, adjust as needed
132- self .origin = origin
133- self .nr = nr
134- self .nz = nz
135- self .rw = rw
136- self .data = data
130+ # def __init__(self, origin=None, nr=3, nz=3, rw=0, data=None):
131+ # if origin is None:
132+ # origin = np.zeros(3, dtype=np.float32)
133+ # # if data is None:
134+ # # data = np.zeros((nr, nz), dtype=np.float32) # Assuming data is a 2D array, adjust as needed
135+ # self.origin = origin
136+ # self.nr = nr
137+ # self.nz = nz
138+ # self.rw = rw
139+ # self.data = data
137140
138141
139142class Calibration :
@@ -143,13 +146,13 @@ def __init__(self, ext_par=None, int_par=None, glass_par=None, added_par=None, m
143146 if ext_par is None :
144147 ext_par = Exterior .copy ()
145148 if int_par is None :
146- int_par = Interior ()
149+ int_par = Interior . copy ()
147150 if glass_par is None :
148151 glass_par = np .array ([0.0 , 0.0 , 1.0 ])
149152 if added_par is None :
150- added_par = ap_52 ()
153+ added_par = ap_52 . copy ()
151154 if mmlut is None :
152- mmlut = mm_lut (np .zeros (3 ), 0 , 0 , 0 , None )
155+ mmlut = mm_lut . copy () # (np.zeros(3), 0, 0, 0, None)
153156
154157 self .ext_par = ext_par
155158 self .int_par = int_par
@@ -418,10 +421,7 @@ def get_glass_vec(self) -> np.ndarray:
418421
419422 def set_added_par (self , listpar : np .ndarray | list ):
420423 """Set added par from an numpy array of parameters."""
421- if isinstance (listpar , list ):
422- listpar = np .array (listpar )
423-
424- self .added_par = ap_52 (* listpar .tolist ())
424+ self .added_par = np .array (listpar , dtype = ap52_dtype ).view (np .recarray )
425425
426426 def copy (self , new_copy ):
427427 """Copy the calibration data to a new object."""
@@ -434,10 +434,10 @@ def copy(self, new_copy):
434434
435435
436436def write_ori (
437- ext_par : np .ndarray ,
438- int_par : Interior ,
437+ ext_par : np .recarray ,
438+ int_par : np . recarray ,
439439 glass : np .ndarray ,
440- added_par : ap_52 ,
440+ added_par : np . recarray ,
441441 filename : str ,
442442 add_file : Optional [str ],
443443) -> bool :
@@ -499,7 +499,7 @@ def compare_exterior(e1: np.ndarray, e2: np.ndarray) -> bool:
499499 )
500500
501501
502- def compare_interior (i1 : Interior , i2 : Interior ) -> bool :
502+ def compare_interior (i1 : np . recarray , i2 : np . recarray ) -> bool :
503503 """Compare interior orientation parameters."""
504504 return i1 .xh == i2 .xh and i1 .yh == i2 .yh and i1 .cc == i2 .cc
505505
0 commit comments