您的位置:首页 > 编程语言 > C语言/C++

C/C++ OpenCV之Laplacian边缘检测

2017-01-10 16:52 411 查看
计算拉普拉斯变换:Laplacian()

void Laplacian(

inputArray src,

outputArray dst,

int deepth,

int ksize=1,

double scale=1,

double delta=0,

int borderType=BORDER_DEFAULT

)

其中int ksize=1,这是关键,这是1,3,5,7这类的奇数,越大说明识别越多

下面是代码:

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;

int main()
{
Mat src, src_gray, dst;

src = imread("1.jpg");
namedWindow("原图");
imshow("原图", src);

//用高斯滤波降噪
Mat g_src;
GaussianBlur(src, g_src, Size(3, 3), 0, 0);

//灰度图像
cvtColor(g_src, src_gray, COLOR_RGB2GRAY);

//开始边缘检测(Laplacian)
Laplacian(src_gray, dst, CV_8U, 9, 1, 0, BORDER_DEFAULT);

namedWindow("效果图");
imshow("效果图", dst);

waitKey();
return 0;
}

运行结果:



我们把

Laplacian(src_gray, dst, CV_8U, 9, 1, 0, BORDER_DEFAULT);

改成

Laplacian(src_gray, dst, CV_8U, 3, 1, 0, BORDER_DEFAULT);

运行结果如下:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  opencv