OpenCV学习笔记(2)-----开启摄像头

    本文记录了opencv 3.1.0 在Ubuntu 16.04系统下启动笔记本缺省摄像头的一些简要代码。

  

#include 
#include 
#include 

using namespace std;
using namespace cv;


int main(int argc, char** argv)
{
	VideoCapture cap(0); /*open the default camera device*/
	if(!cap.isOpened())  /*check open result*/
	  return false;

	cout<<"Original size:"<> frame;
		imshow("camera show", frame);

		if(waitKey(10) == 27) //press key “ESC” to quit from loop
		  break;
	}


	return 0;
}

下面的code是将上面显示彩色图像进行‘转灰度“->"高斯滤波"->"边沿检测"后再输出:
#include 
#include 
#include 

using namespace std;
using namespace cv;


int main(int argc, char** argv)
{
	VideoCapture cap(0); /*open the default camera device*/
	if(!cap.isOpened())  /*check open result*/
	  return false;

	cout<<"Original size:"<> frame;
                cvtColor(frame, gray, CV_BGR2GRAY); //change color to gray
                GaussianBlur(gray, gray, Size(5,5), 1.5, 1.5); //Gauss filter
                Canny(gray, gray, 0, 100, 5); //edage detection
                imshow("camera show", gray);

		if(waitKey(10) == 27) //press key “ESC” to quit from loop
		  break;
	}


	return 0;
}

你可能感兴趣的:(OpenCV)