python opencv 调用摄像头保存到本地的avi文件不正确?

  1. 环境是ubuntu + opencv 3.3.1-dev + python3.5
  2. 代码如下:

# -*- coding:utf-8 -*-

import cv2

import time

import numpy as np

# 打开摄像头

cap = cv2.VideoCapture(0)

# 视屏封装格式

fourcc = cv2.VideoWriter_fourcc(*'MPEG')

# 参数分别为保存为保存文件名, 编码器, 帧率, 大小

out = cv2.VideoWriter('out.avi', fourcc, 20.0, (640, 400))

while True:

ret, frame = cap.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

out.write(frame)

cv2.imshow('frame', frame)

# 抓取图像

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

cv2.imwrite('image/' + str(int(time.time())) + '.jpg', frame)

# 退出

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

break

cap.release()

out.release()

cv2.destroyAllWindows()

摄像头能正常打开, 图像也能抓取, 但是out.avi保存到本地只有几kb, 也打不开

clipboard.png

回答:

http://blog.csdn.net/jeapeduc...

以上是 python opencv 调用摄像头保存到本地的avi文件不正确? 的全部内容, 来源链接: utcz.com/a/160608.html

回到顶部