Skip to content

Handle no screenshot in visualize.py / plotting.py #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openadapt/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ def display_event(
recording = action_event.recording
window_event = action_event.window_event
screenshot = action_event.screenshot

if not screenshot:
logger.warning(
f"{screenshot=} for {action_event=} {window_event=} {recording=}"
)
return None
if diff and screenshot.diff:
image = screenshot.diff.convert("RGBA")
else:
Expand Down
4 changes: 1 addition & 3 deletions openadapt/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ def write_events(
started_counter: multiprocessing.Value,
pre_callback: Callable[[float], dict] | None = None,
post_callback: Callable[[dict], None] | None = None,
event_type_modifier: str = "",
) -> None:
"""Write events of a specific type to the db using the provided write function.

Expand All @@ -345,7 +344,6 @@ def write_events(
timestamp as only argument, returns a state dict.
post_callback: Optional function to call after main loop. Takes state dict as
only argument, returns None.
event_type_modifier: Optional string to differentiate identical event_types
"""
utils.set_start_time(recording.timestamp)

Expand All @@ -368,7 +366,7 @@ def write_events(
total_events = num_events.value
progress = tqdm(
total=total_events,
desc=f"Writing {event_type}{event_type_modifier} events...",
desc=f"Writing {event_type} events...",
unit="event",
colour="green",
dynamic_ncols=True,
Expand Down
50 changes: 29 additions & 21 deletions openadapt/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,36 @@ def main(
logger.warning(exc)
continue

if diff_video:
frame_image = frames[idx]
diff_image = compute_diff(
frame_image, action_event.screenshot.image
)

# TODO: rename
diff = frame_image
mask = diff_image
if image:
if diff_video:
frame_image = frames[idx]
diff_image = compute_diff(
frame_image, action_event.screenshot.image
)

# TODO: rename
diff = frame_image
mask = diff_image
else:
diff = display_event(action_event, diff=True)
mask = action_event.screenshot.diff_mask

if SCRUB:
image = scrub.scrub_image(image)
diff = scrub.scrub_image(diff)
mask = scrub.scrub_image(mask)

image_utf8 = image2utf8(image)
diff_utf8 = image2utf8(diff)
mask_utf8 = image2utf8(mask)
width, height = image.size
else:
diff = display_event(action_event, diff=True)
mask = action_event.screenshot.diff_mask

if SCRUB:
image = scrub.scrub_image(image)
diff = scrub.scrub_image(diff)
mask = scrub.scrub_image(mask)

image_utf8 = image2utf8(image)
diff_utf8 = image2utf8(diff)
mask_utf8 = image2utf8(mask)
width, height = image.size
# TODO: display a placeholder image
image_utf8 = ""
diff_utf8 = ""
mask_utf8 = ""
width = 0
height = 1

action_event_dict = row2dict(action_event)
window_event_dict = row2dict(action_event.window_event)
Expand Down
Loading