Ich benutze die animation.FuncAnimation von matplotlib, um Kamerabilder anzusehen. Ich benutze Python 3.6. Gibt es eine Möglichkeit, eine Funktion an das Close-Event anzuhängen?matplotlib animation close event
Mein Ziel ist: Wenn ich das Fenster schließe, möchte ich auch die Kamera schließen. Ich möchte nur das Fenster der Animation nicht die gesamte Python-Anwendung schließen. Was ist der beste Weg, dies zu tun?
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()
Dies ist nur eine Beispielklasse.
danke im voraus.