# Import the required modules
%pylab inline
import cv2
from IPython.display import clear_output
Populating the interactive namespace from numpy and matplotlib
# Grab the input device, in this case the webcam
# You can also give path to the video file
vid = cv2.VideoCapture("../data/deepdream/deepdream.mp4")
# Put the code in try-except statements
# Catch the keyboard exception and
# release the camera device and
# continue with the rest of code.
try:
while(True):
# Capture frame-by-frame
ret, frame = vid.read()
if not ret:
# Release the Video Device if ret is false
vid.release()
# Message to be displayed after releasing the device
print "Released Video Resource"
break
# Convert the image from OpenCV BGR format to matplotlib RGB format
# to display the image
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Turn off the axis
axis('off')
# Title of the window
title("Input Stream")
# Display the frame
imshow(frame)
show()
# Display the frame until new frame is available
clear_output(wait=True)
except KeyboardInterrupt:
# Release the Video Device
vid.release()
# Message to be displayed after releasing the device
print "Released Video Resource"
Released Video Resource
%%html
<!-- TODO -->
<iframe width="560" height="315" src="https://www.youtube.com/embed/2TT1EKPV_hc" frameborder="0" allowfullscreen></iframe>