我正在尝试测试一个非常简单的程序来使用相机捕获视频,但窗口似乎总是黑色的。相机的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;
}
Run Code Online (Sandbox Code Playgroud)