# How do I can create a Gaussian filter in CUDA that is larger than 32 and double type?

The following code gives an error:

OpenCV(3.4.1) Error: Assertion failed (rowFilter_ != 0) in anonymous-namespace'::SeparableLinearFilter::SeparableLinearFilter, file c:\opencv\3.4.1\opencv-3.4.1\modules\cudafilters\src\filtering.cpp, line 413

filter3 = cv::cuda::createGaussianFilter(CV_64FC1, CV_64FC1, cv::Size(1501, 1501), 250);


and the below code gives an error:

OpenCV(3.4.1) Error: Assertion failed (rowKernel_.cols > 0 && rowKernel_.cols <= 32) in anonymous-namespace'::SeparableLinearFilter::SeparableLinearFilter, file c:\opencv\3.4.1\opencv-3.4.1\modules\cudafilters\src\filtering.cpp, line 404

filter1 = cv::cuda::createGaussianFilter(CV_8UC1, CV_8UC1, cv::Size(33, 33), 15);

edit retag close merge delete

Sort by » oldest newest most voted

I've already replied to a similar question here

Basically the size can be maximum 32 due to CUDA architecture (I suppose), but you can overcome running multiple time the filter. Here it is well explained how to achieve that, and also in the wikipidea page it is written that:

Applying multiple, successive Gaussian blurs to an image has the same effect as applying a single, larger Gaussian blur, whose radius is the square root of the sum of the squares of the blur radii that were actually applied. For example, applying successive Gaussian blurs with radii of 6 and 8 gives the same results as applying a single Gaussian blur of radius 10, since sqrt(6^2 + 8^2) = 10. Because of this relationship, processing time cannot be saved by simulating a Gaussian blur with successive, smaller blurs — the time required will be at least as great as performing the single large blur.

As you can see it increase the time needed for the execution, unfortunately.

more

Thank you. So, if want to apply the filter size larger than 32 x 32 and want high efficiency, I have to write my own custom kernel for that? Now, I am using the cv::cuda::Convolution::convolution()for that. I don't know it has the same results or not.

( 2019-05-18 23:02:28 -0500 )edit

You can generate you kernel defining the own choice sigma and apply to the whole image. There is an online calculator, if you know prior the size and the sigma I suppose it could help you in speed up the process. You can find it here.

Try this:

cv::Mat kernel = (cv::Mat(33,33,CV_64F) << /*here the value that you got from the website*/);
cv::Mat result;
cv::Ptr<cuda::Convolution> conv= cuda::createConvolution(Size(33, 33));
conv->convolve(img, kernel, result);
`

Instead of feed the kernel matrix by hand is possible to create a function to compute it. I found a code in the past but I'm not able to find it again, I'm sorry. By the way, hope it helped.

( 2019-05-19 11:12:18 -0500 )edit

Official site

GitHub

Wiki

Documentation