[OpenCV3函数] —— open获取摄像头视频

open获取摄像头视频

头文件:opencv2/highgui/highgui.hpp

**作用:**从摄像头获取视频流

函数原型:

(VideoCapture).open(index)
  • 如果默认笔记本/台式机只有一个USB摄像头,Index=0; 如果有2个,一般Index为0和1,根据具体情况区分,摄像头接入和断开会改变Index值

  • 如果接入2个以上,但只想用指定的一个,可以在设备管理器中禁用其他,同时Index设置为0

示例:

#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<bits/stdc++.h>
using namespace std;
char file[50] = "C:\\Users\\Administrator\\Desktop\\test.avi";
int main() {
	cv::namedWindow("1",1);
	cv::VideoCapture frames;
	frames.open(0);
	if (!frames.isOpened()) return 0;
	cv::Mat frame;
	while(1) {
		frames >> frame;
		if (frame.empty())break;
		//高斯滤波进行平滑处理降噪
		cv::GaussianBlur(frame, frame, cv::Size(3, 3), 5, 5);	
		cv::cvtColor(frame, frame, cv::COLOR_BGR2GRAY);
		cv::GaussianBlur(frame, frame, cv::Size(5, 5), 10, 10);

		cv::Canny(frame, frame, 1, 20,3,1);
		
		cv::imshow("1", frame);
		if (cv::waitKey(1) >=0)break;
	}
	frames.release();
	cv::waitKey(0);
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值