import cv2 import matplotlib.pyplot as plt class LaptopCamera: def __init__(self, cam_id=0): self.cam_id = cam_id # There must be some "lazy" way to initialize it self.cap = cv2.VideoCapture(cam_id) self.cap.release() self.image = None def stage(self): ... def trigger(self): self.cap.open(self.cam_id) self.image = self.cap.read()[1] self.cap.release() def unstage(self): ... def show(self): plt.imshow(self.image) plt.show() if __name__ == '__main__': lc = LaptopCamera() lc.trigger() lc.show()