fixing interpolator

This commit is contained in:
Q
2025-08-22 21:06:55 +03:00
parent 74db994d16
commit c35a3e90bd

View File

@@ -284,17 +284,15 @@ class Marker:
frame, (0, self.mouse_position[1]), (self.video_res[0], self.mouse_position[1]), (128, 128, 128), 1
)
# Show current track
x, y = [20, 70]
intrp_str = (
""
if not self.points_interpolation_enabled
else " i*" if True in self.points_interpolation_required.values() else " i"
)
self.shadow_text(
frame,
f"P:{str(self.point_index)}{intrp_str}",
(x, y),
(20, 70),
0.5,
1,
(255, 255, 255),
@@ -383,7 +381,7 @@ class Marker:
"y1": ip["y1"],
"visible": ip["visible"],
}
self.points_interpolation_required[self.point_index] = True
self.interpolate_set(self.point_index)
except Exception:
pass
@@ -560,8 +558,7 @@ class Marker:
self.points[self.point_index][self.nr]["y0"],
self.points[self.point_index][self.nr]["y1"],
)
self.points_interpolation_required[self.point_index] = True
self.interpolate_set(self.point_index)
def modify_point_wh(self):
@@ -582,8 +579,7 @@ class Marker:
self.points[self.point_index][self.nr]["x1"] = int(curr_point["cx"] + new_wh)
self.points[self.point_index][self.nr]["y1"] = int(curr_point["cy"] + new_hh)
self.points[self.point_index][self.nr]["visible"] = POINT_VISIBILITY[0]
self.points_interpolation_required[self.point_index] = True
self.interpolate_set(self.point_index)
def toggle_point_visibility(self):
@@ -610,7 +606,7 @@ class Marker:
except Exception as e:
print(e)
pass
self.points_interpolation_required[self.point_index] = True
self.interpolate_set(self.point_index)
def track_point(self):
@@ -626,7 +622,7 @@ class Marker:
if len(tracker_gui.points) > 0:
for nr in tracker_gui.points:
self.points[self.point_index][nr] = tracker_gui.points[nr]
self.points_interpolation_required[self.point_index] = True
self.interpolate_set(self.point_index)
self.nr = max(tracker_gui.points) - 1
self.read_next = True
@@ -675,6 +671,15 @@ class World:
if self.plugin:
self.plugin()
def interpolate_set(self, point_index=None):
if point_index is None:
point_index = self.point_index
self.points_interpolation_required[point_index] = True
if not self.interpolate_thread_alive():
print("ERROR: Interpolator thread is not running!")
self.interpolate_thread_start()
def interpolate_points(self, point_index=None):
"""types:
key: user clicked / accepted frame
@@ -685,7 +690,6 @@ class World:
try:
if not point_index in self.points:
return
self.interpolate_thread_start()
if point_index is None:
point_index = self.point_index
@@ -779,12 +783,17 @@ class World:
def interpolate_thread_stop(self):
self.points_interpolation_thread_exit = True
for point_index in self.points_interpolation_required:
if self.points_interpolation_required[point_index]:
self.interpolate_points(point_index)
def interpolate_thread_alive(self):
if self.points_interpolation_thread is None:
return False
return self.points_interpolation_thread.is_alive()
def interpolate_points_in_thread(self):
self.points_interpolation_frequency = 1
@@ -807,7 +816,7 @@ class World:
self.points_interpolation_enabled = not self.points_interpolation_enabled
if self.points_interpolation_enabled:
self.interpolate_points()
self.interpolate_thread_start()
def draw_help(self, frame):
@@ -1035,7 +1044,7 @@ class World:
)
if not self.points[index][key].get("visible", "NA") in POINT_VISIBILITY:
self.points[index][key]["visible"] = POINT_VISIBILITY[0]
self.interpolate_points()
self.interpolate_set(index)
print(f"Loaded points with index: {index}")
self.point_index = None
@@ -1462,7 +1471,7 @@ class World:
except Exception as e:
print(e)
self.interpolate_thread_stop()
self.interpolate_thread_stop()
self.video_reader.release()
cv2.destroyAllWindows()
self.print_timestamps()
@@ -1617,7 +1626,7 @@ class TrackerGUI:
if i >= cut_after:
continue
track_area = tracked[i][2] * tracked[i][3]
visibility = POINT_VISIBILITY[0] if track_area > 0.9 * bbox_area else POINT_VISIBILITY[1]
visibility = POINT_VISIBILITY[0] if track_area > 0.5 * bbox_area else POINT_VISIBILITY[1]
self.points[old_nr + i] = {
"x0": tracked[i][0],
"y0": tracked[i][1],