Skip to content

Instantly share code, notes, and snippets.

@kevinhughes27
Created February 8, 2014 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinhughes27/8875858 to your computer and use it in GitHub Desktop.
Save kevinhughes27/8875858 to your computer and use it in GitHub Desktop.
a simple starting framework for grabbing frames from a camera or video file using OpenCV and python.
import cv2
CAMERA_INDEX = 0
CODEC = cv2.cv.CV_FOURCC('D','I','V','X')
FPS = 15
def main():
cam = cv2.VideoCapture()
cam.open(CAMERA_INDEX)
w = int(cam.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
h = int(cam.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
video = cv2.VideoWriter('video.avi',CODEC,FPS,(w,h))
key = -1
while key != 1048689:
flag, frame = cam.read()
if(flag == False):
break
cv2.imshow("frame",frame)
video.write(frame)
key = cv2.waitKey(30)
video.release()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment