Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _window_and_sprite(image, caption):
pyglet = check_pyglet_available()
window = pyglet.window.Window(
width=image.width, height=image.height, caption=caption,
)
sprite = pyglet.sprite.Sprite(image)
return window, sprite
def _pyglet_imshow_ndarray(image, caption=None):
# type: (np.ndarray, str) -> None
pyglet = check_pyglet_available()
image = _ndarray_to_imagedata(image)
window, sprite = _window_and_sprite(image, caption=caption)
@window.event
def on_draw():
window.clear()
sprite.draw()
def usage():
print("Usage: ")
print(" h: show help")
print(" q: close window")
@window.event()
def on_key_press(symbol, modifiers):
def _ndarray_to_imagedata(image):
pyglet = check_pyglet_available()
image = PIL.Image.fromarray(image)
image = pyglet.image.ImageData(
width=image.width,
height=image.height,
format=image.mode,
data=image.tobytes(),
pitch=-image.width * len(image.mode),
)
return image
def _pyglet_imshow_generator(images, caption=None, interval=0.5):
# type: (np.ndarray, str, float) -> None
pyglet = check_pyglet_available()
image = _ndarray_to_imagedata(next(images))
window, sprite = _window_and_sprite(image, caption=caption)
window.play = False
@window.event
def on_draw():
window.clear()
sprite.draw()
def usage():
print("Usage: ")
print(" h: show help")
print(" q: close window")
print(" n: next image")