018-Opencv笔记-拉普拉斯算子

拉普拉斯算子(Laplance)

在二阶导数的时候,最大变化处的值为零即边缘是零值。通过二阶导数计算,依据此理论我们可以计算图像二阶导数,提取边缘。

Laplacian(
InputArray src,
OutputArray dst,
int depth, //深度CV_16S
int kisze, // 3
double scale = 1,
double delta =0.0,
int borderType = 4
)

#include "pch.h"
#include 
#include 
#include 

using namespace cv;
int main(int argc, char** argv) {
    Mat src, dst;
    src = imread("D:/girl.jpg");
    if (!src.data) {
        printf("could not load image");
    }
    char input_title[] = "input image";
    char output_title[] = "Laplaiance Result";
    namedWindow(input_title, 0);
    imshow(input_title, 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);
    namedWindow(output_title, 0);
    imshow(output_title, edge_image);

    waitKey(0);
    return 0;
}

你可能感兴趣的:(018-Opencv笔记-拉普拉斯算子)