opencv c++自定义线性滤波

#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>

using namespace cv;
int main()
{
	Mat src = imread("C:/Users/asus/Desktop/tupian/1.jpg");
	if (src.empty())
	{
		printf("could not load image...\n");
		return -1;
	}
	namedWindow("opencv setup demo", WINDOW_AUTOSIZE);
	imshow("opencv setup demo", src);
	namedWindow("output window", WINDOW_AUTOSIZE);
	Mat dst;
	//robart
	Mat kernel_x = (Mat_<int>(2, 2) << 1, 0, 0, -1);//x方向
	filter2D(src, dst, -1, kernel_x, Point(-1, -1), 0, 0);
	imshow("output window", dst);
	Mat kernel_y = (Mat_<int>(2, 2) << 0,1,-1,0);//y方向
	filter2D(src, dst, -1, kernel_y, Point(-1, -1), 0, 0);
	imshow("output robart_y", dst);

	//
	waitKey(0);
	return 0;

}


#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>

using namespace cv;
int main()
{
	Mat src = imread("C:/Users/asus/Desktop/tupian/1.jpg");
	if (src.empty())
	{
		printf("could not load image...\n");
		return -1;
	}
	namedWindow("opencv setup demo", WINDOW_AUTOSIZE);
	imshow("opencv setup demo", src);
	namedWindow("output window", WINDOW_AUTOSIZE);
	Mat dst;
	//sobel
	Mat kernel_x = (Mat_<int>(3, 3) << -1,0,1,-2,0,2,-1,0,1);//x方向
	filter2D(src, dst, -1, kernel_x, Point(-1, -1), 0, 0);
	imshow("output window", dst);
	Mat kernel_y = (Mat_<int>(3, 3) << -1,-2,-1,0,0,0,1,2,1);//y方向
	filter2D(src, dst, -1, kernel_y, Point(-1, -1), 0, 0);
	imshow("output y", dst);

	//
	waitKey(0);
	return 0;

}


#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>

using namespace cv;
int main()
{
	Mat src = imread("C:/Users/asus/Desktop/tupian/1.jpg");
	if (src.empty())
	{
		printf("could not load image...\n");
		return -1;
	}
	namedWindow("opencv setup demo", WINDOW_AUTOSIZE);
	imshow("opencv setup demo", src);
	namedWindow("output window", WINDOW_AUTOSIZE);
	Mat dst;
	//拉普拉斯算子
	Mat kernel_x = (Mat_<int>(3, 3) << 0,-1,0,-1,4,-1,0,-1,0);//x方向
	filter2D(src, dst, -1, kernel_x, Point(-1, -1), 0, 0);
	imshow("output window", dst);


	//
	waitKey(0);
	return 0;

}


#include<opencv2\opencv.hpp>
#include<iostream>
#include<math.h>

using namespace cv;
int main()
{
	Mat src = imread("C:/Users/asus/Desktop/tupian/1.jpg");
	if (src.empty())
	{
		printf("could not load image...\n");
		return -1;
	}
	namedWindow("opencv setup demo", WINDOW_AUTOSIZE);
	imshow("opencv setup demo", src);
	namedWindow("output window", WINDOW_AUTOSIZE);
	Mat dst;
	int c = 0;
	int index = 0;
	int kzize = 3;
	while (true)
	{
		c = waitKey(500);
		if((char)c==27)
		{
			break;
		}
		kzize = 4 + (index % 5) * 2 + 1;
		Mat kernel = Mat::ones(Size(kzize, kzize), CV_32F) / (float)(kzize*kzize);
		filter2D(src, dst, -1, kernel, Point(-1, -1), 0, 0);
		index++;
		imshow("output window", dst);

	}


	//
	waitKey(0);
	return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值