Ask Your Question
0

how to use cv::cuda::Convolution::convolve in opencv?

asked 2015-12-25 12:04:39 -0600

junyan gravatar image

I would like to implement a convolution between an image and a kernel, somewhat like MATLAB conv2(img, kernel,'same'), which indicates that the result image is the same size as the original image.

Before, I use filter2d, like: filter2D(source, dest, img.depth(), kernel, anchor, 0, borderMode);

However, filter2D is a little bit slow when dealing with large images. That's why I think cv::cuda::Convolution::convolve might be a little bit faster.

I read the documentation of cv::cuda::Convolution::convolve

virtual void cv::cuda::Convolution::convolve    (   InputArray  image,
InputArray      templ,
OutputArray     result,
bool            ccorr = false,
Stream &        stream = Stream::Null() 
)

I am a little bit confused, does the word 'template image' equals to kernel? Also there seems no way to choose the size of the result image (which I would like the result image to be the same size as the original one) and border mode, unlike filter2D.

Really hope there is a cuda::filter2D version.......

So could cv::cuda::Convolution::convolve do what I want? If cv::cuda::Convolution::convolve function really can't work for my purpose, then how to use this function?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-12-25 15:45:31 -0600

Brandon212 gravatar image

updated 2015-12-25 15:47:52 -0600

You first have to construct a Convolution object using the template size you want to use (or don't and it will resize, but it will be slightly slower):

Ptr<cuda::Convolution> convolver = cuda::createConvolution(Size(11, 11));

Then you can use it on whatever image you want:

convolver->convolve(inputImg, kernel, outputImg);

It's also always the same size as the input.

edit flag offensive delete link more

Comments

Thank you for replying! And how to choose the template size? Or just using the kernel size?^_^

junyan gravatar imagejunyan ( 2015-12-25 15:52:21 -0600 )edit

Yeah that's just the kernel size

Brandon212 gravatar imageBrandon212 ( 2015-12-25 15:55:08 -0600 )edit

it is changing result image's size : "Result image. If image is W x H and templ is w x h, then result must be W-w+1 x H-h+1." how can we do some padding setup on this operation.

shadowpro67 gravatar imageshadowpro67 ( 2017-09-04 08:10:06 -0600 )edit

Anyone know how to implement this method in Python?

mhtsf gravatar imagemhtsf ( 2020-04-02 10:40:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-25 12:04:39 -0600

Seen: 2,195 times

Last updated: Dec 25 '15