Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blobs with existing targets had a bug due to the complex name structure #80

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ Plugins is a system of extensions to PyPTV without the need to change the GUI

Note, the specific branch `plugin_remback` requires installation of the `pip install rembg[cpu]` or `pip install rembg[gpu]`


### Developers:


1. how to bump the version: ```python bump_version.py --patch```
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyptv"
version = "0.3.1"
version = "0.3.2"
description = "Python GUI for the OpenPTV library `liboptv`"
authors = [
{ name = "Alex Liberzon", email = "alex.liberzon@gmail.com" }
Expand Down
2 changes: 1 addition & 1 deletion pyptv/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.1"
__version__ = "0.3.2"
7 changes: 3 additions & 4 deletions pyptv/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ def warning(msg):
print(f"Warning message: {msg}")


# Reads a parameters directory and returns a dictionary with all parameter
# objects
def readParamsDir(par_path):
# get n_img from ptv.par
""" Reads a parameters directory and returns a dictionary with all parameter objects"""

ptvParams = PtvParams(path=par_path)
ptvParams.read()
n_img = ptvParams.n_img

n_pts = Int(4)

ret = {
Expand Down Expand Up @@ -457,7 +457,6 @@ def read(self):
with open(self.filepath(), "r") as f:
self.base_name = []
for i in range(self.n_img):
# for i in range(max_cam):
self.base_name.append(g(f))

self.first = int(g(f))
Expand Down
37 changes: 23 additions & 14 deletions pyptv/ptv.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from skimage.color import rgb2gray
from pyptv import parameters as par
from pyptv import ptv as ptv
import re


def negative(img):
Expand Down Expand Up @@ -141,12 +142,6 @@ def py_correspondences_proc_c(exp):
# Save targets only after they've been modified:
for i_cam in range(exp.n_cams):
base_name = exp.spar.get_img_base_name(i_cam).decode()
# filename = base_name.split('%')[0] + base_name.split('d')[-1]
# filename = base_name % frame + '_targets'
# write_targets(exp.detections[i_cam], filename, frame)
# exp.detections[i_cam].write(filename.encode(), frame)
# base_name = 'cam_%d.' % (i_cam)
# base_name = replace_format_specifiers(base_name) # %d to %04d
write_targets(exp.detections[i_cam], base_name, frame)


Expand Down Expand Up @@ -306,7 +301,7 @@ def py_sequence_loop(exp):
for i_cam in range(n_cams):
base_image_name = spar.get_img_base_name(i_cam).decode()
if Existing_Target:
targs = read_targets(base_image_name % frame)
targs = read_targets(base_image_name, frame)
else:
# imname = spar.get_img_base_name(i_cam) + str(frame).encode()

Expand Down Expand Up @@ -407,12 +402,18 @@ def py_trackcorr_init(exp):
print("\n renaming for liboptv: \n")
for i_cam in range(exp.n_cams):
orig_filename = exp.spar.get_img_base_name(i_cam).decode()
print(f' from {orig_filename}')
orig_filename = os.path.splitext(orig_filename)[0] + '.'
short_name = re.sub(r'%\d*d', '', orig_filename)
print(f' to {short_name}')

# new_filename = replace_format_specifiers(orig_filename)
# print(orig_filename, orig_filename)

# base_name = exp.spar.get_img_base_name(i_cam).decode()
# filename = base_name.split('%')[0] + base_name.split('d')[-1]
exp.spar.set_img_base_name(i_cam, orig_filename)
# exp.spar.set_img_base_name(i_cam, orig_filename)
exp.spar.set_img_base_name(i_cam, short_name)

tracker = Tracker(exp.cpar, exp.vpar, exp.track_par, exp.spar, exp.cals,
default_naming)
Expand Down Expand Up @@ -658,8 +659,12 @@ def read_targets(file_base: str, frame: int) -> TargetArray:
frame = 123456789

# file_base = replace_format_specifiers(file_base) # remove %d
filename = Path(f'{file_base}{frame:04d}_targets')
# print(f" filename: {filename}")
if re.search(r"%\d*d", file_base):
filename = Path(f'{file_base % frame}_targets')
else:
filename = Path(f'{file_base}{frame:04d}_targets')

print(f" filename: {filename}")

try:
with open(filename, "r", encoding="utf-8") as file:
Expand Down Expand Up @@ -703,8 +708,12 @@ def write_targets(
frame = 123456789

# file_base = replace_format_specifiers(file_base) # remove %d
file_name = f'{file_base}{frame:04d}_targets'
print("Writing targets to file: ", file_name)
if re.search(r"%\d*d", file_base):
filename = Path(f'{file_base % frame}_targets')
else:
filename = Path(f'{file_base}{frame:04d}_targets')

print("Writing targets to file: ", filename)

num_targets = len(targets)

Expand All @@ -715,14 +724,14 @@ def write_targets(
)
# Save the target array to file using savetxt
np.savetxt(
file_name,
filename,
target_arr,
fmt="%4d %9.4f %9.4f %5d %5d %5d %5d %5d",
header=f"{num_targets}",
comments="",
)
success = True
except IOError:
print(f"Can't open targets file: {file_name}")
print(f"Can't open targets file: {filename}")

return success
40 changes: 26 additions & 14 deletions pyptv/pyptv_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1408,10 +1408,6 @@ def load_set_seq_image(self, seq: int, update_all=True, display_only=False):
for i in range(n_cams)
]

# i = seq
# seq_ch = f"{seq:04d}"
# seq_ch = f"{seq:d}"


if update_all is False:
j = self.current_camera
Expand All @@ -1437,17 +1433,31 @@ def overlay_set_images(self, seq_first: int, seq_last:int):
update_all (bool, optional): _description_. Defaults to True.
display_only (bool, optional): _description_. Defaults to False.
"""


for cam_id in range(len(self.camera_list)):
# print("Inside overlay: ", self.base_name[cam_id])

temp_img = []
for seq in range(seq_first, seq_last):
temp_img.append(img_as_ubyte(imread(self.base_name[cam_id] % seq)))

n_cams = len(self.camera_list)
if not hasattr(self, "base_name"):
self.base_name = [
getattr(self.exp1.active_params.m_params, f"Basename_{i+1}_Seq")
for i in range(len(self.camera_list))
]


for cam_id in range(n_cams):
if os.path.exists(self.base_name[cam_id] % seq_first):
temp_img = []
for seq in range(seq_first, seq_last):
_ = imread(self.base_name[cam_id] % seq)
temp_img.append(img_as_ubyte(_))

temp_img = np.array(temp_img)
temp_img = np.max(temp_img, axis=0)
else:
h_img = self.exp1.active_params.m_params.imx
v_img = self.exp1.active_params.m_params.imy
temp_img = img_as_ubyte(np.zeros((h_img, v_img)))

temp_img = np.array(temp_img)
temp_img = np.max(temp_img, axis=0)

self.camera_list[cam_id].update_image(temp_img)


Expand All @@ -1467,6 +1477,7 @@ def load_disp_image(self, img_name: str, j: int, display_only: bool = False):
h_img = self.exp1.active_params.m_params.imx
v_img = self.exp1.active_params.m_params.imy
temp_img = img_as_ubyte(np.zeros((h_img, v_img)))

# if not display_only:
# ptv.py_set_img(temp_img, j)
if len(temp_img) > 0:
Expand Down Expand Up @@ -1504,7 +1515,8 @@ def main():
# exp_path = Path('/home/user/Downloads/one-dot-example/working_folder')
# exp_path = Path('/home/user/Downloads/test_crossing_particle')
# exp_path = Path('../test_cavity')
exp_path = Path('/media/user/ExtremePro/omer/star_exp')
# exp_path = Path('/media/user/ExtremePro/omer/star_exp')
exp_path = Path('/home/user/Documents/repos/blob_pyptv_folder')
print(f"Without input, PyPTV fallbacks to a default {exp_path} \n")

if not exp_path.is_dir() or not exp_path.exists():
Expand Down