opencv读取摄像头并保存成视频(python)

尝试了很久,一直都有问题,最后发现这样可以成功,分享给大家做一个参考。

import cv2

cam = cv2.VideoCapture(0)

wid = int(cam.get(3))
hei = int(cam.get(4)) 
size = (wid,hei)
fps = 30

fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
out = cv2.VideoWriter()
out.open(r"C:\Users\75158\Desktop\OPENCV study\Yarn\video\AA.mp4",
                      fourcc, fps, size)

 
while True:
    ret, frame  = cam.read()
    if ret==False:
        break
    frame = cv2.flip(frame,1)
    
    out.write(frame)
    cv2.imshow("frame",frame)
    
    key = cv2.waitKey(100)
    if cv2.waitKey(25) & 0xFF == ord('1'):#当按键 1 呗按下
            break
cam.release()
out.release()
cv2.destroyAllWindows()
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值