Skip to content

Commit

Permalink
fixed names of mm_lut that cannot be also mmlut as an item in another…
Browse files Browse the repository at this point in the history
… class

replaced list by np.fromstring
  • Loading branch information
alexlib committed Oct 22, 2023
1 parent 291e524 commit c44eda4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
32 changes: 19 additions & 13 deletions openptv_python/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def set_affine_distortion(self, affine: np.ndarray) -> None:


@dataclass
class mmlut:
class mm_lut:
origin: np.ndarray = np.r_[0.0, 0.0, 0.0]
nr: int = 0
nz: int = 0
Expand All @@ -126,8 +126,8 @@ class Calibration:
int_par: Interior = field(default_factory=Interior)
glass_par: Glass = field(default_factory=Glass)
added_par: ap_52 = field(default_factory=ap_52)
mmlut: mmlut = field(
default_factory=lambda: mmlut(
mmlut: mm_lut = field(
default_factory=lambda: mm_lut(
np.zeros(
3,
),
Expand All @@ -138,7 +138,9 @@ class Calibration:
)
)

def from_file(self, ori_file: str, add_file: str = None, add_fallback: str = None):
def from_file(
self, ori_file: str, add_file: str, add_fallback: Optional[str] = None
) -> None:
"""
Read exterior and interior orientation, and if available, parameters for distortion corrections.
Expand All @@ -157,15 +159,19 @@ def from_file(self, ori_file: str, add_file: str = None, add_fallback: str = Non

with open(ori_file, "r", encoding="utf-8") as fp:
# Exterior
self.set_pos([float(x) for x in fp.readline().split()])
self.set_angles([float(x) for x in fp.readline().split()])
# self.set_pos(np.array([float(x) for x in fp.readline().split()]))
# self.set_angles(np.array([float(x) for x in fp.readline().split()]))

self.set_pos(np.fromstring(fp.readline(), dtype=float, sep="\t"))
self.set_angles(np.fromstring(fp.readline(), dtype=float, sep="\t"))

# Exterior rotation matrix
# skip line
fp.readline()

# read 3 lines and set a rotation matrix
[[float(x) for x in fp.readline().split()] for _ in range(3)]
_ = [[float(x) for x in fp.readline().split()] for _ in range(3)]

# I skip reading rotation matrix as it's set up by set_angles.
# self.set_rotation_matrix(np.array(float_list).reshape(3, 3))

Expand All @@ -174,13 +180,15 @@ def from_file(self, ori_file: str, add_file: str = None, add_fallback: str = Non
fp.readline()
tmp = [float(x) for x in fp.readline().split()] # xh,yh
tmp += [float(x) for x in fp.readline().split()] # cc
self.int_par.set_primary_point(tmp)
self.int_par.set_primary_point(np.array(tmp))
# self.int_par.set_back_focal_distance(float(fp.readline()))

# Glass
# skip
fp.readline()
self.glass_par.set_glass_vec([float(x) for x in fp.readline().split()])
self.glass_par.set_glass_vec(
np.array([float(x) for x in fp.readline().split()])
)

# double-check that we have the correct rotation matrix
# self.ext_par.rotation_matrix()
Expand Down Expand Up @@ -409,9 +417,7 @@ def write_ori(
return success


def read_ori(
ori_file: str, add_file: str = None, add_fallback: str = None
) -> Calibration:
def read_ori(ori_file: str, add_file: str, add_fallback: str) -> Calibration:
"""
Read exterior and interior orientation, and if available, parameters for distortion corrections.
Expand Down Expand Up @@ -489,7 +495,7 @@ def compare_addpar(a1, a2):


def read_calibration(
ori_file: str, addpar_file: str = None, fallback_file: str = None
ori_file: str, addpar_file: str, fallback_file: Optional[str] = None
) -> Calibration:
"""Read the orientation file including the added parameters."""
ret = Calibration()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_calibration_binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_full_instantiate(self):
np.testing.assert_array_equal(affine, cal.get_affine())
np.testing.assert_array_equal(glass, cal.get_glass_vec())

def test_Calibration_instantiation(self):
def test_calibration_instantiation(self):
"""Filling a calibration object by reading ori files."""
output_ori_file_name = self.output_directory + "output_ori"
output_add_file_name = self.output_directory + "output_add"
Expand Down Expand Up @@ -117,7 +117,7 @@ def test_set_pos(self):
def test_set_angles(self):
"""Set angles correctly."""
dmatrix_before = self.cal.get_rotation_matrix() # dmatrix before setting angles
angles_np = [0.1111, 0.2222, 0.3333]
angles_np = np.array([0.1111, 0.2222, 0.3333])
self.cal.set_angles(angles_np)

dmatrix_after = self.cal.get_rotation_matrix() # dmatrix after setting angles
Expand Down
4 changes: 2 additions & 2 deletions tests/test_calibration_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Glass,
Interior,
ap_52,
mmlut,
mm_lut,
)


Expand Down Expand Up @@ -61,7 +61,7 @@ def test_calibration_initialization(self):
assert isinstance(self.cal.int_par, Interior)
assert isinstance(self.cal.glass_par, Glass)
assert isinstance(self.cal.added_par, ap_52)
assert isinstance(self.cal.mmlut, mmlut)
assert isinstance(self.cal.mmlut, mm_lut)

def test_exterior_initialization(self):
"""Test exterior parameters initialization."""
Expand Down
6 changes: 3 additions & 3 deletions tests/test_get_mmlut.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path

# from ctypes import c_double
from openptv_python.calibration import mmlut, read_calibration
from openptv_python.calibration import mm_lut, read_calibration
from openptv_python.multimed import get_mmf_from_mmlut, init_mmlut
from openptv_python.parameters import read_control_par, read_volume_par
from openptv_python.vec_utils import vec_set
Expand All @@ -14,11 +14,11 @@ def setUp(self):
self.add_file = Path("tests/testing_fodder/cal/cam2.tif.addpar")
self.vol_file = Path("tests/testing_fodder/parameters/criteria.par")
self.ptv_file = Path("tests/testing_fodder/parameters/ptv.par")
self.cal = read_calibration(self.ori_file, self.add_file, None)
self.cal = read_calibration(self.ori_file, self.add_file)
self.vpar = read_volume_par(self.vol_file)
self.cpar = read_control_par(self.ptv_file)
self.correct_mmlut = [
mmlut(origin=[0.0, 0.0, -250.00001105], nr=130, nz=177, rw=2)
mm_lut(origin=[0.0, 0.0, -250.00001105], nr=130, nz=177, rw=2)
for _ in range(4)
]

Expand Down
6 changes: 3 additions & 3 deletions tests/test_init_mmlut.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
from pathlib import Path

from openptv_python.calibration import mmlut, read_calibration
from openptv_python.calibration import mm_lut, read_calibration
from openptv_python.multimed import init_mmlut
from openptv_python.parameters import read_control_par, read_volume_par

Expand All @@ -15,7 +15,7 @@ def test_init_mmLUT(self):

self.assertTrue(Path(ori_file).exists, f"File {ori_file} does not exist")
self.assertTrue(Path(add_file).exists, f"File {add_file} does not exist")
cal = read_calibration(ori_file, add_file, None)
cal = read_calibration(ori_file, add_file)
self.assertIsNotNone(cal, "\n ORI or ADDPAR file reading failed \n")

self.assertTrue(Path(vol_file).exists, f"File {vol_file} does not exist")
Expand All @@ -27,7 +27,7 @@ def test_init_mmLUT(self):
self.assertIsNotNone(cpar, "\n control parameter file reading failed\n ")

# test_mmlut = [mmlut() for _ in range(cpar.num_cams)]
correct_mmlut = mmlut(
correct_mmlut = mm_lut(
origin=(0.0, 0.0, -250.00001105),
nr=130,
nz=177,
Expand Down

0 comments on commit c44eda4

Please sign in to comment.