Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import matplotlib.pyplot as plt
- class Viewer:
- def __init__(self, video_filename):
- self.cap = cv2.VideoCapture(video_filename)
- self.ax1 = plt.subplot(1, 2, 1)
- self.ax2 = plt.subplot(1, 2, 2)
- # Grab the first frame.
- frame = self.grabframe()
- self.im1 = self.ax1.imshow(frame)
- self.im2 = self.ax2.imshow(frame)
- def grabframe(self):
- ret, frame = self.cap.read()
- if ret:
- return frame
- else:
- print('[ERROR] grabframe failed')
- return self.grabframe()
- def update(self, frame):
- """Update the display."""
- print('[INFO] updating...')
- self.im1.set_data(frame)
- self.im2.set_data(frame)
- plt.draw()
- def main():
- """Run it."""
- cli = argparse.ArgumentParser()
- cli.add_argument('-i', '--input', type=str, required=True)
- args = cli.parse_args()
- viewer = Viewer(args.input)
- while True:
- viewer.update(viewer.grabframe())
- if __name__ == '__main__':
- plt.ion()
- plt.show()
- main()
Add Comment
Please, Sign In to add comment