理论

opencv018-Laplance算子

解释:在二阶导数的时候,最大变化处的值为零即边缘是零值。通过二阶

导数计算,依据此理论我们可以计算图像二阶导数,提取边缘。

l二阶导数我不会,别担心 ->拉普拉斯算子(Laplance operator)

lOpencv已经提供了相关API - cv::Laplance

处理流程:

l高斯模糊 去噪声GaussianBlur()

l转换为灰度图像cvtColor()

l拉普拉斯 二阶导数计算Laplacian()

l取绝对值convertScaleAbs()

l显示结果

API使用cv::Laplacian:

Laplacian(

InputArray src,

OutputArray dst,

int depth, //深度CV_16S

int kisze, // 3

double scale = 1,

double delta =0.0,

int borderType = 4

)

opencv018-Laplance算子

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;

Mat src, dst, gray_src;

int main(int agrc, char** agrv) {

	src = imread("C:/Users/liyangxian/Desktop/bjl/nm3.jpg");
	if (!src.data) {
		printf("no load..\n");
		return -1;
	}
	const char* input_win = "input";
	const char* out_put = "out_put";
	namedWindow(input_win, CV_WINDOW_AUTOSIZE);
	namedWindow(out_put, CV_WINDOW_AUTOSIZE);
	imshow(input_win, src);
	GaussianBlur(src, dst, Size(3, 3), 0, 0);
	cvtColor(dst, gray_src, CV_BGR2GRAY);
	Mat edge_image;
	Laplacian(gray_src, edge_image, CV_16S, 3);
	convertScaleAbs(edge_image, edge_image);
	threshold(edge_image, edge_image, 0, 255, THRESH_OTSU | THRESH_BINARY);
	imshow(out_put, edge_image);

	waitKey(0);
	return 0;
}

相关文章: