Skip to content

Commit 228baac

Browse files
committed
fixed ori file reading
1 parent add5f35 commit 228baac

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

openptv_python/calibration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ def from_file(cls, ori_file: str, add_file: str | None):
145145
ret = cls()
146146

147147
with open(ori_file, "r", encoding="utf-8") as fp:
148-
data = fp.read()
148+
tmp = fp.read()
149149

150-
data = np.fromstring(data, dtype=float, sep=" ")
150+
data = np.fromstring(tmp, dtype=float, sep=" ")
151151
# print(data)
152152

153153
ret.set_pos(data[:3])

openptv_python/trafo.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import numpy as np
55
from numba import float64, int32, njit
6-
from numpy import cos, sin, sqrt
76

87
from .calibration import Calibration
98
from .parameters import ControlPar
@@ -153,7 +152,7 @@ def distort_brown_affine(x: float,
153152
if x == 0 and y == 0:
154153
return 0, 0
155154

156-
r = sqrt(x**2 + y**2)
155+
r = np.sqrt(x**2 + y**2)
157156

158157
x += (
159158
x * (ap.k1 * r**2 + ap.k2 * r**4 + ap.k3 * r**6)
@@ -166,15 +165,13 @@ def distort_brown_affine(x: float,
166165
+ 2 * ap.p1 * x * y
167166
)
168167

169-
x1 = ap.scx * x - sin(ap.she) * y
170-
y1 = cos(ap.she) * y
168+
x1 = ap.scx * x - np.sin(ap.she) * y
169+
y1 = np.cos(ap.she) * y
171170

172171
return x1, y1
173172

174173
@njit(fastmath=True, cache=True, nogil=True)
175-
def correct_brown_affine(
176-
x: float, y: float, ap: np.recarray, tol: float = 1e-5
177-
) -> Tuple[float, float]:
174+
def correct_brown_affine(x: float, y: float, ap: np.recarray, tol: float = 1e-5) -> Tuple[float, float]:
178175
"""Correct a distorted point using the Brown affine model."""
179176
r, rq, xq, yq = 0.0, 0.0, x, y
180177
itnum = 0
@@ -183,21 +180,29 @@ def correct_brown_affine(
183180
return xq, yq
184181

185182
rq = np.sqrt(x**2 + y**2)
183+
two_p1 = 2 * ap.p1
184+
two_p2 = 2 * ap.p2
185+
cos_she = np.cos(ap.she)
186+
sin_she = np.sin(ap.she)
186187

187188
while True:
188189
r = rq
190+
common_term = (ap.k1 * r**2 + ap.k2 * r**4 + ap.k3 * r**6)
191+
xq_common = xq * common_term
192+
yq_common = yq * common_term
193+
189194
xq = (
190-
(x + yq * np.sin(ap.she)) / ap.scx
191-
- xq * (ap.k1 * r**2 + ap.k2 * r**4 + ap.k3 * r**6)
195+
(x + yq * sin_she) / ap.scx
196+
- xq_common
192197
- ap.p1 * (r**2 + 2 * xq**2)
193-
- 2 * ap.p2 * xq * yq
198+
- two_p2 * xq * yq
194199
)
195200

196201
yq = (
197-
y / np.cos(ap.she)
198-
- yq * (ap.k1 * r**2 + ap.k2 * r**4 + ap.k3 * r**6)
202+
y / cos_she
203+
- yq_common
199204
- ap.p2 * (r**2 + 2 * yq**2)
200-
- 2 * ap.p1 * xq * yq
205+
- two_p1 * xq * yq
201206
)
202207

203208
rq = np.sqrt(xq**2 + yq**2)
@@ -207,27 +212,26 @@ def correct_brown_affine(
207212

208213
itnum += 1
209214

210-
if itnum >= 201 or abs(rq - r) / r <= tol:
215+
if itnum >= 201 or np.abs(rq - r) <= tol * r:
211216
break
212217

213218
r = rq
214219
x1 = (
215-
(x + yq * np.sin(ap.she)) / ap.scx
216-
- xq * (ap.k1 * r**2 + ap.k2 * r**4 + ap.k3 * r**6)
220+
(x + yq * sin_she) / ap.scx
221+
- xq * common_term
217222
- ap.p1 * (r**2 + 2 * xq**2)
218-
- 2 * ap.p2 * xq * yq
223+
- two_p2 * xq * yq
219224
)
220225

221226
y1 = (
222-
y / np.cos(ap.she)
223-
- yq * (ap.k1 * r**2 + ap.k2 * r**4 + ap.k3 * r**6)
227+
y / cos_she
228+
- yq * common_term
224229
- ap.p2 * (r**2 + 2 * yq**2)
225-
- 2 * ap.p1 * xq * yq
230+
- two_p1 * xq * yq
226231
)
227232

228233
return x1, y1
229234

230-
231235
def flat_to_dist(flat_x: float, flat_y: float, cal: Calibration) -> Tuple[float, float]:
232236
"""Convert flat-image coordinates to real-image coordinates.
233237

0 commit comments

Comments
 (0)