0
私は、matplotlibのanimation.FuncAnimationを使用してカメラの画像を表示します。私はPython 3.6を使用します。 closeイベントに関数を追加する可能性はありますか?matplotlib animation closeイベント
私の目標は: 私が窓を閉じると、カメラを閉じることもできます。私はちょうど全体のpythonアプリケーションではなく、アニメーションのウィンドウを閉じたいです。これを行う最善の方法は何ですか?
from Class.LiveView import LiveView
from Class.PixelFormat import PixelFormat
import matplotlib.pyplot as plt
import matplotlib.animation as animation
class Viewer(object):
"""show picture"""
def __init__ (self):
self.cap = LiveView()
self.cap.startcam()
self.cap.autoExposureTime()
def plotPicLive(self):
self.cap.startGetPic(PixelFormat.Mono8)
fig = plt.figure()
frame = self.cap.getPic()
fig.add_subplot(1,1,1)
im = plt.imshow(frame, animated=True)
def updatefig(*args):
frame = self.cap.getPic()
im.set_array(frame)
return im
ani = animation.FuncAnimation(fig,updatefig, interval=1)
plt.show()
def close(self):
self.cap.stopPic()
self.cap.close()
self.cap.cleanCam()
これはクラスの一例です。
ありがとうございます。