【发布时间】:2016-08-19 10:04:51
【问题描述】:
我正在尝试测试一个非常简单的程序来使用相机捕获视频,但似乎窗口总是黑色的。 打开摄像头的led,程序编译就好了。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main() {
VideoCapture stream1(0); //0 is the id of video device.0 if you have only one camera.
if (!stream1.isOpened()) { //check if video device has been initialised
cout << "cannot open camera";
}
//unconditional loop
while (true) {
Mat cameraFrame;
stream1.read(cameraFrame);
imshow("cam", cameraFrame);
if (waitKey(30) >= 0)
break;
}
system("pause");
return 0;
}
【问题讨论】:
-
您是否确认该相机适用于其他应用程序?我可以运行您的代码,它会正确显示视频,因此代码基本上没有问题。
标签: c++ opencv camera video-capture