Applies two Gaussian blurs to the drawable, and subtracts the results. This is robust and widely used method for detecting edges.
cv::Mat input;// source image
cv::Mat edge;// output image
cv::Mat blur1;
cv::Mat blur2;
int r1 = 1; // 奇数
int r2 = 49;// 奇数
float s1 =sqrt (-(r1 * r1) / (2 * log (1.0 / 255.0))) ;
float s2 =sqrt (-(r2 * r2) / (2 * log (1.0 / 255.0))) ;
// 两个不同半径的高斯滤波
cv::GaussianBlur(input, blur1, cv::Size(r1,r1),s1);
cv::GaussianBlur(input, blur2, cv::Size(r2,r2),s2);
//作差
cv::subtract(blur1,blur2,edge);
//反色
cv::bitwise_not(edge,edge);
Gimp 插件高斯差分边缘检测 源码:
https://github.com/piksels-and-lines-orchestra/gimp/blob/master/plug-ins/common/edge-dog.c
来源:CSDN
作者:xinyu391
链接:https://blog.csdn.net/xinyu391/article/details/103688297