Ai
2 Star 14 Fork 5

computer-vision/OpenCV-Python-Tutorial

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
5.VideoWriter.py 847 Bytes
一键复制 编辑 原始数据 按行查看 历史
GH 提交于 2017-07-11 14:31 +08:00 . ch05,视频-调整
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
width = 640
ret = cap.set(3, width)
height = 480
ret = cap.set(4, height)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID') # opencv 3.0
# Error: 'module' object has no attribute 'VideoWriter_fourcc'
# fourcc=cv2.VideoWriter_fourcc('X', 'V', 'I', 'D')
#jpeg,h263,'m', 'p', '4', 'v'
#
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (width, height))
while cap.isOpened():
ret, frame = cap.read()
if ret is True:
frame = cv2.resize(frame, (640, 480))
# write the flipped frame
out.write(frame)
cv2.imshow('frame', frame)
else:
break
key = cv2.waitKey(1)
if key == ord("q"):
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/computer-vision/OpenCV-Python-Tutorial.git
git@gitee.com:computer-vision/OpenCV-Python-Tutorial.git
computer-vision
OpenCV-Python-Tutorial
OpenCV-Python-Tutorial
master

搜索帮助