OpenCV学习:Laplance算子

第十五课 Laplance算子
1.理论
在二阶导数的时候,最大变化处的值为零,即边缘为零值,通过二阶导数计算,依次理论我们可以计算
图像二阶导数,提取边缘。
2.API使用
高斯模糊-去噪声GaussianBlur()
转换为灰度图像cvtColor()
拉普拉斯-二阶导数计算Laplancian()
取绝对值convertScaleAbs()
显示结果
3.代码演示

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

	using namespace cv;
	using namespace std;

	int main(int argc, char**argv)
	{
		Mat src,dst;
		src = imread("H:/pictures/prepic.png");

		if (!src.data)
		{
			cout << "could not load image.." << endl;
			return -1;
		}
		char input_title[] = "input image";
		char output_titlle[] = "Laplance result";
		namedWindow(input_title, CV_WINDOW_AUTOSIZE);
		namedWindow(output_titlle, CV_WINDOW_AUTOSIZE);
		imshow("input", src);

		Mat gray_src, edge_image;
		GaussianBlur(src, dst, Size(3, 3), 0, 0);
		cvtColor(dst, gray_src, CV_BGR2GRAY);
		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(output_titlle, edge_image);

		waitKey(0);
		return 0;
	}
发布了20 篇原创文章 · 获赞 4 · 访问量 2539
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章