Ask Your Question
0

Pyramid Laplace Cuda

asked 2016-03-30 09:24:42 -0500

mau gravatar image

updated 2016-03-30 10:17:31 -0500

Hi guys, I'm trying to use laplacianPyramid with cuda, I found this implementation from modules:

    void createLaplacePyrGpu(const Mat &img, int levels, vector<Mat> &pyr)
{
 #ifdef HAVE_OPENCV_GPU

    pyr.resize(levels + 1);

    vector<cuda::GpuMat> gpu_pyr(levels + 1);

    gpu_pyr[0].upload(img);
    for (int i = 0; i < levels; ++i){
        cuda::pyrDown(gpu_pyr[i], gpu_pyr[i + 1]);
    }


    cuda::GpuMat tmp,tmp2;
    for (int i = 0; i < levels; ++i)
    {
        cuda::pyrUp(gpu_pyr[i + 1], tmp);

        cuda::subtract(gpu_pyr[i], tmp, gpu_pyr[i]);

        gpu_pyr[i].download(pyr[i]);
    }

    gpu_pyr[levels].download(pyr[levels]);
#else
    (void)img;
    (void)levels;
    (void)pyr;
#endif
}

With an input image of 960x1080 pixels, at the last iteration of the second for, the function subtract fails, because the two GpuMat are differents.

In the example code, the input image "img", was came from a cv::copyMakeBorder, but I don't get how to build the image with borders for to avoid the error?

Any help?

Thanks for your time.

Mau

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-04-04 02:22:13 -0500

mau gravatar image

updated 2016-04-04 02:23:20 -0500

I answer myself, this works:

int dx = ((1 << levels) - width % (1 << levels)) % (1 << levels);
int dy = ((1 << levels) - height % (1 << levels)) % (1 << levels);

border_top = dy;
border_left = dx;
border_bottom = 0;
border_right = 0;

cv::copyMakeBorder(img, img_with_border1, border_top, border_bottom, border_left, border_right, BORDER_REFLECT);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-03-30 09:24:42 -0500

Seen: 378 times

Last updated: Apr 04 '16