Skip to content

Commit a0402f5

Browse files
author
Agustín Castro
committed
Add Ignore button
1 parent b912a56 commit a0402f5

File tree

1 file changed

+106
-20
lines changed

1 file changed

+106
-20
lines changed

norfair/common_reference_ui.py

Lines changed: 106 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
handling_mark_functions = None
4141
handle_mark_annotation = None
4242

43+
global button_says_ignore
44+
global button_ignore
45+
4346

4447
def set_reference(
4548
reference: str,
@@ -57,6 +60,8 @@ def set_reference(
5760
Creates a UI to annotate points that match in reference and footage, and estimate the transformation.
5861
To add a point, just click a pair of points (one from the footage window, and another from the reference window) and select "Add"
5962
To remove a point, just select the corresponding point at the bottom left corner, and select "Remove".
63+
You can also ignore point, by clicking them and selecting "Ignore". The transformation will not used ingored points.
64+
To 'uningnore' points that have been previously ignored, just click them and select "Unignore".
6065
6166
If either footage or reference are videos, you can jump to future frames to pick points that match.
6267
For example, to jump 215 frames in the footage, just write an integer number of frames to jump next to 'Frames to skip (footage)', and select "Skip frames".
@@ -99,6 +104,8 @@ def set_reference(
99104
global transformation
100105

101106
global button_finish
107+
global button_says_ignore
108+
global button_ignore
102109

103110
global reference_point_canvas
104111
global footage_point_canvas
@@ -154,26 +161,24 @@ def set_reference(
154161

155162
def estimate_transformation(points):
156163
global button_finish
157-
if len(points) >= 4:
158-
curr_pts = np.array(
159-
[point["reference"] for point in points.values()]
160-
) # use current points as reference points
161-
prev_pts = np.array(
162-
[point["footage"] for point in points.values()]
163-
) # use previous points as footage points (to deduce reference -> footage)
164-
165-
try:
164+
curr_pts = np.array(
165+
[point["reference"] for point in points.values() if not point["ignore"]]
166+
) # use current points as reference points
167+
prev_pts = np.array(
168+
[point["footage"] for point in points.values() if not point["ignore"]]
169+
) # use previous points as footage points (to deduce reference -> footage)
170+
171+
button_finish.configure(fg="black", highlightbackground="green")
172+
try:
173+
transformation = transformation_getter(curr_pts, prev_pts)[1]
174+
except:
175+
transformation = None
166176

167-
button_finish.configure(fg="black", highlightbackground="green")
168-
return transformation_getter(curr_pts, prev_pts)[1]
169-
except np.linalg.LinAlgError:
170-
button_finish.configure(
171-
fg="grey", highlightbackground="SystemButtonFace"
172-
)
173-
return None
177+
if transformation is not None:
178+
button_finish.configure(fg="black", highlightbackground="green")
174179
else:
175180
button_finish.configure(fg="grey", highlightbackground="SystemButtonFace")
176-
return None
181+
return transformation
177182

178183
def test_transformation(
179184
change_of_coordinates,
@@ -263,9 +268,23 @@ def handle_annotation(event):
263268
global reference_canvas_size
264269
global footage_original_size
265270
global footage_canvas_size
271+
global button_says_ignore
272+
global button_ignore
273+
global points
266274

267275
points[key]["marked"] = not points[key]["marked"]
268276

277+
marked_points = [
278+
point["ignore"] for point in points.values() if point["marked"]
279+
]
280+
281+
if (len(marked_points) > 0) and (all(marked_points)):
282+
button_says_ignore = False
283+
button_ignore.configure(text="Unignore")
284+
else:
285+
button_says_ignore = True
286+
button_ignore.configure(text="Ignore")
287+
269288
if points[key]["marked"]:
270289
points[key]["button"].configure(fg="black", highlightbackground="red")
271290

@@ -289,7 +308,7 @@ def handle_annotation(event):
289308
try:
290309
reference_point_in_rel_coords = skipper["reference"][
291310
"motion_transformation"
292-
].abs_to_rel(np.array([points[key]["footage"]]))[0]
311+
].abs_to_rel(np.array([points[key]["reference"]]))[0]
293312
reference_point_in_rel_coords = np.multiply(
294313
reference_point_in_rel_coords,
295314
np.array(
@@ -303,13 +322,27 @@ def handle_annotation(event):
303322
reference_point_in_rel_coords = points[key]["reference_canvas"]
304323
pass
305324

325+
if points[key]["ignore"]:
326+
color = "gray"
327+
else:
328+
color = "red"
329+
306330
draw_point_in_canvas(
307-
canvas_footage, footage_point_in_rel_coords, color="red"
331+
canvas_footage, footage_point_in_rel_coords, color=color
308332
)
309333
draw_point_in_canvas(
310-
canvas_reference, reference_point_in_rel_coords, color="red"
334+
canvas_reference, reference_point_in_rel_coords, color=color
311335
)
312336
else:
337+
if points[key]["ignore"]:
338+
points[key]["button"].configure(
339+
fg="gray", highlightbackground="gray"
340+
)
341+
else:
342+
points[key]["button"].configure(
343+
fg="black", highlightbackground="SystemButtonFace"
344+
)
345+
313346
points[key]["button"].configure(
314347
fg="black", highlightbackground="SystemButtonFace"
315348
)
@@ -729,6 +762,7 @@ def handle_add_annotation():
729762
"footage_canvas": footage_point_canvas,
730763
"button": None,
731764
"marked": False,
765+
"ignore": False,
732766
}
733767
points[points_sampled] = new_point
734768

@@ -824,6 +858,58 @@ def handle_test_mode(event):
824858

825859
frame_options_annotate_or_test.pack(side=tk.TOP)
826860

861+
###### MAKE SUBBLOCK TO IGNORE POINTS
862+
863+
button_says_ignore = True
864+
frame_options_ignore = tk.Frame(master=frame_options)
865+
text_ignore = tk.Label(
866+
master=frame_options_ignore,
867+
text="Ignore points",
868+
foreground="white",
869+
background="#5f9ea0",
870+
width=20,
871+
height=1,
872+
)
873+
button_ignore = tk.Button(
874+
master=frame_options_ignore,
875+
text="Ignore",
876+
width=16,
877+
height=1,
878+
bg="blue",
879+
fg="black",
880+
command=lambda: handle_ignore_point(),
881+
)
882+
883+
def handle_ignore_point():
884+
global points
885+
global transformation
886+
global button_says_ignore
887+
888+
if button_says_ignore:
889+
fg = "gray"
890+
highlightbackground = "gray"
891+
else:
892+
fg = "black"
893+
highlightbackground = "SystemButtonFace"
894+
895+
for key, couple in points.items():
896+
if couple["marked"]:
897+
points[key]["ignore"] = button_says_ignore
898+
points[key]["button"].configure(
899+
fg=fg, highlightbackground=highlightbackground
900+
)
901+
points[key]["marked"] = False
902+
remove_drawings_in_canvas(canvas_footage)
903+
remove_drawings_in_canvas(canvas_reference)
904+
button_says_ignore = True
905+
button_ignore.configure(text="Ignore")
906+
transformation = estimate_transformation(points)
907+
908+
text_ignore.pack(side=tk.LEFT)
909+
button_ignore.pack(side=tk.LEFT)
910+
911+
frame_options_ignore.pack(side=tk.TOP)
912+
827913
###### MAKE SUBBLOCK TO REMOVE POINTS
828914

829915
frame_options_remove = tk.Frame(master=frame_options)

0 commit comments

Comments
 (0)