version 0.7.14. fixing interpolator issues

This commit is contained in:
q
2025-09-04 11:31:58 +03:00
parent 61217e034b
commit 793cc66b53
2 changed files with 25 additions and 37 deletions

View File

@@ -2,7 +2,7 @@ import argparse
from tsmark.video_annotator import Marker from tsmark.video_annotator import Marker
VERSION = "0.7.13" VERSION = "0.7.14"
class SmartFormatter(argparse.HelpFormatter): class SmartFormatter(argparse.HelpFormatter):

View File

@@ -814,7 +814,7 @@ class World:
return True return True
return False return False
def interpolate_set(self, point_index=None, nr=None): def interpolate_set(self, point_index=None, nr=None, refresh=False):
if point_index is None: if point_index is None:
point_index = self.point_index point_index = self.point_index
@@ -823,6 +823,11 @@ class World:
if not point_index in self.points_interpolation_required: if not point_index in self.points_interpolation_required:
self.points_interpolation_required[point_index] = [] self.points_interpolation_required[point_index] = []
self.points_interpolation_required[point_index].append(nr) self.points_interpolation_required[point_index].append(nr)
if refresh:
# refresh all points
if point_index in self.points:
self.points_interpolation_required[point_index].extend(list(self.points[point_index].keys()))
if not self.interpolate_thread_alive(): if not self.interpolate_thread_alive():
print("ERROR: Interpolator thread is not running!") print("ERROR: Interpolator thread is not running!")
self.interpolate_thread_start() self.interpolate_thread_start()
@@ -846,12 +851,6 @@ class World:
def point2array(p): def point2array(p):
return [p["x0"], p["y0"], p["x1"], p["y1"]] return [p["x0"], p["y0"], p["x1"], p["y1"]]
def tryadd(s, key, l):
try:
s.add(l[key])
except IndexError:
pass
if point_index in self.points_interpolation_required: if point_index in self.points_interpolation_required:
seed_keys = ( seed_keys = (
[x for x in self.points_interpolation_required[point_index]] [x for x in self.points_interpolation_required[point_index]]
@@ -881,35 +880,23 @@ class World:
global_point_keys = list(sorted(list(self.points[point_index].keys()))) global_point_keys = list(sorted(list(self.points[point_index].keys())))
if len(seed_keys) > 0: if len(seed_keys) > 0:
point_keys = set() point_indexes = []
min_seed = min(seed_keys) min_seed = min(seed_keys)
max_seed = max(seed_keys) max_seed = max(seed_keys)
min_found = False first_seed = None
max_found = False
for pi, nr in enumerate(global_point_keys): for pi, nr in enumerate(global_point_keys):
if not min_found: if nr >= min_seed and nr <= max_seed:
min_index = pi point_indexes.append(pi)
if not max_found: if nr > min_seed and first_seed is None:
max_index = pi first_seed = pi
if nr >= min_seed: point_indexes.append(pi)
min_found = True
if nr <= max_seed:
tryadd(point_keys, pi, global_point_keys)
if nr > max_seed: if nr > max_seed:
max_found = True
break break
if min_found: if len(point_indexes) == 0:
for shift in range(-3, 0): point_indexes.append(pi)
tryadd(point_keys, min_index + shift, global_point_keys) min_index = max(0, min(point_indexes) - 3)
if max_found: max_index = min(len(global_point_keys) - 1, max(point_indexes) + 3)
for shift in range(2): point_keys = [global_point_keys[pi] for pi in range(min_index, max_index + 1)]
tryadd(point_keys, max_index + shift, global_point_keys)
else:
for shift in range(-3, -1):
tryadd(point_keys, len(global_point_keys) + shift, global_point_keys)
point_keys = list(sorted(list(point_keys)))
else: else:
point_keys = global_point_keys point_keys = global_point_keys
@@ -954,10 +941,10 @@ class World:
new_points[key]["age"] = age new_points[key]["age"] = age
self.points_interpolated[point_index] = new_points self.points_interpolated[point_index] = new_points
if point_index in self.points_interpolation_required: if point_index in self.points_interpolation_required:
self.points_interpolation_required[point_index] = [ self.points_interpolation_required[point_index] = [
x for x in self.points_interpolation_required[point_index] if x not in seed_keys x for x in self.points_interpolation_required[point_index] if x not in seed_keys
] ]
except Exception as e: except Exception as e:
print(f"Interpolation error: {e}") print(f"Interpolation error: {e}")
@@ -1251,7 +1238,7 @@ class World:
) )
if not self.points[index][key].get("visible", "NA") in POINT_VISIBILITY: if not self.points[index][key].get("visible", "NA") in POINT_VISIBILITY:
self.points[index][key]["visible"] = POINT_VISIBILITY[0] self.points[index][key]["visible"] = POINT_VISIBILITY[0]
self.interpolate_set(index, key) self.interpolate_set(index, refresh=True)
print(f"Loaded points with index: {index}") print(f"Loaded points with index: {index}")
self.point_index = None self.point_index = None
@@ -1563,6 +1550,7 @@ class World:
self.point_click = 0 self.point_click = 0
else: else:
self.point_index = chr(k2) self.point_index = chr(k2)
self.interpolate_set(refresh=True)
elif k & 0xFF == ord("g"): # Go to elif k & 0xFF == ord("g"): # Go to
self.shadow_text( self.shadow_text(
frame_visu, frame_visu,