【发布时间】:2014-01-05 07:29:15
【问题描述】:
我正在尝试在 OpenCV 中运行用于从网络摄像头捕获视频的程序。每次我运行程序时,都会显示一个灰色屏幕。我最初尝试使用 CvCapture 函数在 C API 中编程,它工作得非常好。但是现在在 C++ API 中,当我尝试运行以下使用 VideoCapture 的代码时,会显示灰屏。
我该如何解决这个问题?请帮忙。我的 OpenCV 版本是 2.4.6,我在 MS Visual Studio 2010 Professional 中运行代码。
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(int argc, char** argv)
{
VideoCapture capture(0);
Mat frame;
if( !capture.isOpened() )
throw "Error when reading steam_avi";
namedWindow( "w", 1);
for( ; ; )
{
capture.read(frame);
if(frame.empty())
break;
imshow("w", frame);
waitKey(1);
}
waitKey(0);
}
【问题讨论】:
-
有人知道这个吗?我得到了同样的东西。