1.laplace算子
一阶导数的极值位置,二阶导数为0。所以我们也可以用这个特点来作为检测图像边缘的方法。
Laplacian 算子 的定义:
OpenCV函数 Laplacian 实现了Laplacian算子。 实际上,由于 Laplacian使用了图像梯度,它内部调用了 Sobel 算子
对应函数:Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );函数接受了以下参数:src_gray: 输入图像。dst: 输出图像ddepth: 输出图像的深度。 因为输入图像的深度是 CV_8U ,这里我们必须定义 ddepth =CV_16S 以避免外溢。kernel_size: 内部调用的 Sobel算子的内核大小,此例中设置为3。scale, delta 和 BORDER_DEFAULT: 使用默认值以下是源代码:
#include <cv.h>#include <opencv2/core/core.hpp> #include <opencv2/imgPRoc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp>using namespace std;using namespace cv;int main( int argc, char** argv ){//Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );/*函数接受了以下参数: src_gray: 输入图像。 dst: 输出图像 ddepth: 输出图像的深度。 因为输入图像的深度是 CV_8U ,这里我们必须定义 ddepth = CV_16S 以避免外溢。 kernel_size: 内部调用的 Sobel算子的内核大小,此例中设置为3。 scale, delta 和 BORDER_DEFAULT: 使用默认值。*/ int kernel_size=3; int scale = 1; int delta = 0; Mat image=imread("./1.jpg",CV_LOAD_IMAGE_GRAYSCALE); Mat lap; Laplacian(image,lap,CV_16S,kernel_size,scale,delta,BORDER_DEFAULT); //convertScaleAbs( dst, abs_dst ); //将输出图像的深度转化为 CV_8U : Mat lap_image; convertScaleAbs(lap,lap_image); imwrite("./lap.jpg",lap_image); imshow("laplace",lap_image); waitKey(0); return 0;}原图片:
效果图:
新闻热点
疑难解答