小编Moh*_*kar的帖子

opencv黑屏视频采集

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

c++ camera opencv video-capture

6
推荐指数
2
解决办法
5902
查看次数

标签 统计

c++ ×1

camera ×1

opencv ×1

video-capture ×1