opencv 3.2.0无法访问摄像头0

时间:2017-06-13 09:00:58

标签: c++ opencv camera

将opencv 3.2.0编译为mingw - Windows 10创建者中的代码块

我可以用opencv编写程序,它们运行,例如Lena.cpp。 但是当我需要相机时,程序运行,制作窗口,但它不显示笔记本电脑的相机(0)。 这是代码:

#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;
}
return 0;
}

0 个答案:

没有答案