Skip to content

Commit f9e23c5

Browse files
committed
preparing for production. fixing vs pyptv
1 parent ee9f365 commit f9e23c5

3 files changed

Lines changed: 428 additions & 17 deletions

File tree

openptv_python/orientation.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
from .vec_utils import unit_vector, vec_norm, vec_set
2222

2323

24+
def is_singular(matrix):
25+
rank = np.linalg.matrix_rank(matrix)
26+
return rank < matrix.shape[0]
27+
2428
@njit
2529
def skew_midpoint(
2630
vert1: np.ndarray, direct1: np.ndarray, vert2: np.ndarray, direct2: np.ndarray
@@ -578,13 +582,29 @@ def orient(
578582
# if np.any(np.isnan(X)):
579583
# pdb.set_trace()
580584

581-
XPX = np.linalg.inv(np.dot(X[:, :numbers].T, X[:, :numbers]))
585+
XTX = np.dot(X[:, :numbers].T, X[:, :numbers])
586+
if is_singular(XTX):
587+
XPX = np.linalg.pinv(XTX)
588+
else:
589+
XPX = np.linalg.inv(XTX)
590+
591+
592+
# XPX = np.linalg.inv()
593+
594+
# def invert_singular_matrix(m):
595+
# a, b = m.shape
596+
# if a != b:
597+
# raise ValueError("Only square matrices are invertible.")
598+
# identity_matrix = np.eye(a, a)
599+
# return np.linalg.lstsq(m, identity_matrix)[0]
582600

583601

584602
# import pdb; pdb.set_trace()
585-
for i in range(numbers):
586-
# print(f"{i=}, {np.sqrt(XPX[i][i]) = }")
587-
sigmabeta[i] = sigmabeta[NPAR] * np.sqrt(XPX[i][i])
603+
# for i in range(numbers):
604+
# # print(f"{i=}, {np.sqrt(XPX[i][i]) = }")
605+
# sigmabeta[i] = sigmabeta[NPAR] * np.sqrt(XPX[i][i])
606+
607+
sigmabeta[:numbers] = sigmabeta[NPAR]*np.sqrt(np.diag(XPX))
588608

589609
if stopflag:
590610
cal.update_rotation_matrix()
@@ -843,13 +863,16 @@ def full_calibration(
843863
"""
844864
err_est = np.empty((NPAR + 1), dtype=np.float64)
845865

846-
# convert numpy array to list of Target objects
847-
targs = [Target() for _ in img_pts]
866+
if isinstance(img_pts, np.ndarray):
867+
# convert numpy array to list of Target objects
868+
targs = [Target() for _ in img_pts]
848869

849-
for ptx, pt in enumerate(img_pts):
850-
targs[ptx].x = pt[0]
851-
targs[ptx].y = pt[1]
852-
targs[ptx].pnr = ptx
870+
for ptx, pt in enumerate(img_pts):
871+
targs[ptx].x = pt[0]
872+
targs[ptx].y = pt[1]
873+
targs[ptx].pnr = ptx
874+
else:
875+
targs = img_pts
853876

854877
residuals = orient(cal, cparam, len(ref_pts), ref_pts, targs, orient_par, err_est, dm=dm, drad=drad)
855878

openptv_python/tracking_frame_buf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,15 @@ def write_targets(
215215
success = False
216216

217217
# fix old-type names, that are like cam1.# or just cam1.
218-
if "%" not in file_base:
219-
file_base = file_base + "%05d"
220218
if '#' in file_base:
221219
file_base = file_base.replace('#', '%05d')
220+
if "%" not in file_base:
221+
file_base = file_base + "%05d"
222+
223+
if frame_num == 0:
224+
frame_num = 123456789
222225

223-
file_name = (
224-
file_base + "_targets"
225-
if frame_num == 0
226-
else file_base % frame_num + "_targets"
227-
)
226+
file_name = file_base % frame_num + "_targets"
228227

229228
try:
230229
# Convert targets to a 2D numpy array

0 commit comments

Comments
 (0)