Guest User

Untitled

a guest
Jan 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import cv2
  2. import matplotlib.pyplot as plt
  3.  
  4. class Viewer:
  5. def __init__(self, video_filename):
  6. self.cap = cv2.VideoCapture(video_filename)
  7. self.ax1 = plt.subplot(1, 2, 1)
  8. self.ax2 = plt.subplot(1, 2, 2)
  9.  
  10. # Grab the first frame.
  11. frame = self.grabframe()
  12. self.im1 = self.ax1.imshow(frame)
  13. self.im2 = self.ax2.imshow(frame)
  14.  
  15. def grabframe(self):
  16. ret, frame = self.cap.read()
  17. if ret:
  18. return frame
  19. else:
  20. print('[ERROR] grabframe failed')
  21. return self.grabframe()
  22.  
  23. def update(self, frame):
  24. """Update the display."""
  25. print('[INFO] updating...')
  26. self.im1.set_data(frame)
  27. self.im2.set_data(frame)
  28. plt.draw()
  29.  
  30.  
  31. def main():
  32. """Run it."""
  33. cli = argparse.ArgumentParser()
  34. cli.add_argument('-i', '--input', type=str, required=True)
  35. args = cli.parse_args()
  36.  
  37. viewer = Viewer(args.input)
  38.  
  39. while True:
  40. viewer.update(viewer.grabframe())
  41.  
  42. if __name__ == '__main__':
  43. plt.ion()
  44. plt.show()
  45. main()
Add Comment
Please, Sign In to add comment