【发布时间】:2016-12-19 16:49:50
【问题描述】:
当我在函数中使用:'x'.write(frame) for write to video file in opencv 程序传递代码并且我编译它时没有错误但是当我打开文件时我看到它是 0 kb 并且播放器无法播放。 有人可以帮我吗?
这是我的代码:
// Setup output video
cv::VideoWriter output_cap("output.avi",
CV_CAP_PROP_FOURCC,
CV_CAP_PROP_FPS,
cv::Size(1376, 768));
// Loop to read frames from the image and write it to the output capture
cv::Mat frame = imread("1.jpg", 0);
for(int hgf=1;hgf<=300;hgf++)
{
if (!frame.data)
{
break;
}
output_cap.write(frame);
}
大家好!
【问题讨论】:
-
我怀疑打开文件“1.jpg”失败,所以没有什么可写的。首先确保它正确打开。
-
它是打开的“1.JPG”我检查了它。
-
你检查它是打开的而不是空的吗?尝试显示它,并在
!frame.empty()上添加检查。首先确保您的输入是正确的。我建议使用docs.opencv.org/2.4/doc/tutorials/introduction/… -
CV_CAP_PROP_FOURCC和CV_CAP_PROP_FPS的设置是什么?您是否尝试将output_cap.write(frame);替换为output_cap << frame?frame频道的数量是否等于VideoWriter设置?