Created
July 23, 2015 02:49
-
-
Save wtakuo/4e135ba8854a83f7d4a7 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
#!/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