Commit 8461cb3f authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

refactored gpu::convolve function:

* converted it to Algorithm
* old API still can be used for source compatibility (marked as deprecated)
parent 26a4be89
......@@ -374,7 +374,23 @@ CV_EXPORTS void mulAndScaleSpectrums(InputArray src1, InputArray src2, OutputArr
//! For complex-to-real transform it is assumed that the source matrix is packed in CUFFT's format.
CV_EXPORTS void dft(InputArray src, OutputArray dst, Size dft_size, int flags=0, Stream& stream = Stream::Null());
struct CV_EXPORTS ConvolveBuf
//! computes convolution (or cross-correlation) of two images using discrete Fourier transform
//! supports source images of 32FC1 type only
//! result matrix will have 32FC1 type
class CV_EXPORTS Convolution : public Algorithm
{
public:
virtual void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr = false, Stream& stream = Stream::Null()) = 0;
};
CV_EXPORTS Ptr<Convolution> createConvolution(Size user_block_size = Size());
__OPENCV_GPUARITHM_DEPR_BEFORE__ void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr = false, Stream& stream = Stream::Null()) __OPENCV_GPUARITHM_DEPR_AFTER__;
inline void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr , Stream& stream)
{
createConvolution()->convolve(image, templ, result, ccorr, stream);
}
struct ConvolveBuf
{
Size result_size;
Size block_size;
......@@ -385,15 +401,15 @@ struct CV_EXPORTS ConvolveBuf
GpuMat image_spect, templ_spect, result_spect;
GpuMat image_block, templ_block, result_data;
void create(Size image_size, Size templ_size);
static Size estimateBlockSize(Size result_size, Size templ_size);
void create(Size, Size){}
static Size estimateBlockSize(Size, Size){ return Size(); }
};
//! computes convolution (or cross-correlation) of two images using discrete Fourier transform
//! supports source images of 32FC1 type only
//! result matrix will have 32FC1 type
CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr = false);
CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr, ConvolveBuf& buf, Stream& stream = Stream::Null());
__OPENCV_GPUARITHM_DEPR_BEFORE__ void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr, ConvolveBuf& buf, Stream& stream = Stream::Null()) __OPENCV_GPUARITHM_DEPR_AFTER__;
inline void convolve(InputArray image, InputArray templ, OutputArray result, bool ccorr, ConvolveBuf& buf, Stream& stream)
{
createConvolution(buf.user_block_size)->convolve(image, templ, result, ccorr, stream);
}
}} // namespace cv { namespace gpu {
......
......@@ -228,10 +228,11 @@ PERF_TEST_P(Sz_KernelSz_Ccorr, Convolve,
cv::gpu::GpuMat d_templ = cv::gpu::createContinuous(templ_size, templ_size, CV_32FC1);
d_templ.upload(templ);
cv::Ptr<cv::gpu::Convolution> convolution = cv::gpu::createConvolution();
cv::gpu::GpuMat dst;
cv::gpu::ConvolveBuf d_buf;
TEST_CYCLE() cv::gpu::convolve(d_image, d_templ, dst, ccorr, d_buf);
TEST_CYCLE() convolution->convolve(d_image, d_templ, dst, ccorr);
GPU_SANITY_CHECK(dst);
}
......
This diff is collapsed.
......@@ -419,8 +419,10 @@ GPU_TEST_P(Convolve, Accuracy)
cv::Mat src = randomMat(size, CV_32FC1, 0.0, 100.0);
cv::Mat kernel = randomMat(cv::Size(ksize, ksize), CV_32FC1, 0.0, 1.0);
cv::Ptr<cv::gpu::Convolution> conv = cv::gpu::createConvolution();
cv::gpu::GpuMat dst;
cv::gpu::convolve(loadMat(src), loadMat(kernel), dst, ccorr);
conv->convolve(loadMat(src), loadMat(kernel), dst, ccorr);
cv::Mat dst_gold;
convolveDFT(src, kernel, dst_gold, ccorr);
......
......@@ -172,15 +172,16 @@ namespace
return;
}
gpu::ConvolveBuf convolve_buf;
convolve_buf.user_block_size = buf.user_block_size;
Ptr<gpu::Convolution> conv = gpu::createConvolution(buf.user_block_size);
if (image.channels() == 1)
gpu::convolve(image.reshape(1), templ.reshape(1), result, true, convolve_buf, stream);
{
conv->convolve(image.reshape(1), templ.reshape(1), result, true, stream);
}
else
{
GpuMat result_;
gpu::convolve(image.reshape(1), templ.reshape(1), result_, true, convolve_buf, stream);
conv->convolve(image.reshape(1), templ.reshape(1), result_, true, stream);
extractFirstChannel_32F(result_, result, image.channels(), StreamAccessor::getStream(stream));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment