Ask Your Question
0

Using the cuda::createMedianFilter

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

nicksoto24 gravatar image

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

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
0

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

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 https://github.com/opencv/opencv/blob...

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

Comments

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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 2,534 times

Last updated: Mar 11 '18