added support of multichannel matrices in gpu::minMax
authorAlexey Spizhevoy <no@email>
Wed, 24 Nov 2010 09:03:37 +0000 (09:03 +0000)
committerAlexey Spizhevoy <no@email>
Wed, 24 Nov 2010 09:03:37 +0000 (09:03 +0000)
modules/gpu/src/arithm.cpp
tests/gpu/src/arithm.cpp

index b94db38..7c54719 100644 (file)
@@ -496,34 +496,34 @@ namespace cv { namespace gpu { namespace mathfunc {
 \r
 void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal)\r
 {\r
-    CV_Assert(src.channels() == 1);\r
+    GpuMat src_ = src.reshape(1);\r
 \r
     double maxVal_;\r
     if (!maxVal) \r
         maxVal = &maxVal_;\r
   \r
-    switch (src.type())\r
+    switch (src_.type())\r
     {\r
     case CV_8U:\r
-        mathfunc::min_max_caller<unsigned char>(src, minVal, maxVal);\r
+        mathfunc::min_max_caller<unsigned char>(src_, minVal, maxVal);\r
         break;\r
     case CV_8S:\r
-        mathfunc::min_max_caller<signed char>(src, minVal, maxVal);\r
+        mathfunc::min_max_caller<signed char>(src_, minVal, maxVal);\r
         break;\r
     case CV_16U:\r
-        mathfunc::min_max_caller<unsigned short>(src, minVal, maxVal);\r
+        mathfunc::min_max_caller<unsigned short>(src_, minVal, maxVal);\r
         break;\r
     case CV_16S:\r
-        mathfunc::min_max_caller<signed short>(src, minVal, maxVal);\r
+        mathfunc::min_max_caller<signed short>(src_, minVal, maxVal);\r
         break;\r
     case CV_32S:\r
-        mathfunc::min_max_caller<int>(src, minVal, maxVal);\r
+        mathfunc::min_max_caller<int>(src_, minVal, maxVal);\r
         break;\r
     case CV_32F:\r
-        mathfunc::min_max_caller<float>(src, minVal, maxVal);\r
+        mathfunc::min_max_caller<float>(src_, minVal, maxVal);\r
         break;\r
     case CV_64F:\r
-        mathfunc::min_max_caller<double>(src, minVal, maxVal);\r
+        mathfunc::min_max_caller<double>(src_, minVal, maxVal);\r
         break;\r
     default:\r
         CV_Error(CV_StsBadArg, "Unsupported type");\r
index f159d9d..f8b65ac 100644 (file)
@@ -678,22 +678,23 @@ struct CV_GpuMinMaxTest: public CvTest
 \r
     void run(int)\r
     {\r
-        for (int type = CV_8U; type <= CV_64F; ++type)\r
-        {\r
-            int rows = 1, cols = 3;\r
-            test(rows, cols, type);\r
-            for (int i = 0; i < 4; ++i)\r
+        for (int cn = 1; cn <= 4; ++cn)\r
+            for (int depth = CV_8U; depth <= CV_64F; ++depth)\r
             {\r
-                int rows = 1 + rand() % 1000;\r
-                int cols = 1 + rand() % 1000;\r
-                test(rows, cols, type);\r
+                int rows = 1, cols = 3;\r
+                test(rows, cols, cn, depth);\r
+                for (int i = 0; i < 4; ++i)\r
+                {\r
+                    int rows = 1 + rand() % 1000;\r
+                    int cols = 1 + rand() % 1000;\r
+                    test(rows, cols, cn, depth);\r
+                }\r
             }\r
-        }\r
     }\r
 \r
-    void test(int rows, int cols, int type)\r
+    void test(int rows, int cols, int cn, int depth)\r
     {\r
-        cv::Mat src(rows, cols, type);\r
+        cv::Mat src(rows, cols, CV_MAKE_TYPE(depth, cn));\r
         cv::RNG rng;\r
         for (int i = 0; i < src.rows; ++i)\r
         { \r
@@ -702,20 +703,21 @@ struct CV_GpuMinMaxTest: public CvTest
         }\r
 \r
         double minVal, maxVal;\r
-        if (type != CV_8S)\r
+        Mat src_ = src.reshape(1);\r
+        if (depth != CV_8S)\r
         {\r
             cv::Point minLoc, maxLoc;\r
-            cv::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc);\r
+            cv::minMaxLoc(src_, &minVal, &maxVal, &minLoc, &maxLoc);\r
         }\r
         else \r
         {\r
             // OpenCV's minMaxLoc doesn't support CV_8S type \r
             minVal = std::numeric_limits<double>::max();\r
             maxVal = std::numeric_limits<double>::min();\r
-            for (int i = 0; i < src.rows; ++i)\r
-                for (int j = 0; j < src.cols; ++j)\r
+            for (int i = 0; i < src_.rows; ++i)\r
+                for (int j = 0; j < src_.cols; ++j)\r
                 {\r
-                    char val = src.at<char>(i, j);\r
+                    char val = src_.at<char>(i, j);\r
                     if (val < minVal) minVal = val;\r
                     if (val > maxVal) maxVal = val;\r
                 }\r