keeping visibility when modifying points

This commit is contained in:
q
2025-08-21 15:50:30 +03:00
parent af70258261
commit e924b3fcea

View File

@@ -380,7 +380,7 @@ class Marker:
"y0": ip["y0"], "y0": ip["y0"],
"x1": ip["x1"], "x1": ip["x1"],
"y1": ip["y1"], "y1": ip["y1"],
"visible": POINT_VISIBILITY[0], "visible": ip["visible"],
} }
self.points_interpolation_required[self.point_index] = True self.points_interpolation_required[self.point_index] = True
except Exception: except Exception:
@@ -474,7 +474,6 @@ class Marker:
"y1": ip["y1"], "y1": ip["y1"],
"visible": POINT_VISIBILITY[0], "visible": POINT_VISIBILITY[0],
} }
# self.interpolate_points()
def modify_point(self, position, x, y): def modify_point(self, position, x, y):
"""position: tl topleft, br bottomright, c center""" """position: tl topleft, br bottomright, c center"""
@@ -507,7 +506,7 @@ class Marker:
"y0": y, "y0": y,
"x1": min(self.video_res[0] - 1, x + w), "x1": min(self.video_res[0] - 1, x + w),
"y1": min(self.video_res[1] - 1, y + h), "y1": min(self.video_res[1] - 1, y + h),
"visible": POINT_VISIBILITY[0], "visible": last_p["visible"],
} }
if position == "br": if position == "br":
self.points[self.point_index][self.nr] = { self.points[self.point_index][self.nr] = {
@@ -515,7 +514,7 @@ class Marker:
"y0": max(0, y - h), "y0": max(0, y - h),
"x1": x, "x1": x,
"y1": y, "y1": y,
"visible": POINT_VISIBILITY[0], "visible": last_p["visible"],
} }
if position == "c": if position == "c":
self.points[self.point_index][self.nr] = { self.points[self.point_index][self.nr] = {
@@ -523,12 +522,11 @@ class Marker:
"y0": max(0, int(y - h / 2)), "y0": max(0, int(y - h / 2)),
"x1": min(self.video_res[0] - 1, int(x + w / 2)), "x1": min(self.video_res[0] - 1, int(x + w / 2)),
"y1": min(self.video_res[1] - 1, int(y + h / 2)), "y1": min(self.video_res[1] - 1, int(y + h / 2)),
"visible": POINT_VISIBILITY[0], "visible": last_p["visible"],
} }
else: else:
# not a new point # not a new point
self.points[self.point_index][self.nr]["visible"] = POINT_VISIBILITY[0]
if position == "c": if position == "c":
current = self.points[self.point_index][self.nr] current = self.points[self.point_index][self.nr]
w = abs(current["x1"] - current["x0"]) w = abs(current["x1"] - current["x0"])
@@ -538,7 +536,7 @@ class Marker:
"y0": max(0, int(y - h / 2)), "y0": max(0, int(y - h / 2)),
"x1": min(self.video_res[0] - 1, int(x + w / 2)), "x1": min(self.video_res[0] - 1, int(x + w / 2)),
"y1": min(self.video_res[1] - 1, int(y + h / 2)), "y1": min(self.video_res[1] - 1, int(y + h / 2)),
"visible": POINT_VISIBILITY[0], "visible": current["visible"],
} }
elif position == "tl": elif position == "tl":
self.points[self.point_index][self.nr]["x0"] = x self.points[self.point_index][self.nr]["x0"] = x
@@ -1485,6 +1483,7 @@ class TrackerGUI:
ok, frame = self.marker.video_reader.read() ok, frame = self.marker.video_reader.read()
frame = cv2.resize(frame.copy(), self.marker.video_res) frame = cv2.resize(frame.copy(), self.marker.video_res)
bbox = tuple([curr_point["x0"], curr_point["y0"], curr_point["w"], curr_point["h"]]) bbox = tuple([curr_point["x0"], curr_point["y0"], curr_point["w"], curr_point["h"]])
bbox_area = curr_point["w"] * curr_point["h"]
ok = tracker.init(frame, bbox) ok = tracker.init(frame, bbox)
visu_interval = 0.2 visu_interval = 0.2
show_time = 0 show_time = 0
@@ -1507,10 +1506,10 @@ class TrackerGUI:
point = self.marker.get_point(nr=self.marker.nr + i) point = self.marker.get_point(nr=self.marker.nr + i)
bbox = tuple([point["x0"], point["y0"], point["w"], point["h"]]) bbox = tuple([point["x0"], point["y0"], point["w"], point["h"]])
tracked[i] = [*bbox, 1] tracked[i] = [*bbox, 1]
show_message = f"Tracking... ({i}/{max_frames})" show_message = f"Tracking... ({i+1}/{max_frames})"
else: else:
# Tracking failure # Tracking failure
show_message = f"Tracking failure detected ({i}/{max_frames})" show_message = f"Tracking failure detected ({i+1}/{max_frames})"
bbox = None bbox = None
if time.time() > show_time + visu_interval: if time.time() > show_time + visu_interval:
@@ -1598,12 +1597,14 @@ class TrackerGUI:
for i in sorted(list(tracked.keys())): for i in sorted(list(tracked.keys())):
if i >= cut_after: if i >= cut_after:
continue continue
track_area = tracked[i][2] * tracked[i][3]
visibility = POINT_VISIBILITY[0] if track_area > 0.9 * bbox_area else POINT_VISIBILITY[1]
self.points[old_nr + i] = { self.points[old_nr + i] = {
"x0": tracked[i][0], "x0": tracked[i][0],
"y0": tracked[i][1], "y0": tracked[i][1],
"x1": tracked[i][0] + tracked[i][2], "x1": tracked[i][0] + tracked[i][2],
"y1": tracked[i][1] + tracked[i][3], "y1": tracked[i][1] + tracked[i][3],
"visible": POINT_VISIBILITY[0], "visible": visibility,
} }
self.marker.nr = old_nr + cut_after - 1 self.marker.nr = old_nr + cut_after - 1