From 5fad2a3f24b6b1e41a4f6783decaf08967de5c0d Mon Sep 17 00:00:00 2001 From: wykvictor Date: Thu, 29 Dec 2016 16:46:35 +0800 Subject: [PATCH 1/2] Speedup MedianFilter::apply() when calling repeatedly Speedup MedianFilter::apply(), avoid to newly create the two GpuMat every time calling filter->apply(), which is very time consuming. --- modules/cudafilters/src/filtering.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/cudafilters/src/filtering.cpp b/modules/cudafilters/src/filtering.cpp index 21efde0103..d01504b2dd 100644 --- a/modules/cudafilters/src/filtering.cpp +++ b/modules/cudafilters/src/filtering.cpp @@ -1068,6 +1068,8 @@ namespace private: int windowSize; int partitions; + GpuMat devHist; + GpuMat devCoarseHist; }; MedianFilter::MedianFilter(int srcType, int _windowSize, int _partitions) : @@ -1098,10 +1100,13 @@ namespace // Note - these are hardcoded in the actual GPU kernel. Do not change these values. int histSize=256, histCoarseSize=8; - - BufferPool pool(_stream); - GpuMat devHist = pool.getBuffer(1, src.cols*histSize*partitions,CV_32SC1); - GpuMat devCoarseHist = pool.getBuffer(1,src.cols*histCoarseSize*partitions,CV_32SC1); + int devHistCols = src.cols*histSize*partitions, devCoarseHistCols = src.cols*histCoarseSize*partitions; + if(devHist.empty() || devCoarseHist.empty() || devHist.cols != devHistCols || devCoarseHist.cols != devCoarseHistCols) + { + BufferPool pool(_stream); + devHist = pool.getBuffer(1, devHistCols, CV_32SC1); + devCoarseHist = pool.getBuffer(1, devCoarseHistCols, CV_32SC1); + } devHist.setTo(0, _stream); devCoarseHist.setTo(0, _stream); From c6f666a02bfc30e6dff6f2687551424701e33063 Mon Sep 17 00:00:00 2001 From: Yakun Wang Date: Thu, 29 Dec 2016 18:29:44 +0800 Subject: [PATCH 2/2] BufferPool is used for temporary buffer, use mat create directly --- modules/cudafilters/src/filtering.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/cudafilters/src/filtering.cpp b/modules/cudafilters/src/filtering.cpp index d01504b2dd..1afd9cd763 100644 --- a/modules/cudafilters/src/filtering.cpp +++ b/modules/cudafilters/src/filtering.cpp @@ -1100,13 +1100,9 @@ namespace // Note - these are hardcoded in the actual GPU kernel. Do not change these values. int histSize=256, histCoarseSize=8; - int devHistCols = src.cols*histSize*partitions, devCoarseHistCols = src.cols*histCoarseSize*partitions; - if(devHist.empty() || devCoarseHist.empty() || devHist.cols != devHistCols || devCoarseHist.cols != devCoarseHistCols) - { - BufferPool pool(_stream); - devHist = pool.getBuffer(1, devHistCols, CV_32SC1); - devCoarseHist = pool.getBuffer(1, devCoarseHistCols, CV_32SC1); - } + + devHist.create(1, src.cols*histSize*partitions, CV_32SC1); + devCoarseHist.create(1, src.cols*histCoarseSize*partitions, CV_32SC1); devHist.setTo(0, _stream); devCoarseHist.setTo(0, _stream);