E1: Hello OpenCv

In [1]:
# standard setup
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import cv2

# useful helper function to show images inline
from helpers import imshow

load and display an image

In [2]:
img = cv2.imread('coins.jpg')
imshow(img)

capture single frame of video

In [5]:
# capture a frame from the camera
camera = cv2.VideoCapture(0)
ret, frame = camera.read()
imshow(frame)
camera.release()

Bonus

capture and display multiple frames from the camera

In [4]:
camera = cv2.VideoCapture(0)
while True:
    # Capture frame-by-frame
    ret, frame = camera.read()
    cv2.imshow('camera', frame)
    if cv2.waitKey(5) == 27:
        break
cv2.destroyAllWindows()
print('destroy')
camera.release()
print('release')
cv2.waitKey(1) # extra waitKey sometimes needed to close camera window
destroy
release
Out[4]:
-1