Skip to content

Instantly share code, notes, and snippets.

@wtakuo
Created July 23, 2015 02:49
Show Gist options
  • Save wtakuo/4e135ba8854a83f7d4a7 to your computer and use it in GitHub Desktop.
Save wtakuo/4e135ba8854a83f7d4a7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
'''
OpenCV WebCam Viewer
Reference: http://stackoverflow.com/questions/2601194/displaying-webcam-feed-using-opencv-and-python
'''
import cv2
def camview(name):
cv2.namedWindow(name)
vc = cv2.VideoCapture(0)
if vc.isOpened():
print('Type ESC to dismiss the camera window')
rv, img = vc.read()
while rv:
cv2.imshow(name, img)
rv, img = vc.read()
key = cv2.waitKey(20)
if key == 27:
break
cv2.destroyWindow(name)
else:
print('No camera available')
if __name__ == '__main__':
camview('Camera')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment