2020from skimage .util import img_as_ubyte
2121from 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"""
4446example 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
12031201def 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
16831670def 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
17821767def 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
0 commit comments