1. 程式人生 > >Ubuntu16.04下opencv呼叫攝像頭的程式

Ubuntu16.04下opencv呼叫攝像頭的程式

配置opencv可以參考http://jingyan.baidu.com/article/14bd256e466474bb6d2612db.html

//test.cpp原始檔
#include<opencv2/opencv.hpp>
#include<iostream>

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<opencv2/opencv.hpp>  ‘/’不要用成‘\’,否則包含不了標頭檔案。。