From: Vladislav Vinogradov Date: Tue, 26 Oct 2010 05:44:50 +0000 (+0000) Subject: fix unnecessary memory allocation in gpu::magnitude and gpu::phase X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~8519 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c39f0ee33a0694a3a27426acdad7bad40eb842e;p=platform%2Fupstream%2Fopencv.git fix unnecessary memory allocation in gpu::magnitude and gpu::phase --- diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index 1146de4..6640290 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -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 diff --git a/modules/gpu/src/arithm.cpp b/modules/gpu/src/arithm.cpp index b507cc6..db118d0 100644 --- a/modules/gpu/src/arithm.cpp +++ b/modules/gpu/src/arithm.cpp @@ -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) diff --git a/tests/gpu/src/arithm.cpp b/tests/gpu/src/arithm.cpp index ddc2276..dd7a0a4 100644 --- a/tests/gpu/src/arithm.cpp +++ b/tests/gpu/src/arithm.cpp @@ -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); }