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;
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值