【发布时间】:2016-02-07 20:17:44
【问题描述】:
我曾经创建过一个项目并且它工作正常,在重新安装操作系统后,我设置了环境和所有组件,突然我根本没有得到任何输出。我的测试程序很简单:
#include <cstdio>
#include "opencv2/opencv.hpp"
#include <iostream>
#include <sstream>
using namespace cv;
using namespace std;
int main(int, char**)
{
VideoCapture cap("videofile.avi");
if (!cap.isOpened()) // check if we succeeded
return -1;
namedWindow("Frame", 1);
for (;;)
{
Mat frame;
if (!cap.read(frame)) {
cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl;
exit(EXIT_FAILURE);
}
imshow("Frame", frame);
if (waitKey(30) >= 0) break;
}
return 0;
}
我已安装所有必要的编解码器并更新了显卡驱动程序。仍然出现同样的黑屏。
编辑:
问题似乎只在使用 AVC 编解码器播放 .avi 视频时出现
【问题讨论】:
-
代码似乎没问题。尝试使用默认摄像头的
VideoCapture cap(0);。如果它有效,那么你有一些编解码器问题 -
@Miki 它确实适用于相机。我将不得不再次检查我的编解码器。我已经安装了 K-Lite 编解码器 Mega
-
你的PATH变量或二进制目录中有opencv_ffmpeg dll吗?
-
是的,我有,有趣的是我上次不需要这样的东西。
-
@Croolman 加载和显示单个图像是否有效?您可以尝试使用 cv::VideoWriter 将网络摄像头流录制到 .avi 文件并尝试使用 cv::VideoCapture 加载该文件吗?如果是编解码器问题,如果编码工作,解码应该工作?!?