fix unnecessary memory allocation in gpu::magnitude and gpu::phase

pull/13383/head
Vladislav Vinogradov 14 years ago
parent d0a4352eae
commit 2c39f0ee33
  1. 2
      modules/gpu/include/opencv2/gpu/gpu.hpp
  2. 28
      modules/gpu/src/arithm.cpp
  3. 4
      tests/gpu/src/arithm.cpp

@ -557,7 +557,7 @@ namespace cv
//! computes the integral image and integral for the squared image
//! sum will have CV_32S type, sqsum - CV32F type
//! supports only CV_32FC1 source type
//! supports only CV_8UC1 source type
CV_EXPORTS void integral(GpuMat& src, GpuMat& sum, GpuMat& sqsum);
//! computes the standard deviation of integral images

@ -660,18 +660,20 @@ namespace cv { namespace gpu { namespace mathfunc
namespace
{
inline void cartToPolar_caller(const GpuMat& x, const GpuMat& y, GpuMat& mag, bool magSqr, GpuMat& angle, bool angleInDegrees, cudaStream_t stream)
inline void cartToPolar_caller(const GpuMat& x, const GpuMat& y, GpuMat* mag, bool magSqr, GpuMat* angle, bool angleInDegrees, cudaStream_t stream)
{
CV_DbgAssert(x.size() == y.size() && x.type() == y.type());
CV_Assert(x.depth() == CV_32F);
mag.create(x.size(), x.type());
angle.create(x.size(), x.type());
if (mag)
mag->create(x.size(), x.type());
if (angle)
angle->create(x.size(), x.type());
GpuMat x1cn = x.reshape(1);
GpuMat y1cn = y.reshape(1);
GpuMat mag1cn = mag.reshape(1);
GpuMat angle1cn = angle.reshape(1);
GpuMat mag1cn = mag ? mag->reshape(1) : GpuMat();
GpuMat angle1cn = angle ? angle->reshape(1) : GpuMat();
mathfunc::cartToPolar_gpu(x1cn, y1cn, mag1cn, magSqr, angle1cn, angleInDegrees, stream);
}
@ -695,42 +697,42 @@ namespace
void cv::gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& dst)
{
::cartToPolar_caller(x, y, dst, false, GpuMat(), false, 0);
::cartToPolar_caller(x, y, &dst, false, 0, false, 0);
}
void cv::gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& dst, const Stream& stream)
{
::cartToPolar_caller(x, y, dst, false, GpuMat(), false, StreamAccessor::getStream(stream));
::cartToPolar_caller(x, y, &dst, false, 0, false, StreamAccessor::getStream(stream));
}
void cv::gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& dst)
{
::cartToPolar_caller(x, y, dst, true, GpuMat(), false, 0);
::cartToPolar_caller(x, y, &dst, true, 0, false, 0);
}
void cv::gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& dst, const Stream& stream)
{
::cartToPolar_caller(x, y, dst, true, GpuMat(), false, StreamAccessor::getStream(stream));
::cartToPolar_caller(x, y, &dst, true, 0, false, StreamAccessor::getStream(stream));
}
void cv::gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees)
{
::cartToPolar_caller(x, y, GpuMat(), false, angle, angleInDegrees, 0);
::cartToPolar_caller(x, y, 0, false, &angle, angleInDegrees, 0);
}
void cv::gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, const Stream& stream)
{
::cartToPolar_caller(x, y, GpuMat(), false, angle, angleInDegrees, StreamAccessor::getStream(stream));
::cartToPolar_caller(x, y, 0, false, &angle, angleInDegrees, StreamAccessor::getStream(stream));
}
void cv::gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& mag, GpuMat& angle, bool angleInDegrees)
{
::cartToPolar_caller(x, y, mag, false, angle, angleInDegrees, 0);
::cartToPolar_caller(x, y, &mag, false, &angle, angleInDegrees, 0);
}
void cv::gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& mag, GpuMat& angle, bool angleInDegrees, const Stream& stream)
{
::cartToPolar_caller(x, y, mag, false, angle, angleInDegrees, StreamAccessor::getStream(stream));
::cartToPolar_caller(x, y, &mag, false, &angle, angleInDegrees, StreamAccessor::getStream(stream));
}
void cv::gpu::polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees)

@ -620,12 +620,12 @@ struct CV_GpuNppImagePhaseTest : public CV_GpuArithmTest
}
cv::Mat cpuRes;
cv::phase(mat1, mat2, cpuRes);
cv::phase(mat1, mat2, cpuRes, true);
GpuMat gpu1(mat1);
GpuMat gpu2(mat2);
GpuMat gpuRes;
cv::gpu::phase(gpu1, gpu2, gpuRes);
cv::gpu::phase(gpu1, gpu2, gpuRes, true);
return CheckNorm(cpuRes, gpuRes);
}

Loading…
Cancel
Save