[C++][转载]ubuntu下C++ opencv 显示视频或者读取摄像头代码

配置opencv可以参考http://jingyan.baidu.com/article/14bd256e466474bb6d2612db.html
 
//test.cpp源文件
#include
#include
 
using namespace std;
using namespace cv;
 
int main(int argc,char **argv)
{
    VideoCapture capture(0);
    namedWindow("hhh",CV_WINDOW_AUTOSIZE);
    while(true)
    {    
        Mat frame;
        capture>>frame;
        imshow("hhh",frame);
        waitKey(30);
    }
    return 0;
}

保存之后在终端输入g++ `pkg-config opencv --cflags` test.cpp -o test `pkg-config opencv --libs`  就可以生成可执行文件test,然后在终端输入./test即可调用摄像头。

注意!!包含头文件时#include  ‘/’不要用成‘\’,否则包含不了头文件。

你可能感兴趣的:(C/C++)