簡體   English   中英

顯示GIF並等待按鍵

[英]Show GIF and wait for key press

我正在嘗試使圖像序列的標簽自動化。 我需要根據一定數量對它們進行排序,這可以由操作員輕松找到。

我的想法是為每個序列顯示一個gif(在屏幕上彈出),讓操作員按數字鍵,然后將序列復制到正確的位置,然后彈出另一個gif,等等。

現在,我設法顯示gif並等待按下按鈕,但是我無法獲得所按下的確切鍵...

知道怎么做嗎? 而且我希望能夠在將gif放在前面而不是在終端的同時按下鍵...

這是我的代碼:

    fig = plt.figure()
    for img in sequence:
        im = plt.imshow(img_array,animated=True,cmap='gray')
        ims.append([im])

    ani = animation.ArtistAnimation(fig,ims,interval=50,blit=True,repeat_delay=1000)
    plt.draw()
    plt.pause(1)
    n = raw_input("how many?")
    plt.close(fig) ## shows all the gifs at once, opening multiple windows.

我認為您不想在此處使用動畫,因為那樣只會給用戶固定的有限時間來決定按下某個鍵。 而是使用按鍵來觸發對下一張圖像的更改。

import numpy as np
import matplotlib.pyplot as plt

images = [np.random.rand(10,10) for i in range(13)]

fig, ax = plt.subplots()

im = ax.imshow(images[0], vmin=0, vmax=1, cmap='gray')

curr = [0]
def next_image(evt=None):
    n = int(evt.key)
    # do something with current image
    print("You pressed {}".format(n))
    # advance to next image
    if curr[0] < len(images)-1:
        curr[0] += 1
        im.set_array(images[curr[0]])
        fig.canvas.draw_idle()
    else:
        plt.close()

fig.canvas.mpl_connect("key_press_event", next_image)        
plt.show()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM