Ubuntu16.04下OpenCV调用笔记本摄像头

1,新建一个test.cpp文件,插入下列代码,保存

#include<opencv2/opencv.hpp>
#include<iostream>
 
using namespace std;
using namespace cv;
 
int main(int argc,char **argv)
{
    VideoCapture capture(0);
    namedWindow("myCamera",CV_WINDOW_AUTOSIZE);
    while(true)
    {    
        Mat frame;
        capture>>frame;
        imshow("myCamera",frame);
        waitKey(30);
    }
    return 0;
}

2,生成可执行程序test

$ g++ `pkg-config opencv --cflags` test.cpp -o test `pkg-config opencv --libs`

注意:这里是``(键盘Tab上面的那个键),而不是单引号' '

3,运行test,即可调用摄像头

$ ./test

注意:可使用Ctrl + c 终止当前正在运行的程序

原文地址:https://www.cnblogs.com/SystemCall/p/10629658.html