【笔记】Opencv打开内置摄像头

        Opencv中VideoCapture是专门用来处理视频文件或者摄像头视频流的类,详细的说明和用法可以参考Opencv2.4.13的说明文档:点击打开链接

        使用VideoCapture打开内置摄像头的例子:

#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp>  
 
using namespace cv; 
 
int main(int argc,char *argv[])  
{  
	VideoCapture cap(0);//打开默认的摄像头
	if(!cap.isOpened())  
	{  
		return -1;  
	}  
	Mat frame;  	
	bool stop = false;  
	while(!stop)  
	{  		
		cap.read(frame); //  或cap>>frame;			
		imshow("Video",frame);
		if(waitKey(30)==27) //Esc键退出
		{
			stop = true;  
		}  
	}
	return 0;  
}  

 

#include <opencv2/highgui/highgui.hpp>  
#include <opencv2/imgproc/imgproc.hpp>  
#include <opencv2/core/core.hpp>  
 
using namespace cv; 
 
int main(int argc,char *argv[])  
{  
	VideoCapture cap(0);//打开默认的摄像头
	if(!cap.isOpened())  
	{  
		return -1;  
	}  
	Mat frame; //接收视频输入流 
	Mat embedFrame;
	cap.read(frame); //  或cap>>frame;
	int hight=frame.rows;
	int width=frame.cols;
	embedFrame=Mat::ones(Size(width/3,hight/3),CV_8UC3);
	bool stop = false;  
	while(!stop)  
	{  		
		cap.read(frame); //  或cap>>frame;
		for(int i=0;i<embedFrame.rows;i++)
		{
			for(int j=0;j<embedFrame.cols;j++)
			{
				embedFrame.at<Vec3b>(i,j)[0]=frame.at<Vec3b>(i*3,j*3)[0];
				embedFrame.at<Vec3b>(i,j)[1]=frame.at<Vec3b>(i*3,j*3)[1];
				embedFrame.at<Vec3b>(i,j)[2]=frame.at<Vec3b>(i*3,j*3)[2];
			}
		}
		Mat roi=frame(Rect(0,0,embedFrame.cols,embedFrame.rows));
		addWeighted(roi,0,embedFrame,1,0,roi,-1);		
		imshow("Video",frame);
		if(waitKey(30)==27) //Esc键退出
		{
			stop = true;  
		}  
	}
	return 0;  
} 

bool VideoCapture::set(int propId, double value) 和 double VideoCapture::get(int propId)

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值