使用核的图像卷积----水平直线的检测

使用核的图像卷积----水平直线的检测

//Program to apply a simple filter matrix to an image to detect horizontal edges

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
	Mat img=imread("E:\\图片\\hd1.jpg",CV_LOAD_IMAGE_GRAYSCALE);
	Mat img_filtered;
	//Filter kernel for detecting vertical edges
	float vertical_fk[5][5]={{0,0,0,0,0},{0,0,0,0,0},{-1,-2,6,-2,-1},{0,0,0,0,0},{0,0,0,0,0}};
	//Filter kernel for detecting horizontal edges
	float horizontal_fk[5][5]={{0,0,-1,0,0},{0,0,-2,0,0},{0,0,6,0,0},{0,0,-2,0,0},{0,0,-1,0,0}};
	Mat filter_kernel=Mat(5,5,CV_32FC1,horizontal_fk);//检测水平直线
	//Mat filter_kernel=Mat(5,5,CV_32FC1,vertical_fk);//检测垂直直线
	//apply filter
	filter2D(img,img_filtered,-1,filter_kernel);
	namedWindow("Image");
	namedWindow("Filtered image");
	imshow("Image",img);
	imshow("Filtered image",img_filtered);
	while(char (waitKey(1))!='q')
	{
	}
	return 0;
}

原始图像:


处理后的效果图(水平直线检测):


垂直直线的检测:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值