Skip to content

Commit 662a04c

Browse files
committed
VIC-14682 Expression cleanup (#194)
Cleanup annotations so it doesn't show "unknown" for expression Force camera view on top
1 parent b41417d commit 662a04c

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

anki_vector/annotate.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,19 @@ def _label_for_face(self, obj): # pylint: disable=no-self-use
342342
343343
Override or replace to customize.
344344
"""
345+
label_text = ""
345346
expression = faces.Expression(obj.expression).name
347+
348+
if obj.name:
349+
label_text = f"Name:{obj.name}"
350+
if expression != "UNKNOWN":
351+
label_text += f"\nExpression:{expression}"
346352
if obj.expression_score:
347353
# if there is a specific known expression, then also show the score
348354
# (display a % to make it clear the value is out of 100)
349-
expression += f"\nScore:{sum(obj.expression_score)}"
350-
if obj.name:
351-
return ImageText(f"Name:{obj.name}\nExpression:{expression}\nFace Id:({obj.face_id})")
352-
return ImageText(f"Name:unknown\nExpression:{expression}\nFace Id:{obj.face_id}")
355+
label_text += f"\nScore:{sum(obj.expression_score)}"
356+
357+
return ImageText(label_text + "\n" + f"Face Id:{obj.face_id}")
353358

354359

355360
class TextAnnotator(Annotator): # pylint: disable=too-few-public-methods

anki_vector/camera_viewer/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TkCameraViewer: # pylint: disable=too-few-public-methods
4141
:param force_on_top: Specifies whether the window should be forced on top of all others.
4242
"""
4343

44-
def __init__(self, queue: mp.Queue, event: mp.Event, overlays: list = None, timeout: float = 10.0, force_on_top: bool = False):
44+
def __init__(self, queue: mp.Queue, event: mp.Event, overlays: list = None, timeout: float = 10.0, force_on_top: bool = True):
4545
self.tk_root = tk.Tk()
4646
self.width = None
4747
self.height = None
@@ -72,7 +72,10 @@ def _resize_window(self, evt: tk.Event) -> None:
7272

7373
def draw_frame(self) -> None:
7474
"""Display an image on to a Tkinter label widget."""
75-
image = self.queue.get(True, timeout=self.timeout)
75+
try:
76+
image = self.queue.get(True, timeout=self.timeout)
77+
except:
78+
return
7679
self.width, self.height = image.size
7780
while image:
7881
if self.event.is_set():
@@ -87,7 +90,10 @@ def draw_frame(self) -> None:
8790
self.label.image = tk_image
8891
self.tk_root.update_idletasks()
8992
self.tk_root.update()
90-
image = self.queue.get(True, timeout=self.timeout)
93+
try:
94+
image = self.queue.get(True, timeout=self.timeout)
95+
except:
96+
return
9197

9298

9399
def main(queue: mp.Queue, event: mp.Event, overlays: list = None, timeout: float = 10.0, force_on_top: bool = False) -> None:

anki_vector/viewer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, robot):
5757
self._frame_queue: mp.Queue = None
5858
self._process = None
5959

60-
def show(self, timeout: float = 10.0, force_on_top: bool = False) -> None:
60+
def show(self, timeout: float = 10.0, force_on_top: bool = True) -> None:
6161
"""Render a video stream using the images obtained from
6262
Vector's camera feed.
6363

examples/tutorials/19_annotate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def main():
7676
robot.camera.image_annotator.add_annotator("clock", clock)
7777
robot.camera.image_annotator.add_annotator("battery", Battery)
7878

79-
time.sleep(5)
79+
time.sleep(10)
8080

8181
print("Turning off all annotations for 5 seconds")
8282
robot.camera.image_annotator.annotation_enabled = False

0 commit comments

Comments
 (0)