opencv::卷积运算函数filter2D()
使用掩模板矩阵(kernel)计算每个像素值

与原图相比,没有黑边

 

int main(int argc, char** argv) {

    Mat srcImage = imread(STRPAHT2);

    //判断图像是否加载成功
    if (srcImage.data)
        cout << "图像加载成功!" << endl << endl;
    else
    {
        cout << "图像加载失败!" << endl << endl;
        return -1;
    }
    namedWindow("srcImage", WINDOW_AUTOSIZE);
    imshow("srcImage", srcImage);

    Mat kern = (Mat_<char>(3, 3) << 0, -1, 0,
                                    -1, 5, -1,
                                    0, -1, 0);
    Mat dstImage;
    filter2D(srcImage, dstImage, srcImage.depth(), kern);
    namedWindow("dstImage", WINDOW_AUTOSIZE);
    imshow("dstImage", dstImage);

    waitKey(0);
}