added buffered version of norm, updated performance sample and docs
authorAlexey Spizhevoy <no@email>
Tue, 1 Feb 2011 10:46:19 +0000 (10:46 +0000)
committerAlexey Spizhevoy <no@email>
Tue, 1 Feb 2011 10:46:19 +0000 (10:46 +0000)
doc/gpu_matrix_reductions.tex
modules/gpu/include/opencv2/gpu/gpu.hpp
modules/gpu/src/matrix_reductions.cpp
samples/gpu/performance/tests.cpp

index 70b5c5f..875d751 100644 (file)
@@ -17,12 +17,19 @@ See also: \cvCppCross{meanStdDev}.
 \cvCppFunc{gpu::norm}\r
 Returns norm of matrix (or of two matrices difference).\r
 \r
-\cvdefCpp{double norm(const GpuMat\& src1, int normType=NORM\_L2);}\r
+\cvdefCpp{double norm(const GpuMat\& src, int normType=NORM\_L2);}\r
 \begin{description}\r
-\cvarg{src1}{Source matrix. Any matrices except 64F are supported.}\r
+\cvarg{src}{Source matrix. Any matrices except 64F are supported.}\r
 \cvarg{normType}{Norm type. \texttt{NORM\_L1}, \texttt{NORM\_L2} and \texttt{NORM\_INF} are supported for now.}\r
 \end{description}\r
 \r
+\cvdefCpp{double norm(const GpuMat\& src, int normType, GpuMat\& buf);}\r
+\begin{description}\r
+\cvarg{src}{Source matrix. Any matrices except 64F are supported.}\r
+\cvarg{normType}{Norm type. \texttt{NORM\_L1}, \texttt{NORM\_L2} and \texttt{NORM\_INF} are supported for now.}\r
+\cvarg{buf}{Optional buffer to avoid extra memory allocations. It's resized automatically.}\r
+\end{description}\r
+\r
 \cvdefCpp{double norm(const GpuMat\& src1, const GpuMat\& src2,\par\r
   int normType=NORM\_L2);}\r
 \begin{description}\r
index 77f2acd..df30a8c 100644 (file)
@@ -750,9 +750,14 @@ namespace cv
 \r
         //! computes norm of array\r
         //! supports NORM_INF, NORM_L1, NORM_L2\r
-        //! supports only CV_8UC1 type\r
+        //! supports all matrices except 64F\r
         CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);\r
 \r
+        //! computes norm of array\r
+        //! supports NORM_INF, NORM_L1, NORM_L2\r
+        //! supports all matrices except 64F\r
+        CV_EXPORTS double norm(const GpuMat& src1, int normType, GpuMat& buf);\r
+\r
         //! computes norm of the difference between two arrays\r
         //! supports NORM_INF, NORM_L1, NORM_L2\r
         //! supports only CV_8UC1 type\r
index 3ef13f6..f9baf66 100644 (file)
@@ -49,6 +49,7 @@ using namespace cv::gpu;
 \r
 void cv::gpu::meanStdDev(const GpuMat&, Scalar&, Scalar&) { throw_nogpu(); }\r
 double cv::gpu::norm(const GpuMat&, int) { throw_nogpu(); return 0.0; }\r
+double cv::gpu::norm(const GpuMat&, int, GpuMat&) { throw_nogpu(); return 0.0; }\r
 double cv::gpu::norm(const GpuMat&, const GpuMat&, int) { throw_nogpu(); return 0.0; }\r
 Scalar cv::gpu::sum(const GpuMat&) { throw_nogpu(); return Scalar(); }\r
 Scalar cv::gpu::sum(const GpuMat&, GpuMat&) { throw_nogpu(); return Scalar(); }\r
@@ -88,18 +89,24 @@ void cv::gpu::meanStdDev(const GpuMat& src, Scalar& mean, Scalar& stddev)
 \r
 double cv::gpu::norm(const GpuMat& src, int normType)\r
 {\r
+    GpuMat buf;\r
+    return norm(src, normType, buf);\r
+}\r
+\r
+double cv::gpu::norm(const GpuMat& src, int normType, GpuMat& buf)\r
+{\r
     GpuMat src_single_channel = src.reshape(1);\r
 \r
     if (normType == NORM_L1)\r
-        return absSum(src_single_channel)[0];\r
+        return absSum(src_single_channel, buf)[0];\r
 \r
     if (normType == NORM_L2)\r
-        return sqrt(sqrSum(src_single_channel)[0]);\r
+        return sqrt(sqrSum(src_single_channel, buf)[0]);\r
 \r
     if (normType == NORM_INF)\r
     {\r
         double min_val, max_val;\r
-        minMax(src_single_channel, &min_val, &max_val);\r
+        minMax(src_single_channel, &min_val, &max_val, GpuMat(), buf);\r
         return std::max(std::abs(min_val), std::abs(max_val));\r
     }\r
 \r
index 340d6f1..6c7b01b 100644 (file)
@@ -198,22 +198,24 @@ TEST(integral)
 TEST(norm)\r
 {\r
     Mat src;\r
-    gpu::GpuMat d_src;\r
+    gpu::GpuMat d_src, d_buf;\r
 \r
     for (int size = 1000; size <= 8000; size *= 2)\r
     {\r
-        SUBTEST << "size " << size << ", 8U";\r
+        SUBTEST << "size " << size << ", 32F";\r
 \r
-        gen(src, size, size, CV_8U, 0, 256);\r
+        gen(src, size, size, CV_32F, 0, 1);\r
 \r
         CPU_ON;\r
-        norm(src);\r
+        for (int i = 0; i < 10; ++i)\r
+            norm(src, NORM_L2);\r
         CPU_OFF;\r
 \r
         d_src = src;\r
 \r
         GPU_ON;\r
-        gpu::norm(d_src);\r
+        for (int i = 0; i < 10; ++i)\r
+            gpu::norm(d_src, NORM_L2, d_buf);\r
         GPU_OFF;\r
     }\r
 }\r