Skip to content

Using Image.show() fails because the temporary file written does not exist #5968

@trzy

Description

@trzy

What did you do?

I am using the below code (with show_image=True) to show an image. Works with Pillow==8.4.0 but fails with Pillow==9.0.0. The image viewer applications opens up but the temporary file that Pillow produces is not there.

def show_detections(output_path, show_image, image, scored_boxes_by_class_index, class_index_to_name):
  # Draw all results
  ctx = ImageDraw.Draw(image, mode = "RGBA")
  color_idx = 0
  for class_index, scored_boxes in scored_boxes_by_class_index.items():
    for i in range(scored_boxes.shape[0]):
      scored_box = scored_boxes[i,:]
      class_name = class_index_to_name[class_index]
      text = "%s %1.2f" % (class_name, scored_box[4])
      color = _class_to_color(class_index = class_index)
      _draw_rectangle(ctx = ctx, corners = scored_box[0:4], color = color, thickness = 2)
      _draw_text(image = image, text = text, position = (scored_box[1], scored_box[0]), color = color, scale = 1.5, offset_lines = -1)

  # Output
  if show_image:
    image.show()
  if output_path is not None:
    image.save(output_path)
    print("Wrote detection results to '%s'" % output_path)

Inserting a sleep thereafter doesn't help.

What did you expect to happen?

The temporary file should be present and the application should be able to view it.

What actually happened?

Image file not found.

What are your OS, Python and Pillow versions?

  • OS: Ubuntu
  • Python: 3.8.5
  • Pillow: 9.0.0
code goes here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions