Skip to content

Commit

Permalink
working on read_targets that fails now
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlib committed Nov 17, 2023
1 parent 9e99044 commit 44c8916
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 220 deletions.
2 changes: 1 addition & 1 deletion openptv_python/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __post_init__(self):
if len(self.img_base_name) == 0:
self.img_base_name = [""] * self.num_cams

def set_img_base_name(self, icam: int, new_name: str | None = None):
def set_img_base_name(self, icam: int, new_name: str):
"""Set the image base name for each camera."""
if icam > self.num_cams:
raise ValueError("Length of names must be equal to num_cams.")
Expand Down
8 changes: 4 additions & 4 deletions openptv_python/segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class Peak:
def targ_rec(
img: np.ndarray,
targ_par: TargetPar,
xmin: float,
xmax: float,
ymin: float,
ymax: float,
xmin: int,
xmax: int,
ymin: int,
ymax: int,
cpar: ControlPar,
num_cam,
) -> TargetArray:
Expand Down
201 changes: 95 additions & 106 deletions openptv_python/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
COORD_UNUSED,
CORRES_NONE,
MAX_CANDS,
MAX_TARGETS,
NEXT_NONE,
POS_INF,
PREV_NONE,
Expand All @@ -22,9 +21,9 @@
)
from .imgcoord import img_coord
from .orientation import point_position
from .parameters import ControlPar, SequencePar, TrackPar, VolumePar
from .parameters import ControlPar, TrackPar
from .tracking_frame_buf import Frame, Target
from .tracking_run import TrackingRun, tr_new
from .tracking_run import TrackingRun
from .trafo import dist_to_flat, metric_to_pixel, pixel_to_metric
from .vec_utils import vec_copy, vec_diff_norm, vec_subt

Expand Down Expand Up @@ -60,7 +59,10 @@ def reset_foundpix_array(arr: List[Foundpix], arr_len: int, num_cams: int) -> No

# Set default values for each whichcam member of the foundpix object
for cam in range(num_cams):
arr[i].whichcam[cam] = 0
if len(arr[i].whichcam) < num_cams:
arr[i].whichcam.append(0)
else:
arr[i].whichcam[cam] = 0

return None

Expand Down Expand Up @@ -717,21 +719,8 @@ def trackcorr_c_loop(run_info, step):
] * 4 # volume center projection on cameras
rr = 0.0

# Shortcuts to inside current frame
curr_path_inf, ref_path_inf = None, None
curr_corres = None
curr_targets = None
_ix = 0 # For use in any of the complex index expressions below
orig_parts = 0 # avoid infinite loop with particle addition set

# Shortcuts into the TrackingRun struct
cal = None
fb = None
tpar = None
vpar = None
cpar = None

w, wn = None, None
count1, num_added = 0, 0

fb = run_info.fb
Expand Down Expand Up @@ -990,7 +979,7 @@ def trackcorr_c_loop(run_info, step):
fb.write_frame_from_start(step)

if step < run_info.seq_par.last - 2:
fb.read_frame_at_end(step + 3, 0)
fb.read_frame_at_end(False, step + 3)
# end of sequence loop


Expand Down Expand Up @@ -1232,91 +1221,91 @@ def trackback_c(run_info: TrackingRun):
}


class Tracker:
"""
Workflow: instantiate, call restart() to initialize the frame buffer, then.
call either ``step_forward()`` while it still return True, then call
``finalize()`` to finish the run. Alternatively, ``full_forward()`` will
do all this for you.
"""

def __init__(
self,
cpar: ControlPar,
vpar: VolumePar,
tpar: TrackPar,
spar: SequencePar,
cals: List[Calibration],
naming: dict,
flatten_tol: float = 0.0001,
):
"""
Initialize the tracker.
Arguments:
---------
ControlPar cpar, VolumePar vpar, TrackPar tpar,
SequencePar spar - the usual parameter objects, as read from
anywhere.
cals - a list of Calibratiopn objects.
dict naming - a dictionary with naming rules for the frame buffer
files. See the ``default_naming`` member (which is the default).
"""
# We need to keep a reference to the Python objects so that their
# allocations are not freed.
self._keepalive = (cpar, vpar, tpar, spar, cals)

self.run_info = tr_new(
spar,
tpar,
vpar,
cpar,
TR_BUFSPACE,
MAX_TARGETS,
naming["corres"],
naming["linkage"],
naming["prio"],
cals,
flatten_tol,
)
self.step = self.run_info.seq_par.first

def restart(self):
"""
Prepare a tracking run. Sets up initial buffers and performs the.
one-time calculations used throughout the loop.
"""
self.step = self.run_info.seq_par.first
track_forward_start(self.run_info)

def step_forward(self):
"""Perform one tracking step for the current frame of iteration."""
if self.step >= self.run_info.seq_par.last:
return False

trackcorr_c_loop(self.run_info, self.step)
self.step += 1
return True

def finalize(self):
"""Finish a tracking run."""
trackcorr_c_finish(self.run_info, self.step)

def full_forward(self):
"""Do a full tracking run from restart to finalize."""
track_forward_start(self.run_info)
for step in range(self.run_info.seq_par.first, self.run_info.seq_par.last):
trackcorr_c_loop(self.run_info, step)
trackcorr_c_finish(self.run_info, self.run_info.seq_par.last)

def full_backward(self):
"""Do a full backward run on existing tracking results. so make sure.
results exist or it will explode in your face.
"""
trackback_c(self.run_info)

def current_step(self):
return self.step
# class Tracker:
# """
# Workflow: instantiate, call restart() to initialize the frame buffer, then.

# call either ``step_forward()`` while it still return True, then call
# ``finalize()`` to finish the run. Alternatively, ``full_forward()`` will
# do all this for you.
# """

# def __init__(
# self,
# cpar: ControlPar,
# vpar: VolumePar,
# tpar: TrackPar,
# spar: SequencePar,
# cals: List[Calibration],
# naming: dict,
# flatten_tol: float = 0.0001,
# ):
# """
# Initialize the tracker.

# Arguments:
# ---------
# ControlPar cpar, VolumePar vpar, TrackPar tpar,
# SequencePar spar - the usual parameter objects, as read from
# anywhere.
# cals - a list of Calibratiopn objects.
# dict naming - a dictionary with naming rules for the frame buffer
# files. See the ``default_naming`` member (which is the default).
# """
# # We need to keep a reference to the Python objects so that their
# # allocations are not freed.
# self._keepalive = (cpar, vpar, tpar, spar, cals)

# self.run_info = tr_new(
# spar,
# tpar,
# vpar,
# cpar,
# TR_BUFSPACE,
# MAX_TARGETS,
# naming["corres"],
# naming["linkage"],
# naming["prio"],
# cals,
# flatten_tol,
# )
# self.step = self.run_info.seq_par.first

# def restart(self):
# """
# Prepare a tracking run. Sets up initial buffers and performs the.

# one-time calculations used throughout the loop.
# """
# self.step = self.run_info.seq_par.first
# track_forward_start(self.run_info)

# def step_forward(self):
# """Perform one tracking step for the current frame of iteration."""
# if self.step >= self.run_info.seq_par.last:
# return False

# trackcorr_c_loop(self.run_info, self.step)
# self.step += 1
# return True

# def finalize(self):
# """Finish a tracking run."""
# trackcorr_c_finish(self.run_info, self.step)

# def full_forward(self):
# """Do a full tracking run from restart to finalize."""
# track_forward_start(self.run_info)
# for step in range(self.run_info.seq_par.first, self.run_info.seq_par.last):
# trackcorr_c_loop(self.run_info, step)
# trackcorr_c_finish(self.run_info, self.run_info.seq_par.last)

# def full_backward(self):
# """Do a full backward run on existing tracking results. so make sure.

# results exist or it will explode in your face.
# """
# trackback_c(self.run_info)

# def current_step(self):
# return self.step
Loading

0 comments on commit 44c8916

Please sign in to comment.