|
|
@ -77,7 +77,9 @@ void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, int, int, int) { throw_n |
|
|
|
void cv::gpu::mulSpectrums(const GpuMat&, const GpuMat&, GpuMat&, int, bool) { throw_nogpu(); } |
|
|
|
void cv::gpu::mulSpectrums(const GpuMat&, const GpuMat&, GpuMat&, int, bool) { throw_nogpu(); } |
|
|
|
void cv::gpu::mulAndScaleSpectrums(const GpuMat&, const GpuMat&, GpuMat&, int, float, bool) { throw_nogpu(); } |
|
|
|
void cv::gpu::mulAndScaleSpectrums(const GpuMat&, const GpuMat&, GpuMat&, int, float, bool) { throw_nogpu(); } |
|
|
|
void cv::gpu::dft(const GpuMat&, GpuMat&, Size, int) { throw_nogpu(); } |
|
|
|
void cv::gpu::dft(const GpuMat&, GpuMat&, Size, int) { throw_nogpu(); } |
|
|
|
|
|
|
|
void cv::gpu::ConvolveBuf::create(Size, Size) { throw_nogpu(); } |
|
|
|
void cv::gpu::convolve(const GpuMat&, const GpuMat&, GpuMat&, bool) { throw_nogpu(); } |
|
|
|
void cv::gpu::convolve(const GpuMat&, const GpuMat&, GpuMat&, bool) { throw_nogpu(); } |
|
|
|
|
|
|
|
void cv::gpu::convolve(const GpuMat&, const GpuMat&, GpuMat&, bool, ConvolveBuf&) { throw_nogpu(); } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#else /* !defined (HAVE_CUDA) */ |
|
|
|
#else /* !defined (HAVE_CUDA) */ |
|
|
@ -1211,36 +1213,65 @@ void cv::gpu::dft(const GpuMat& src, GpuMat& dst, Size dft_size, int flags) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// crossCorr
|
|
|
|
// convolve
|
|
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
|
|
|
|
|
|
|
void cv::gpu::ConvolveBuf::create(Size image_size, Size templ_size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Estimates optimal block size
|
|
|
|
result_size = Size(image_size.width - templ_size.width + 1, |
|
|
|
void convolveOptBlockSize(int w, int h, int tw, int th, int& bw, int& bh) |
|
|
|
image_size.height - templ_size.height + 1); |
|
|
|
|
|
|
|
block_size = estimateBlockSize(result_size, templ_size); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dft_size.width = getOptimalDFTSize(block_size.width + templ_size.width - 1); |
|
|
|
|
|
|
|
dft_size.height = getOptimalDFTSize(block_size.width + templ_size.height - 1); |
|
|
|
|
|
|
|
createContinuous(dft_size, CV_32F, image_block); |
|
|
|
|
|
|
|
createContinuous(dft_size, CV_32F, templ_block); |
|
|
|
|
|
|
|
createContinuous(dft_size, CV_32F, result_data); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spect_len = dft_size.height * (dft_size.width / 2 + 1); |
|
|
|
|
|
|
|
createContinuous(1, spect_len, CV_32FC2, image_spect); |
|
|
|
|
|
|
|
createContinuous(1, spect_len, CV_32FC2, templ_spect); |
|
|
|
|
|
|
|
createContinuous(1, spect_len, CV_32FC2, result_spect); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block_size.width = std::min(dft_size.width - templ_size.width + 1, result_size.width); |
|
|
|
|
|
|
|
block_size.height = std::min(dft_size.height - templ_size.height + 1, result_size.height); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Size cv::gpu::ConvolveBuf::estimateBlockSize(Size result_size, Size templ_size) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int major, minor; |
|
|
|
int major, minor; |
|
|
|
getComputeCapability(getDevice(), major, minor); |
|
|
|
getComputeCapability(getDevice(), major, minor); |
|
|
|
|
|
|
|
|
|
|
|
int scale = 40; |
|
|
|
int scale = 40; |
|
|
|
int bh_min = 1024; |
|
|
|
Size bsize_min(1024, 1024); |
|
|
|
int bw_min = 1024; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check whether we use Fermi generation or newer GPU
|
|
|
|
// Check whether we use Fermi generation or newer GPU
|
|
|
|
if (major >= 2)
|
|
|
|
if (major >= 2)
|
|
|
|
{ |
|
|
|
{ |
|
|
|
bh_min = 2048; |
|
|
|
bsize_min.width = 2048; |
|
|
|
bw_min = 2048; |
|
|
|
bsize_min.height = 2048; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bw = std::max(tw * scale, bw_min); |
|
|
|
Size bsize(std::max(templ_size.width * scale, bsize_min.width), |
|
|
|
bh = std::max(th * scale, bh_min); |
|
|
|
std::max(templ_size.height * scale, bsize_min.height)); |
|
|
|
bw = std::min(bw, w); |
|
|
|
|
|
|
|
bh = std::min(bh, h); |
|
|
|
bsize.width = std::min(bsize.width, result_size.width); |
|
|
|
|
|
|
|
bsize.height = std::min(bsize.height, result_size.height); |
|
|
|
|
|
|
|
return bsize; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result,
|
|
|
|
|
|
|
|
bool ccorr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ConvolveBuf buf; |
|
|
|
|
|
|
|
convolve(image, templ, result, ccorr, buf); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr) |
|
|
|
void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result,
|
|
|
|
|
|
|
|
bool ccorr, ConvolveBuf& buf) |
|
|
|
{ |
|
|
|
{ |
|
|
|
StaticAssert<sizeof(float) == sizeof(cufftReal)>::check(); |
|
|
|
StaticAssert<sizeof(float) == sizeof(cufftReal)>::check(); |
|
|
|
StaticAssert<sizeof(float) * 2 == sizeof(cufftComplex)>::check(); |
|
|
|
StaticAssert<sizeof(float) * 2 == sizeof(cufftComplex)>::check(); |
|
|
@ -1248,32 +1279,25 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, |
|
|
|
CV_Assert(image.type() == CV_32F); |
|
|
|
CV_Assert(image.type() == CV_32F); |
|
|
|
CV_Assert(templ.type() == CV_32F); |
|
|
|
CV_Assert(templ.type() == CV_32F); |
|
|
|
|
|
|
|
|
|
|
|
result.create(image.rows - templ.rows + 1, image.cols - templ.cols + 1, CV_32F); |
|
|
|
buf.create(image.size(), templ.size()); |
|
|
|
|
|
|
|
result.create(buf.result_size, CV_32F); |
|
|
|
Size block_size; |
|
|
|
|
|
|
|
convolveOptBlockSize(result.cols, result.rows, templ.cols, templ.rows,
|
|
|
|
|
|
|
|
block_size.width, block_size.height); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Size dft_size; |
|
|
|
Size& block_size = buf.block_size; |
|
|
|
dft_size.width = getOptimalDFTSize(block_size.width + templ.cols - 1); |
|
|
|
Size& dft_size = buf.dft_size; |
|
|
|
dft_size.height = getOptimalDFTSize(block_size.width + templ.rows - 1); |
|
|
|
int& spect_len = buf.spect_len; |
|
|
|
|
|
|
|
|
|
|
|
block_size.width = std::min(dft_size.width - templ.cols + 1, result.cols); |
|
|
|
GpuMat& image_block = buf.image_block; |
|
|
|
block_size.height = std::min(dft_size.height - templ.rows + 1, result.rows); |
|
|
|
GpuMat& templ_block = buf.templ_block; |
|
|
|
|
|
|
|
GpuMat& result_data = buf.result_data; |
|
|
|
|
|
|
|
|
|
|
|
int spect_len = dft_size.height * (dft_size.width / 2 + 1); |
|
|
|
GpuMat& image_spect = buf.image_spect; |
|
|
|
GpuMat image_spect = createContinuous(1, spect_len, CV_32FC2); |
|
|
|
GpuMat& templ_spect = buf.templ_spect; |
|
|
|
GpuMat templ_spect = createContinuous(1, spect_len, CV_32FC2); |
|
|
|
GpuMat& result_spect = buf.result_spect; |
|
|
|
GpuMat result_spect = createContinuous(1, spect_len, CV_32FC2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cufftHandle planR2C, planC2R; |
|
|
|
cufftHandle planR2C, planC2R; |
|
|
|
cufftSafeCall(cufftPlan2d(&planC2R, dft_size.height, dft_size.width, CUFFT_C2R)); |
|
|
|
cufftSafeCall(cufftPlan2d(&planC2R, dft_size.height, dft_size.width, CUFFT_C2R)); |
|
|
|
cufftSafeCall(cufftPlan2d(&planR2C, dft_size.height, dft_size.width, CUFFT_R2C)); |
|
|
|
cufftSafeCall(cufftPlan2d(&planR2C, dft_size.height, dft_size.width, CUFFT_R2C)); |
|
|
|
|
|
|
|
|
|
|
|
GpuMat image_block = createContinuous(dft_size, CV_32F); |
|
|
|
|
|
|
|
GpuMat templ_block = createContinuous(dft_size, CV_32F); |
|
|
|
|
|
|
|
GpuMat result_data = createContinuous(dft_size, CV_32F); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GpuMat templ_roi(templ.size(), CV_32F, templ.data, templ.step); |
|
|
|
GpuMat templ_roi(templ.size(), CV_32F, templ.data, templ.step); |
|
|
|
copyMakeBorder(templ_roi, templ_block, 0, templ_block.rows - templ_roi.rows, 0,
|
|
|
|
copyMakeBorder(templ_roi, templ_block, 0, templ_block.rows - templ_roi.rows, 0,
|
|
|
|
templ_block.cols - templ_roi.cols, 0); |
|
|
|
templ_block.cols - templ_roi.cols, 0); |
|
|
@ -1288,9 +1312,10 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, |
|
|
|
{ |
|
|
|
{ |
|
|
|
Size image_roi_size(std::min(x + dft_size.width, image.cols) - x, |
|
|
|
Size image_roi_size(std::min(x + dft_size.width, image.cols) - x, |
|
|
|
std::min(y + dft_size.height, image.rows) - y); |
|
|
|
std::min(y + dft_size.height, image.rows) - y); |
|
|
|
GpuMat image_roi(image_roi_size, CV_32F, (void*)(image.ptr<float>(y) + x), image.step); |
|
|
|
GpuMat image_roi(image_roi_size, CV_32F, (void*)(image.ptr<float>(y) + x),
|
|
|
|
copyMakeBorder(image_roi, image_block, 0, image_block.rows - image_roi.rows, 0,
|
|
|
|
image.step); |
|
|
|
image_block.cols - image_roi.cols, 0); |
|
|
|
copyMakeBorder(image_roi, image_block, 0, image_block.rows - image_roi.rows, |
|
|
|
|
|
|
|
0, image_block.cols - image_roi.cols, 0); |
|
|
|
|
|
|
|
|
|
|
|
cufftSafeCall(cufftExecR2C(planR2C, image_block.ptr<cufftReal>(),
|
|
|
|
cufftSafeCall(cufftExecR2C(planR2C, image_block.ptr<cufftReal>(),
|
|
|
|
image_spect.ptr<cufftComplex>())); |
|
|
|
image_spect.ptr<cufftComplex>())); |
|
|
@ -1301,8 +1326,10 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, |
|
|
|
|
|
|
|
|
|
|
|
Size result_roi_size(std::min(x + block_size.width, result.cols) - x, |
|
|
|
Size result_roi_size(std::min(x + block_size.width, result.cols) - x, |
|
|
|
std::min(y + block_size.height, result.rows) - y); |
|
|
|
std::min(y + block_size.height, result.rows) - y); |
|
|
|
GpuMat result_roi(result_roi_size, result.type(), (void*)(result.ptr<float>(y) + x), result.step); |
|
|
|
GpuMat result_roi(result_roi_size, result.type(),
|
|
|
|
GpuMat result_block(result_roi_size, result_data.type(), result_data.ptr(), result_data.step); |
|
|
|
(void*)(result.ptr<float>(y) + x), result.step); |
|
|
|
|
|
|
|
GpuMat result_block(result_roi_size, result_data.type(),
|
|
|
|
|
|
|
|
result_data.ptr(), result_data.step); |
|
|
|
result_block.copyTo(result_roi); |
|
|
|
result_block.copyTo(result_roi); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|