Created
November 23, 2018 22:11
-
-
Save glemaitre/72295f70d4a9f3fcd486dfbad4131ca1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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