Skip to content

Commit dcd875b

Browse files
committed
removed obsolete stuff
1 parent 2ecf530 commit dcd875b

File tree

3 files changed

+26
-104
lines changed

3 files changed

+26
-104
lines changed

openptv_python/correspondences.py

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from .calibration import Calibration
77
from .constants import (
8-
COORD_UNUSED,
98
CORRES_NONE,
109
MAX_TARGETS,
1110
MAXCAND,
@@ -16,95 +15,6 @@
1615
from .find_candidate import find_candidate
1716
from .parameters import ControlPar, VolumePar
1817
from .tracking_frame_buf import Frame, Target, n_tupel_dtype
19-
from .trafo import dist_to_flat, pixel_to_metric
20-
21-
22-
class MatchedCoords:
23-
"""Keep a block of 2D flat coordinates.add().
24-
25-
each with a "point number", the same
26-
as the number on one ``target`` from the block to which this block is kept
27-
matched. This block is x-sorted.
28-
29-
NB: the data is not meant to be directly manipulated at this point. The
30-
coord_2d arrays are most useful as intermediate objects created and
31-
manipulated only by other liboptv functions. Although one can imagine a
32-
use case for direct manipulation in Python, it is rare and supporting it
33-
is a low priority.
34-
"""
35-
36-
def __init__(self, targs, cpar, cal, tol=0.00001, reset_numbers=True):
37-
"""Allocate and initialize the memory.add().
38-
39-
including coordinate conversion and sorting.
40-
41-
Arguments:
42-
TargetArray targs - the TargetArray to be converted and matched.
43-
ControlParams cpar - parameters of image size etc. for conversion.
44-
Calibration cal - representation of the camera parameters to use in
45-
the flat/distorted transforms.
46-
double tol - optional tolerance for the lens distortion correction
47-
phase, see ``optv.transforms``.
48-
reset_numbers - if True (default) numbers the targets too, in their
49-
current order. This shouldn't be necessary since all TargetArray
50-
creators number the targets, but this gets around cases where they
51-
don't.
52-
"""
53-
self._num_pts = len(targs)
54-
self.buf = np.empty(self._num_pts,
55-
dtype=np.dtype([('x', np.float64), ('y', np.float64), ('pnr', np.int32)]))
56-
57-
for tnum, targ in enumerate(targs):
58-
targ = targs[tnum]
59-
if reset_numbers:
60-
targ.pnr = tnum
61-
62-
self.buf[tnum]['x'], self.buf[tnum]['y'] = pixel_to_metric(
63-
targ.x, targ.y, cpar)
64-
65-
self.buf[tnum]['x'], self.buf[tnum]['y'] = dist_to_flat(
66-
self.buf[tnum]['x'], self.buf[tnum]['y'], cal, tol
67-
)
68-
self.buf[tnum]['pnr'] = targ.pnr
69-
70-
self.buf.sort(order='x')
71-
72-
def as_arrays(self):
73-
"""Return the matched coordinates as NumPy arrays.
74-
75-
Returns
76-
-------
77-
pos - (n,2) array, the (x,y) flat-coordinates position of n targets.
78-
pnr - n-length array, the corresponding target number for each point.
79-
"""
80-
pos = np.empty((self._num_pts, 2))
81-
pnr = np.empty(self._num_pts, dtype=np.int_)
82-
83-
for pt in range(self._num_pts):
84-
pos[pt, 0] = self.buf[pt]['x']
85-
pos[pt, 1] = self.buf[pt]['y']
86-
pnr[pt] = self.buf[pt]['pnr']
87-
88-
return pos, pnr
89-
90-
def get_by_pnrs(self, pnrs):
91-
"""Return the flat positions of points whose pnr property is given.
92-
93-
as an (n,2) flat position array. Assumes all pnrs are to be found, otherwise
94-
there will be garbage at the end of the position array.
95-
"""
96-
pos = np.full((len(pnrs), 2), COORD_UNUSED, dtype=np.float64)
97-
for pt in range(self._num_pts):
98-
which = np.flatnonzero(self.buf[pt]['pnr'] == pnrs)
99-
if len(which) > 0:
100-
which = which[0]
101-
pos[which, 0] = self.buf[pt]['x']
102-
pos[which, 1] = self.buf[pt]['y']
103-
return pos
104-
105-
def __del__(self):
106-
del self.buf
107-
10818

10919
Correspond_dtype = np.dtype([
11020
('p1', np.int32), # PT_UNUSED

openptv_python/multimed.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def fast_multimed_r_nlay(
6767
y0: float,
6868
z0: float,
6969
pos: np.ndarray
70-
) -> float:
70+
) -> float:
7171
"""Faster mutlimedia model calculation."""
7272
n_iter = 40
7373
X, Y, Z = pos
@@ -85,7 +85,8 @@ def fast_multimed_r_nlay(
8585
beta2 = np.arcsin(np.sin(beta1) * n1 / n2[0])
8686
beta3 = np.arcsin(np.sin(beta1) * n1 / n3)
8787

88-
rbeta = (z0 - d[0]) * np.tan(beta1) - zout * np.tan(beta3) + np.sum(d * np.tan(beta2))
88+
rbeta = (z0 - d[0]) * np.tan(beta1) - zout * \
89+
np.tan(beta3) + np.sum(d * np.tan(beta2))
8990

9091
rdiff = r - rbeta
9192
rq += rdiff
@@ -106,7 +107,7 @@ def trans_cam_point(
106107
107108
pos_t, cross_p, cross_c = trans_cam_point(ex, mm, glass, pos, ex_t)
108109
"""
109-
origin = np.r_[ex.x0, ex.y0, ex.z0] # type: ignore
110+
origin = np.r_[ex.x0, ex.y0, ex.z0] # type: ignore
110111
pos = pos.astype(np.float64)
111112

112113
return fast_trans_cam_point(
@@ -119,7 +120,7 @@ def fast_trans_cam_point(
119120
d: float,
120121
glass_dir: np.ndarray,
121122
pos: np.ndarray
122-
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float]:
123+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float]:
123124
"""Derive translation of camera point."""
124125
dist_o_glass = float(np.linalg.norm(glass_dir)) # vector length
125126
if dist_o_glass == 0.0:
@@ -174,8 +175,15 @@ def back_trans_point(
174175
"""
175176
return fast_back_trans_point(glass, mm.d[0], cross_c, cross_p, pos_t)
176177

178+
177179
@njit(fastmath=True, cache=True, nogil=True)
178-
def fast_back_trans_point(glass_direction: np.ndarray, d: float, cross_c, cross_p, pos_t) -> np.ndarray:
180+
def fast_back_trans_point(
181+
glass_direction: np.ndarray,
182+
d: float,
183+
cross_c: np.ndarray,
184+
cross_p: np.ndarray,
185+
pos_t: np.ndarray
186+
) -> np.ndarray:
179187
"""Run numba faster version of back projection."""
180188
# Calculate the glass direction vector
181189

@@ -199,12 +207,13 @@ def fast_back_trans_point(glass_direction: np.ndarray, d: float, cross_c, cross_
199207

200208
# If the norm of the vector temp is greater than zero, adjust the position
201209
# of the point in the camera coordinate system
202-
if norm_temp > 0.0: # type: ignore
210+
if norm_temp > 0.0: # type: ignore
203211
renorm_temp = temp * (-pos_t[0] / norm_temp)
204212
pos = pos - renorm_temp
205213

206214
return pos
207215

216+
208217
@njit(fastmath=True, cache=True, nogil=True)
209218
def move_along_ray(glob_z: float, vertex: np.ndarray, direct: np.ndarray) -> np.ndarray:
210219
"""Move along the ray to the global z plane.
@@ -252,7 +261,7 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati
252261
z_max_t = z_max
253262

254263
# intersect with image vertices rays
255-
cal_t = Calibration(mmlut = cal.mmlut.copy())
264+
cal_t = Calibration(mmlut=cal.mmlut.copy())
256265

257266
for i in range(2):
258267
for j in range(2):
@@ -273,9 +282,9 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati
273282

274283
R = vec_norm(
275284
np.r_[xyz_t[0] - cal_t.ext_par.x0,
276-
xyz_t[1] - cal_t.ext_par.y0,
277-
0]
278-
)
285+
xyz_t[1] - cal_t.ext_par.y0,
286+
0]
287+
)
279288

280289
if R > Rmax:
281290
Rmax = R
@@ -291,7 +300,7 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati
291300
z_max_t = xyz_t[2]
292301

293302
R = vec_norm(np.r_[xyz_t[0] - cal_t.ext_par.x0,
294-
xyz_t[1] - cal_t.ext_par.y0, 0])
303+
xyz_t[1] - cal_t.ext_par.y0, 0])
295304

296305
if R > Rmax:
297306
Rmax = R
@@ -317,8 +326,9 @@ def init_mmlut(vpar: VolumePar, cpar: ControlPar, cal: Calibration) -> Calibrati
317326
for i in range(nr):
318327
for j in range(nz):
319328
xyz = np.r_[Ri[i] + cal_t.ext_par.x0,
320-
cal_t.ext_par.y0, Zi[j]]
321-
cal.mmlut_data.flat[i * nz + j] = multimed_r_nlay(cal_t, cpar.mm, xyz)
329+
cal_t.ext_par.y0, Zi[j]]
330+
cal.mmlut_data.flat[i * nz +
331+
j] = multimed_r_nlay(cal_t, cpar.mm, xyz)
322332

323333
# print(f"filled mmlut data with {data}")
324334
# cal.mmlut_data = data
@@ -337,6 +347,8 @@ def get_mmf_from_mmlut(cal: Calibration, pos: np.ndarray) -> float:
337347
return fast_get_mmf_from_mmlut(rw, origin, data, nz, nr, pos)
338348

339349
# @njit
350+
351+
340352
def fast_get_mmf_from_mmlut(
341353
rw: int,
342354
origin: np.ndarray,

tests/test_corresp.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@
648648
"name": "python",
649649
"nbconvert_exporter": "python",
650650
"pygments_lexer": "ipython3",
651-
"version": "3.10.9"
651+
"version": "3.12.2"
652652
},
653653
"orig_nbformat": 4
654654
},

0 commit comments

Comments
 (0)