opencv学习日记——生成边缘检测滤波器
getDerivKernels(行输出矩阵, 列输出矩阵, x方向导数的阶次, y方向导数的阶次, 滤波器大小)
getDerivKernels(sobel_x1, sobel_y1, 1, 0, 3);
举例 x方向导数的阶次为1,说明生成的矩阵有一列0,滤波器尺寸为3,就是两列数字中间加这一列0,以此类推,3的时候有3列0,所以滤波器尺寸为7.
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat sobel_x1, sobel_y1, sobelX1;
//getDerivKernels(行输出矩阵, 列输出矩阵, x方向导数的阶次, y方向导数的阶次, 滤波器大小)
getDerivKernels(sobel_x1, sobel_y1, 1, 0, 3);
sobel_x1 = sobel_x1.reshape(CV_8U, 1);
sobelX1 = sobel_y1 * sobel_x1;
cout << sobelX1 << endl;
Mat sobel_x2, sobel_y2, sobelX2;
getDerivKernels(sobel_x2, sobel_y2, 3, 0, 7);
sobel_x2 = sobel_x2.reshape(CV_8U, 1);
sobelX2 = sobel_y2 * sobel_x2;
cout << sobelX2 << endl;
}
‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’
[-1, 0, 1;
-2, 0, 2;
-1, 0, 1]
[-1, 0, 3, 0, -3, 0, 1;
-6, 0, 18, 0, -18, 0, 6;
-15, 0, 45, 0, -45, 0, 15;
-20, 0, 60, 0, -60, 0, 20;
-15, 0, 45, 0, -45, 0, 15;
-6, 0, 18, 0, -18, 0, 6;
-1, 0, 3, 0, -3, 0, 1]