fix unnecessary memory allocation in gpu::magnitude and gpu::phase
authorVladislav Vinogradov <no@email>
Tue, 26 Oct 2010 05:44:50 +0000 (05:44 +0000)
committerVladislav Vinogradov <no@email>
Tue, 26 Oct 2010 05:44:50 +0000 (05:44 +0000)
modules/gpu/include/opencv2/gpu/gpu.hpp
modules/gpu/src/arithm.cpp
tests/gpu/src/arithm.cpp

index 1146de4..6640290 100644 (file)
@@ -557,7 +557,7 @@ namespace cv
         \r
         //! computes the integral image and integral for the squared image\r
         //! sum will have CV_32S type, sqsum - CV32F type\r
-        //! supports only CV_32FC1 source type\r
+        //! supports only CV_8UC1 source type\r
         CV_EXPORTS void integral(GpuMat& src, GpuMat& sum, GpuMat& sqsum);\r
 \r
         //! computes the standard deviation of integral images\r
index b507cc6..db118d0 100644 (file)
@@ -660,18 +660,20 @@ namespace cv { namespace gpu { namespace mathfunc
 \r
 namespace\r
 {\r
-    inline void cartToPolar_caller(const GpuMat& x, const GpuMat& y, GpuMat& mag, bool magSqr, GpuMat& angle, bool angleInDegrees, cudaStream_t stream)\r
+    inline void cartToPolar_caller(const GpuMat& x, const GpuMat& y, GpuMat* mag, bool magSqr, GpuMat* angle, bool angleInDegrees, cudaStream_t stream)\r
     {\r
         CV_DbgAssert(x.size() == y.size() && x.type() == y.type());\r
         CV_Assert(x.depth() == CV_32F);\r
 \r
-        mag.create(x.size(), x.type());\r
-        angle.create(x.size(), x.type());\r
+        if (mag)\r
+            mag->create(x.size(), x.type());\r
+        if (angle)\r
+            angle->create(x.size(), x.type());\r
 \r
         GpuMat x1cn = x.reshape(1);\r
         GpuMat y1cn = y.reshape(1);\r
-        GpuMat mag1cn = mag.reshape(1);\r
-        GpuMat angle1cn = angle.reshape(1);\r
+        GpuMat mag1cn = mag ? mag->reshape(1) : GpuMat();\r
+        GpuMat angle1cn = angle ? angle->reshape(1) : GpuMat();\r
 \r
         mathfunc::cartToPolar_gpu(x1cn, y1cn, mag1cn, magSqr, angle1cn, angleInDegrees, stream);\r
     }\r
@@ -695,42 +697,42 @@ namespace
 \r
 void cv::gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& dst)\r
 {\r
-    ::cartToPolar_caller(x, y, dst, false, GpuMat(), false, 0);\r
+    ::cartToPolar_caller(x, y, &dst, false, 0, false, 0);\r
 }\r
 \r
 void cv::gpu::magnitude(const GpuMat& x, const GpuMat& y, GpuMat& dst, const Stream& stream)\r
 {\r
-    ::cartToPolar_caller(x, y, dst, false, GpuMat(), false, StreamAccessor::getStream(stream));\r
+    ::cartToPolar_caller(x, y, &dst, false, 0, false, StreamAccessor::getStream(stream));\r
 }\r
 \r
 void cv::gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& dst)\r
 {\r
-    ::cartToPolar_caller(x, y, dst, true, GpuMat(), false, 0);\r
+    ::cartToPolar_caller(x, y, &dst, true, 0, false, 0);\r
 }\r
 \r
 void cv::gpu::magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& dst, const Stream& stream)\r
 {\r
-    ::cartToPolar_caller(x, y, dst, true, GpuMat(), false, StreamAccessor::getStream(stream));\r
+    ::cartToPolar_caller(x, y, &dst, true, 0, false, StreamAccessor::getStream(stream));\r
 }\r
 \r
 void cv::gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees)\r
 {\r
-    ::cartToPolar_caller(x, y, GpuMat(), false, angle, angleInDegrees, 0);\r
+    ::cartToPolar_caller(x, y, 0, false, &angle, angleInDegrees, 0);\r
 }\r
 \r
 void cv::gpu::phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, const Stream& stream)\r
 {   \r
-    ::cartToPolar_caller(x, y, GpuMat(), false, angle, angleInDegrees, StreamAccessor::getStream(stream));\r
+    ::cartToPolar_caller(x, y, 0, false, &angle, angleInDegrees, StreamAccessor::getStream(stream));\r
 }\r
 \r
 void cv::gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& mag, GpuMat& angle, bool angleInDegrees)\r
 {\r
-    ::cartToPolar_caller(x, y, mag, false, angle, angleInDegrees, 0);\r
+    ::cartToPolar_caller(x, y, &mag, false, &angle, angleInDegrees, 0);\r
 }\r
 \r
 void cv::gpu::cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& mag, GpuMat& angle, bool angleInDegrees, const Stream& stream)\r
 {\r
-    ::cartToPolar_caller(x, y, mag, false, angle, angleInDegrees, StreamAccessor::getStream(stream));\r
+    ::cartToPolar_caller(x, y, &mag, false, &angle, angleInDegrees, StreamAccessor::getStream(stream));\r
 }\r
 \r
 void cv::gpu::polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees)\r
index ddc2276..dd7a0a4 100644 (file)
@@ -620,12 +620,12 @@ struct CV_GpuNppImagePhaseTest : public CV_GpuArithmTest
         }\r
 \r
         cv::Mat cpuRes;\r
-        cv::phase(mat1, mat2, cpuRes);\r
+        cv::phase(mat1, mat2, cpuRes, true);\r
 \r
         GpuMat gpu1(mat1);\r
         GpuMat gpu2(mat2);\r
         GpuMat gpuRes;\r
-        cv::gpu::phase(gpu1, gpu2, gpuRes);\r
+        cv::gpu::phase(gpu1, gpu2, gpuRes, true);\r
 \r
         return CheckNorm(cpuRes, gpuRes);\r
     }\r