【发布时间】:2021-10-23 23:21:00
【问题描述】:
我最近开始使用 opencv-python 进行编程,但是当我尝试使用 cv2 编写视频时卡住了。 脚本的输出为空。这是我的代码:
import cv2
import numpy as np
import matplotlib.pyplot as plt
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'h263')
out = cv2.VideoWriter('cv2_camera_output.mp4',fourcc, 20.0, (800,600))
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame', frame)
cv2.imshow('gray', gray)
out.write(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
out.release()
cv2.destroyAllWindows()
我猜问题一定与fourcc编解码器有关。所以我用谷歌搜索是否有适用于 mac 的fourCC 编解码器(我使用的是 OS X 10.12.3 (Sierra)),但 所有建议都不适用于我的电脑,所以这个问题甚至可能不存在在fourCC编解码器中。这些是我访问过的链接:
OpenCV Documentation (I didn't follow this one, it was just to make sure, and it didn't work either)
GitHub Tests for FourCC codecs on OS X
有人知道真正的问题吗?任何帮助都会很棒
【问题讨论】: