// cv::Mat myGetGaussianKernel(int ksize, double sigma, int ktype = CV_64F) { double constE = 2.718281828459045; cv::Mat mat(ksize, ksize, ktype); for (int iRow = 0; iRow < ksize; iRow++) { for (int iCol = 0; iCol < ksize; iCol++) { double val = -(pow((iCol - (ksize - 1) / 2), 2) + pow((iRow - (ksize - 1) / 2), 2)); val = val / (2 * sigma * sigma); double elementVal = pow(constE, val); mat.at<double>(iCol, iRow) = elementVal / (2 * CV_PI * sigma * sigma); } } return mat; }