opencv reads the video captured by the camera and saves it

import cv2

cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('lianzheng.avi', fourcc, 20.0, (640, 480))
while True:
    ret, frame = cap.read()
    print(frame.shape)
    out.write(frame)
    cv2.imshow('frame', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
out.release()
cv2.destroyAllWindows()

(640, 480)
Be sure to pay attention to this parameter. Many people cannot open the saved video because this parameter is incorrect.
You can first take a look at frame.shape
and print it out. If it is (480,640)
, then the parameter is (640,480)
according to your own situation. Decide yourself

Guess you like

Origin blog.csdn.net/wuxulong123/article/details/116976500