Created
September 14, 2016 17:32
-
-
Save tibaes/35b9dbd7cbf81a98955067aa318290e7 to your computer and use it in GitHub Desktop.
IPython display cv images
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
# Using docker goldenheart:1.1.0 | |
# pip3 install matplotlib | |
# Import the required modules | |
%pylab inline | |
import cv2 | |
from IPython.display import clear_output | |
frame = cv2.imread("image.jpg") | |
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) | |
axis('off') | |
title('my window') | |
imshow(frame) | |
show() |
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
# 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" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment