Skip to content

Commit 5da454c

Browse files
committed
fixing tests
1 parent 685a166 commit 5da454c

5 files changed

Lines changed: 68 additions & 24 deletions

File tree

src/openptv_python/correspondences.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,33 @@ def py_correspondences(
565565
"""
566566
num_cams = get_num_cams(cparam)
567567

568+
if should_use_native("correspondences") and HAS_NATIVE_CORRESPONDENCES and optv_correspondences is not None:
569+
native_cals = [to_native_calibration(cal) for cal in calib]
570+
native_vparam = to_native_volume_par(vparam)
571+
native_cparam = to_native_control_par(cparam)
572+
native_img_pts = [to_native_target_array(img_pts[cam]) for cam in range(num_cams)]
573+
native_flat_coords = [
574+
optv_correspondences.MatchedCoords(
575+
native_img_pts[cam], native_cparam, native_cals[cam], 0.0001
576+
)
577+
for cam in range(num_cams)
578+
]
579+
580+
if num_cams == 1:
581+
return optv_correspondences.single_cam_correspondence(
582+
native_img_pts,
583+
native_flat_coords,
584+
native_cals,
585+
)
586+
587+
return optv_correspondences.correspondences(
588+
native_img_pts,
589+
native_flat_coords,
590+
native_cals,
591+
native_vparam,
592+
native_cparam,
593+
)
594+
568595
frm = Frame(num_cams, MAX_TARGETS)
569596

570597
# Special case of a single camera, follow the single_cam_correspondence docstring

src/openptv_python/tracking_frame_buf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ def __eq__(self, __value) -> bool:
145145

146146
def sort_target_y(targets: List[Target]) -> List[Target]:
147147
"""Sort targets by y coordinate."""
148+
if hasattr(targets, "sort_y") and callable(getattr(targets, "sort_y", None)):
149+
targets.sort_y()
150+
return targets
148151
return sorted(targets, key=lambda t: _target_pos(t)[1])
149152

150153

src/pyptv/_backend.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ def _to_openptv_name(name: str) -> str:
6060
from optv.parameters import TargetParams
6161
from optv.parameters import TrackingParams
6262
from optv.parameters import VolumeParams
63+
from optv.correspondences import MatchedCoords
64+
from optv.correspondences import correspondences as py_correspondences
6365
from optv.epipolar import epipolar_curve
6466
from optv.image_processing import preprocess_image
6567
from optv.imgcoord import image_coordinates
@@ -77,6 +79,7 @@ def _to_openptv_name(name: str) -> str:
7779
convert_arr_metric_to_pixel,
7880
convert_arr_pixel_to_metric,
7981
)
82+
correspondences = py_correspondences
8083
else:
8184
from openptv_python.calibration import Calibration
8285
from openptv_python.parameters import ControlPar as ControlParams
@@ -99,11 +102,11 @@ def _to_openptv_name(name: str) -> str:
99102
from openptv_python.track import Tracker, default_naming
100103
from openptv_python.trafo import arr_pixel_to_metric as convert_arr_pixel_to_metric
101104
from openptv_python.trafo import arr_metric_to_pixel as convert_arr_metric_to_pixel
102-
from openptv_python.correspondences import (
103-
MatchedCoords,
104-
py_correspondences,
105-
correspondences,
106-
)
105+
from openptv_python.correspondences import (
106+
MatchedCoords,
107+
py_correspondences,
108+
correspondences,
109+
)
107110
from openptv_python.tracking_frame_buf import sort_target_y
108111
from openptv_python.imgcoord import img_coord
109112

@@ -236,6 +239,7 @@ def create_target_params(**kwargs) -> TargetParams:
236239
"Tracker",
237240
"MatchedCoords",
238241
"py_correspondences",
242+
"correspondences",
239243
# Functions
240244
"preprocess_image",
241245
"target_recognition",

src/pyptv/ptv.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,8 @@ def py_correspondences_proc_c(exp, frame=DEFAULT_FRAME_NUM):
591591
short_file_bases = exp.target_filenames
592592
print(f"short_file_bases: {short_file_bases}")
593593
_ensure_target_output_writable(short_file_bases)
594-
native_detections = bool(exp.detections) and type(exp.detections[0]).__module__.startswith("optv.")
595-
if not native_detections:
596-
for i_cam in range(exp.num_cams):
597-
write_targets(exp.detections[i_cam], short_file_bases[i_cam], frame)
594+
for i_cam in range(exp.num_cams):
595+
write_targets(exp.detections[i_cam], short_file_bases[i_cam], frame)
598596

599597
print(
600598
f"Frame {frame} had {[s.shape[1] for s in sorted_pos]!r} correspondences."
@@ -832,12 +830,17 @@ def py_sequence_loop(exp) -> None:
832830
flat = np.array(
833831
[corr.get_by_pnrs(corresp) for corr, corresp in zip(corrected, sorted_corresp)]
834832
)
835-
legacy_cals = [from_native_calibration(cal) for cal in exp.cals]
836-
legacy_cpar = _to_python_cpar(exp.cpar)
837-
legacy_vpar = _to_python_vpar(exp.vpar)
833+
if should_use_native("orientation"):
834+
legacy_cals = exp.cals
835+
legacy_cpar = exp.cpar
836+
legacy_vpar = exp.vpar
837+
else:
838+
legacy_cals = [from_native_calibration(cal) for cal in exp.cals]
839+
legacy_cpar = _to_python_cpar(exp.cpar)
840+
legacy_vpar = _to_python_vpar(exp.vpar)
838841
pos, _ = point_positions(
839842
flat.transpose(1, 0, 2),
840-
get_multimedia_par(legacy_cpar),
843+
legacy_cpar,
841844
legacy_cals,
842845
legacy_vpar,
843846
)
@@ -983,18 +986,25 @@ def _sum_grey_value(target):
983986
return target.sum_grey_value()
984987
return target.sumg
985988

986-
with open(output_path, "w", encoding="utf-8") as file:
987-
file.write(f"{num_targets}\n")
988-
for target in target_list:
989-
pnr = int(_value(getattr(target, "pnr")))
990-
x, y = _pos(target)
991-
n, nx, ny = _pixel_counts(target)
992-
sumg = int(_sum_grey_value(target))
993-
tnr = int(_value(getattr(target, "tnr")))
994-
file.write(
995-
f"{pnr:4d} {float(x):9.4f} {float(y):9.4f} "
996-
f"{int(n):5d} {int(nx):5d} {int(ny):5d} {sumg:5d} {tnr:5d}\n"
989+
target_arr = np.array(
990+
[
991+
(
992+
_value(getattr(target, "pnr")),
993+
*_pos(target),
994+
*_pixel_counts(target),
995+
_sum_grey_value(target),
996+
_value(getattr(target, "tnr")),
997997
)
998+
for target in target_list
999+
]
1000+
)
1001+
np.savetxt(
1002+
output_path,
1003+
target_arr,
1004+
fmt="%4d %9.4f %9.4f %5d %5d %5d %5d %5d",
1005+
header=f"{num_targets}",
1006+
comments="",
1007+
)
9981008
success = True
9991009
except OSError as exc:
10001010
_raise_output_write_error(output_path, exc)

tests/pyptv/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)