import cv2
import numpy as np
import os

cap = cv2.VideoCapture(1)#v4l2-ctl --list-devices 查看设备号,非正常中断时,设备号会变,?????????????后续解答
fourcc=0x7634706d
out = cv2.VideoWriter('1.mp4', fourcc,30, (640,480))#mp4比avi小,分辨率是frame.shape,设置成其他分辨保存的视频打不开
num=0
while 1:
# get a frame
    ret, frame = cap.read()
    print(frame.shape)
# save a frame
    out.write(frame)
# show a frame
    cv2.imshow("capture", frame)

    c="%06d"%(num)
    cv2.imwrite(path+str(c)+'.jpg',frame)     
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

    num +=1
cap.release()
out.release()
cv2.destroyAllWindows()

posted on 2018-10-16 19:19  gloria11  阅读(1286)  评论(0编辑  收藏  举报