Skip to content

Instantly share code, notes, and snippets.

@kamatari
Created July 13, 2014 15:59
Show Gist options
  • Save kamatari/ae0f37cd31375a191e0e to your computer and use it in GitHub Desktop.
Save kamatari/ae0f37cd31375a191e0e to your computer and use it in GitHub Desktop.
'''
usage:
python show_camera_or_video.py
or
python show_camera_or_video.py cam
or
python show_camera_or_video.py inputfilename.avi
'''
import numpy as np
import cv2
def getSource():
import sys
if (len(sys.argv) != 2):
source = "./xxxx.avi"
elif (sys.argv[1] == 'cam'):
source = 0 # 0 means camera_id
else:
source = sys.argv[1]
return source
if __name__=='__main__':
source = getSource()
cam = cv2.VideoCapture(source)
while (True):
ret, frame = cam.read()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cam.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment