Skip to content

Instantly share code, notes, and snippets.

@glemaitre
Created November 23, 2018 22:11
Show Gist options
  • Save glemaitre/72295f70d4a9f3fcd486dfbad4131ca1 to your computer and use it in GitHub Desktop.
Save glemaitre/72295f70d4a9f3fcd486dfbad4131ca1 to your computer and use it in GitHub Desktop.
import cv2
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
def grab_frame(cap):
_, frame = cap.read()
return cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
def update(i):
im.set_data(grab_frame(cap))
def close(event):
if event.key == 'q':
plt.close(event.canvas.figure)
cap = cv2.VideoCapture(0)
fig, ax = plt.subplots()
im = ax.imshow(grab_frame(cap))
ani = FuncAnimation(plt.gcf(), update, interval=20)
cid = plt.gcf().canvas.mpl_connect("key_press_event", close)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment