|
10 | 10 |
|
11 | 11 | import openptv_python |
12 | 12 | from openptv_python._native_compat import ( |
| 13 | + HAS_OPTV, |
13 | 14 | get_active_engine, |
14 | 15 | get_engine_preference, |
15 | 16 | get_engine_reason, |
@@ -50,13 +51,22 @@ def _to_openptv_name(name: str) -> str: |
50 | 51 | # Module imports with compatibility wrapping |
51 | 52 | # ============================================================================= |
52 | 53 |
|
53 | | -from openptv_python.calibration import Calibration |
54 | | -from openptv_python.parameters import ControlPar as ControlParams |
55 | 54 | from openptv_python.parameters import MultimediaPar |
56 | | -from openptv_python.parameters import SequencePar as SequenceParams |
57 | | -from openptv_python.parameters import TargetPar as TargetParams |
58 | | -from openptv_python.parameters import TrackPar as TrackingParams |
59 | | -from openptv_python.parameters import VolumePar as VolumeParams |
| 55 | + |
| 56 | +if HAS_OPTV: |
| 57 | + from optv.calibration import Calibration |
| 58 | + from optv.parameters import ControlParams |
| 59 | + from optv.parameters import SequenceParams |
| 60 | + from optv.parameters import TargetParams |
| 61 | + from optv.parameters import TrackingParams |
| 62 | + from optv.parameters import VolumeParams |
| 63 | +else: |
| 64 | + from openptv_python.calibration import Calibration |
| 65 | + from openptv_python.parameters import ControlPar as ControlParams |
| 66 | + from openptv_python.parameters import SequencePar as SequenceParams |
| 67 | + from openptv_python.parameters import TargetPar as TargetParams |
| 68 | + from openptv_python.parameters import TrackPar as TrackingParams |
| 69 | + from openptv_python.parameters import VolumePar as VolumeParams |
60 | 70 | from openptv_python.image_processing import preprocess_image |
61 | 71 | from openptv_python.segmentation import target_recognition |
62 | 72 | from openptv_python.correspondences import ( |
@@ -116,21 +126,31 @@ def get_backend_status() -> str: |
116 | 126 |
|
117 | 127 | def create_control_params(num_cams: int, **kwargs) -> ControlParams: |
118 | 128 | """Create ControlParams with backend-appropriate initialization.""" |
119 | | - cpar = ControlParams( |
120 | | - num_cams=num_cams, |
121 | | - img_base_name=["" for _ in range(num_cams)], |
122 | | - cal_img_base_name=["" for _ in range(num_cams)], |
123 | | - mm=MultimediaPar(), |
124 | | - ) |
| 129 | + cpar = ControlParams(num_cams) |
125 | 130 | for key, value in kwargs.items(): |
| 131 | + if key == "mm" and hasattr(cpar, "get_multimedia_params"): |
| 132 | + mm = cpar.get_multimedia_params() |
| 133 | + if mm is not None and isinstance(value, dict): |
| 134 | + for mm_key, mm_value in value.items(): |
| 135 | + setter = getattr(mm, f"set_{mm_key}", None) |
| 136 | + if callable(setter): |
| 137 | + setter(mm_value) |
| 138 | + elif hasattr(mm, mm_key): |
| 139 | + setattr(mm, mm_key, mm_value) |
| 140 | + continue |
126 | 141 | if hasattr(cpar, key): |
127 | 142 | setattr(cpar, key, value) |
128 | 143 | return cpar |
129 | 144 |
|
130 | 145 |
|
131 | 146 | def create_sequence_params(num_cams: int, **kwargs) -> SequenceParams: |
132 | 147 | """Create SequenceParams with backend-appropriate initialization.""" |
133 | | - spar = SequenceParams(img_base_name=["" for _ in range(num_cams)]) |
| 148 | + try: |
| 149 | + spar = SequenceParams(num_cams=num_cams) |
| 150 | + except TypeError: |
| 151 | + spar = SequenceParams() |
| 152 | + if hasattr(spar, "set_img_base_name"): |
| 153 | + spar.set_img_base_name(["" for _ in range(num_cams)]) |
134 | 154 |
|
135 | 155 | for key, value in kwargs.items(): |
136 | 156 | if hasattr(spar, key): |
@@ -160,10 +180,7 @@ def create_volume_params(**kwargs) -> VolumeParams: |
160 | 180 |
|
161 | 181 | def create_target_params(**kwargs) -> TargetParams: |
162 | 182 | """Create TargetParams with backend-appropriate initialization.""" |
163 | | - if BACKEND == "openptv_python": |
164 | | - tpar = TargetParams() |
165 | | - else: |
166 | | - tpar = TargetParams() |
| 183 | + tpar = TargetParams() |
167 | 184 |
|
168 | 185 | for key, value in kwargs.items(): |
169 | 186 | if hasattr(tpar, key): |
|
0 commit comments