Skip to content
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

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

Closed
trzy opened this issue Jan 17, 2022 · 3 comments
Closed

Comments

@trzy
Copy link

trzy commented Jan 17, 2022

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
@radarhere
Copy link
Member

radarhere commented Jan 17, 2022

Hi. There is already an issue open for this - #5945.
What application is opening?
Inserting sleep in your code wouldn't work, but some users in that other thread have found that inserting sleep into Pillow's code works. Is that what you've tried? What values have you tried?

@trzy
Copy link
Author

trzy commented Jan 18, 2022

Ah, sorry, didn't realize. I've tried a sleep of as high as 5 seconds. The image viewer is just the default GNOME image viewer in Ubuntu.

@radarhere
Copy link
Member

Pillow 9.0.1 has just been released, and should resolve this. Let us know if it does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants