opencv对摄像头采集视频的几种变换

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace cv;
using namespace std;

Mat Sobel(Mat src);//Sobel边缘检测;
Mat Laplace(Mat src);//拉普拉斯边缘检测;
Mat Threshold(Mat src);//改变阈值
void threshold(int , void*);//改变阈值的回调函数

int threshold_type = 0;//阈值操作类型;
int threshold_value = 0;//阈值
int const max_type = 3;
int const max_value = 255;
int const max_binvalue = 255;
Mat thresh_temp,thresh_dst;

int main(){
	VideoCapture cap(0);
	if(!cap.isOpened()){
		cout<<"摄像头未能打开"<<endl;
	}
	namedWindow("Video");
	namedWindow("Sobel");
	namedWindow("Laplace");
	namedWindow("Threshold");
	while(true){
		Mat frame;
		cap>>frame;
		if(cap.isOpened() && (char)waitKey(1)!='q'){
			imshow("Video",frame);
			imshow("Sobel",Sobel(frame));
			imshow("Laplace",Laplace(frame));
			imshow("Threshold",Threshold(frame));
		}
		else break;
	}
	return 0;
}
Mat Sobel(Mat src){
	Mat dst,temp,abs_dst;
	cvtColor(src,temp,CV_RGB2GRAY);
	Sobel(temp,dst,CV_16S,0,1,3,1,0,BORDER_DEFAULT);
	convertScaleAbs(dst,abs_dst);
	return abs_dst;
}
Mat Laplace(Mat src){
	Mat dst,temp,abs_dst;
	cvtColor(src,temp,CV_RGB2GRAY);
	Laplacian(temp,dst,CV_16S,3,1,0,BORDER_DEFAULT);
	convertScaleAbs(dst,abs_dst);
	return abs_dst;
}

Mat Threshold(Mat src){
	
	cvtColor(src,thresh_temp,CV_RGB2GRAY);
	createTrackbar("ThresholdType","Threshold",&threshold_type,max_type,threshold);
	createTrackbar("ThresholdValue","Threshold",&threshold_value,max_value,threshold);
	threshold(0,0);
	return thresh_dst;
}
void threshold(int,void*){
	threshold(thresh_temp,thresh_dst,threshold_value,255,threshold_type);
}
具有一定的可玩性。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值