首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV中的GaussianBlur -Function是如何工作的

OpenCV中的GaussianBlur -Function是如何工作的
EN

Stack Overflow用户
提问于 2017-06-23 18:34:33
回答 1查看 621关注 0票数 0

我想问在哪里可以找到OpenCV中的高斯模糊函数是如何实现的。当查看源码时,我只能找到这个file,但我正在查找完成卷积的代码。例如,如下所示:

代码语言:javascript
复制
 for x to picture.rows
    for y to picture.cols
       for r to mask.width
         for c to mask.cols 
            do convolution

OpenCV GaussianBlur是为每个像素计算卷积,还是每隔一秒计算一次卷积来加快速度?

EN

回答 1

Stack Overflow用户

发布于 2017-06-23 18:46:14

下面是一些实现了高斯滤波器的链接,我希望它能对你有所帮助。

示例代码-

代码语言:javascript
复制
int main( int argc, char** argv )
{
    //create 2 empty windows
    namedWindow( "Original Image" , CV_WINDOW_AUTOSIZE );
    namedWindow( "Smoothed Image" , CV_WINDOW_AUTOSIZE );

    // Load an image from file
    Mat src = imread( "MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED );

    //show the loaded image
    imshow( "Original Image", src );

    Mat dst;
    char zBuffer[35];

    for ( int i = 1; i  <  31; i = i + 2 )
    {
        //copy the text to the "zBuffer"
        _snprintf_s(zBuffer, 35,"Kernel Size : %d x %d", i, i);

        //smooth the image using Gaussian kernel in the "src" and save it to "dst"
        GaussianBlur( src, dst, Size( i, i ), 0, 0 );

        //put the text in the "zBuffer" to the "dst" image
        putText( dst, zBuffer, Point( src.cols/4, src.rows/8), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255), 2 );

        //show the blurred image with the text
        imshow( "Smoothed Image", dst );

        //wait for 2 seconds
        int c = waitKey(2000);

        //if the "esc" key is pressed during the wait, return
        if (c == 27)
        {
            return 0;
        }
    }

    //make the "dst" image, black
    dst = Mat::zeros( src.size(), src.type() );

    //copy the text to the "zBuffer"
    _snprintf_s(zBuffer, 35,"Press Any Key to Exit");

    //put the text in the "zBuffer" to the "dst" image
    putText( dst, zBuffer, Point( src.cols/4,  src.rows / 2), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255) );

    //show the black image with the text
    imshow( "Smoothed Image", dst );

    //wait for a key press infinitely
    waitKey(0);

    return 0;
}

链接-

Link 1

Link2

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44719305

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档