Ask Your Question

Using the cuda::createMedianFilter

asked 2018-03-08 19:01:38 -0500

nicksoto24 gravatar image

updated 2018-03-11 01:16:02 -0500

Hey guys, so I've used the median blur for the CPU and I wanted to see how long it takes for it to complete on the GPU using cuda.

I know there's cv::medianBlur but there's also a cv::cuda::createMedianFilter and I put the only working int srcTyp (CV_8UC1) and the next parameter is the window size. How exactly should I specify the window size and how do I actually get the filter to be applied onto the photo that I want to use. I don't exactly know how to get the filter to really be applied to said image.

Any help is appreciated! Thank you.C:\fakepath\medianfilterfunction.png

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-03-09 06:43:42 -0500

Hi, For examples of how to use the CUDA API your best bet is to check out the code used in the performance tests. For example the median filter performance test is line 384 onward

The lines of code taken from the above which I think you are interested in are

const int kernel = 3;
const cv::cuda::GpuMat d_src(src);
cv::cuda::GpuMat dst;
cv::Ptr<cv::cuda::Filter> median = cv::cuda::createMedianFilter(d_src.type(), kernel);
median->apply(d_src, dst);

where the window size would be 3 in this example.

edit flag offensive delete link more


OpenCV(3.4.1-dev) Error: Assertion failed (srcType == (((0) & ((1 << 3) - 1)) + (((1)-1) << 3))) in `anonymous-namespace'::MedianFilter::MedianFilter, file C:\OpenCV Directories\opencv-master\modules\cudafilters\src\filtering.cpp, line 1077. I seem to be getting this error but not sure what might be the cause of this. I've edited my comment so that it shows the code for my function as well. Thank you again for your help!

nicksoto24 gravatar imagenicksoto24 ( 2018-03-11 01:17:28 -0500 )edit

It looks like you are using a 3 channel image by calling imread with the following flag CV_LOAD_IMAGE_COLOR If the filter algorithm only processes single channel images you need to call imread with CV_LOAD_IMAGE_GRAYSCALE

cudawarped gravatar imagecudawarped ( 2018-03-11 12:53:57 -0500 )edit

Question Tools

1 follower


Asked: 2018-03-08 19:01:38 -0500

Seen: 1,242 times

Last updated: Mar 11 '18