How to capture, write and display a video in opencv.

import cv2
import numpy as np

capture = cv2.VideoCapture(0)
frame_width = int(capture.get(3))
frame_height = int(capture.get(4))

out = cv2.VideoWriter('output_1.avi',
                      
cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'), 15,

                (frame_width, frame_height))


while True:
    ret, frame = capture.read()
    out.write(frame)
    cv2.imshow('window', frame)
    if cv2.waitKey(1) == 27:
        break
capture.release()
cv2.destroyAllWindows()

Comments

Popular posts from this blog

how to Create a Black Image in OpenCV

Playing a video from file with color BGR, RGB, GRAY, HSV in OpenCV

Capturing Video via webcam