Created
February 8, 2014 02:42
-
-
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.
This file contains 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
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