How to use the imgviz._io._pyglet.base.check_pyglet_available function in imgviz

To help you get started, we’ve selected a few imgviz examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wkentaro / imgviz / imgviz / _io / _pyglet / pyglet_imshow.py View on Github external
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
github wkentaro / imgviz / imgviz / _io / _pyglet / pyglet_imshow.py View on Github external
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):
github wkentaro / imgviz / imgviz / _io / _pyglet / pyglet_imshow.py View on Github external
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
github wkentaro / imgviz / imgviz / _io / _pyglet / pyglet_imshow.py View on Github external
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")