Skip to content

Commit 37b8fb0

Browse files
committed
added .backend
1 parent 412e332 commit 37b8fb0

6 files changed

Lines changed: 311 additions & 41 deletions

File tree

src/openptv_python/parameters.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,26 +451,50 @@ def set_cn(self, cn: float) -> None:
451451
"""Set the refractive index."""
452452
self.cn = cn
453453

454+
def get_cn(self) -> float:
455+
"""Return the refractive index."""
456+
return self.cn
457+
454458
def set_cnx(self, cnx: float) -> None:
455459
"""Set the refractive index in x direction."""
456460
self.cnx = cnx
457461

462+
def get_cnx(self) -> float:
463+
"""Return the refractive index in x direction."""
464+
return self.cnx
465+
458466
def set_cny(self, cny: float) -> None:
459467
"""Set the refractive index in y direction."""
460468
self.cny = cny
461469

470+
def get_cny(self) -> float:
471+
"""Return the refractive index in y direction."""
472+
return self.cny
473+
462474
def set_csumg(self, csumg: float) -> None:
463475
"""Set the maximum sum of the gradient."""
464476
self.csumg = csumg
465477

478+
def get_csumg(self) -> float:
479+
"""Return the maximum sum of the gradient."""
480+
return self.csumg
481+
466482
def set_eps0(self, eps0: float) -> None:
467483
"""Set the maximum sum of the gradient."""
468484
self.eps0 = eps0
469485

486+
def get_eps0(self) -> float:
487+
"""Return the maximum epipolar distance."""
488+
return self.eps0
489+
470490
def set_corrmin(self, corrmin: float):
471491
"""Set the minimum correlation value of all criteria."""
472492
self.corrmin = corrmin
473493

494+
def get_corrmin(self) -> float:
495+
"""Return the minimum correlation value of all criteria."""
496+
return self.corrmin
497+
474498
def get_X_lay(self) -> list[float]:
475499
"""Legacy getter for x-layer bounds."""
476500
return self.x_lay

src/pyptv/_backend.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,19 @@ def _to_openptv_name(name: str) -> str:
5151
from openptv_python.parameters import VolumePar as VolumeParams
5252
from openptv_python.image_processing import preprocess_image
5353
from openptv_python.segmentation import target_recognition
54-
from openptv_python.correspondences import correspondences, MatchedCoords
54+
from openptv_python.correspondences import (
55+
MatchedCoords,
56+
py_correspondences,
57+
correspondences,
58+
)
5559
from openptv_python.orientation import (
5660
point_positions,
5761
multi_cam_point_positions,
5862
external_calibration,
5963
full_calibration,
6064
match_detection_to_ref,
6165
)
62-
from openptv_python.tracking_frame_buf import TargetArray, Target, Frame
66+
from openptv_python.tracking_frame_buf import TargetArray, Target, Frame, sort_target_y
6367
from openptv_python.track import Tracker, default_naming
6468
from openptv_python.trafo import arr_pixel_to_metric as convert_arr_pixel_to_metric
6569
from openptv_python.trafo import arr_metric_to_pixel as convert_arr_metric_to_pixel
@@ -167,13 +171,15 @@ def create_target_params(**kwargs) -> TargetParams:
167171
"Frame",
168172
"Tracker",
169173
"MatchedCoords",
174+
"py_correspondences",
170175
# Functions
171176
"preprocess_image",
172177
"target_recognition",
173178
"correspondences",
174179
"point_positions",
175180
"multi_cam_point_positions",
176181
"default_naming",
182+
"sort_target_y",
177183
"convert_arr_pixel_to_metric",
178184
"convert_arr_metric_to_pixel",
179185
"image_coordinates",

src/pyptv/ptv.py

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,27 @@
2020
from skimage.util import img_as_ubyte
2121
from skimage.color import rgb2gray
2222

23-
from openptv_python.calibration import Calibration
24-
from openptv_python.correspondences import MatchedCoords, py_correspondences
25-
from openptv_python.imgcoord import image_coordinates
26-
from openptv_python.image_processing import preprocess_image
27-
from openptv_python.orientation import (
23+
from ._backend import (
24+
Calibration,
25+
ControlParams,
26+
Frame,
27+
MatchedCoords,
28+
SequenceParams,
29+
TargetArray,
30+
TargetParams,
31+
Tracker,
32+
TrackingParams,
33+
VolumeParams,
34+
convert_arr_pixel_to_metric,
35+
default_naming,
36+
image_coordinates,
2837
multi_cam_point_positions,
2938
point_positions,
39+
preprocess_image,
40+
py_correspondences,
41+
sort_target_y,
42+
target_recognition,
3043
)
31-
from openptv_python.parameters import (
32-
ControlPar as ControlParams,
33-
SequencePar as SequenceParams,
34-
TargetPar as TargetParams,
35-
TrackPar as TrackingParams,
36-
VolumePar as VolumeParams,
37-
)
38-
from openptv_python.trafo import arr_pixel_to_metric as convert_arr_pixel_to_metric
39-
from openptv_python.segmentation import target_recognition
40-
from openptv_python.track import Tracker, default_naming
41-
from openptv_python.tracking_frame_buf import Frame, TargetArray, sort_target_y
4244

4345
"""
4446
example from Tracker documentation:
@@ -1016,8 +1018,6 @@ def full_scipy_calibration(
10161018
cal: Calibration, XYZ: np.ndarray, targs: TargetArray, cpar: ControlParams, flags=[]
10171019
):
10181020
"""Full calibration using scipy.optimize"""
1019-
from openptv_python.trafo import arr_metric_to_pixel as convert_arr_metric_to_pixel
1020-
10211021
def _residuals_k(x, cal, XYZ, xy, cpar):
10221022
cal.set_radial_distortion(x)
10231023
targets = convert_arr_metric_to_pixel(
@@ -1146,8 +1146,6 @@ def dumbbell_target_func(targets, cpar, calibs, db_length, db_weight):
11461146
float
11471147
The weighted ray convergence + length error measure.
11481148
"""
1149-
from openptv_python.orientation import multi_cam_point_positions
1150-
11511149
num_cams = cpar.get_num_cams()
11521150
num_targs = targets.shape[1]
11531151
multimed_pars = cpar.get_multimedia_params()
@@ -1202,8 +1200,6 @@ def dumbbell_target_func(targets, cpar, calibs, db_length, db_weight):
12021200

12031201
def dumbbell_target_residuals(targets, cpar, calibs, db_length, db_weight):
12041202
"""Return residuals per target pair for least-squares optimization."""
1205-
from openptv_python.orientation import multi_cam_point_positions
1206-
12071203
num_targs = targets.shape[1]
12081204
if num_targs % 2 != 0:
12091205
raise ValueError("Number of targets must be even for dumbbell calibration")
@@ -1242,8 +1238,6 @@ def dumbbell_ba_residuals(
12421238
calib_vec packs active camera extrinsics and per-frame 3D endpoints.
12431239
targets is shaped (num_cams, num_frames, 2, 2) in metric coordinates.
12441240
"""
1245-
from openptv_python.imgcoord import image_coordinates
1246-
12471241
if db_length <= 0:
12481242
raise ValueError("Dumbbell length must be positive")
12491243
if db_weight < 0:
@@ -1473,8 +1467,6 @@ def calib_dumbbell(cal_gui)-> None:
14731467
metric_by_cam = np.array(metric_by_cam)
14741468

14751469
if db_eps > 0:
1476-
from openptv_python.orientation import multi_cam_point_positions
1477-
14781470
keep_mask = np.ones(num_frames, dtype=bool)
14791471
removed = 0
14801472
for frame_idx in range(num_frames):
@@ -1497,9 +1489,6 @@ def calib_dumbbell(cal_gui)-> None:
14971489
raise ValueError("All frames filtered by dumbbell length eps")
14981490

14991491
def _print_camera_residuals(label: str, metric_targets: np.ndarray) -> None:
1500-
from openptv_python.orientation import multi_cam_point_positions
1501-
from openptv_python.imgcoord import image_coordinates
1502-
15031492
num_cams_local, num_frames_local, num_targs_local, _ = metric_targets.shape
15041493
sums = np.zeros(num_cams_local, dtype=float)
15051494
counts = np.zeros(num_cams_local, dtype=int)
@@ -1562,8 +1551,6 @@ def _print_camera_residuals(label: str, metric_targets: np.ndarray) -> None:
15621551
calib_vec = calib_vec.flatten()
15631552

15641553
def _init_dumbbell_points(metric_targets: np.ndarray) -> np.ndarray:
1565-
from openptv_python.orientation import multi_cam_point_positions
1566-
15671554
num_cams_local, num_frames_local, _, _ = metric_targets.shape
15681555
points = np.zeros((num_frames_local, 2, 3), dtype=float)
15691556

@@ -1682,8 +1669,6 @@ def _init_dumbbell_points(metric_targets: np.ndarray) -> np.ndarray:
16821669

16831670
def calib_particles(exp):
16841671
"""Calibration with particles."""
1685-
1686-
from openptv_python.tracking_frame_buf import Frame
16871672

16881673
# Handle both Experiment objects and MainGUI objects
16891674
if hasattr(exp, 'pm'):
@@ -1781,14 +1766,19 @@ def calib_particles(exp):
17811766

17821767
def clone_calibration(calibration_obj):
17831768
"""Return a copy of a Calibration object using all get/set methods."""
1784-
from openptv_python.calibration import Calibration
17851769
import numpy as np
1786-
new_cal = Calibration()
1770+
new_cal = calibration_obj.__class__()
17871771
new_cal.set_pos(np.array(calibration_obj.get_pos()))
17881772
new_cal.set_angles(np.array(calibration_obj.get_angles()))
17891773
new_cal.set_primary_point(np.array(calibration_obj.get_primary_point()))
17901774
new_cal.set_radial_distortion(np.array(calibration_obj.get_radial_distortion()))
17911775
new_cal.set_decentering(np.array(calibration_obj.get_decentering()))
1792-
new_cal.set_affine_trans(np.array(calibration_obj.get_affine()))
1776+
affine = np.array(calibration_obj.get_affine())
1777+
if hasattr(new_cal, "set_affine_trans"):
1778+
new_cal.set_affine_trans(affine)
1779+
elif hasattr(new_cal, "set_affine_distortion"):
1780+
new_cal.set_affine_distortion(affine)
1781+
else:
1782+
raise AttributeError("Calibration object does not support affine setters")
17931783
new_cal.set_glass_vec(np.array(calibration_obj.get_glass_vec()))
17941784
return new_cal

src/pyptv/pyptv_gui.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@
2424
from .parameter_gui import Main_Params, Calib_Params, Tracking_Params
2525
from .__version__ import __version__
2626
from . import ptv
27-
from openptv_python.trafo import arr_metric_to_pixel as convert_arr_metric_to_pixel
28-
from openptv_python.epi import epipolar_curve
29-
from openptv_python.imgcoord import image_coordinates
27+
from ._backend import (
28+
Calibration,
29+
TargetArray,
30+
convert_arr_metric_to_pixel,
31+
epipolar_curve,
32+
external_calibration,
33+
full_calibration,
34+
image_coordinates,
35+
match_detection_to_ref,
36+
target_recognition,
37+
)
3038
from .calibration_gui import CalibrationGUI
3139

3240
"""PyPTV_GUI is the GUI for the OpenPTV (www.openptv.net) written in

0 commit comments

Comments
 (0)