From 13d18d65a84991144da0ba707382e1c985f42208 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Wed, 24 Nov 2010 09:03:37 +0000 Subject: [PATCH] added support of multichannel matrices in gpu::minMax --- modules/gpu/src/arithm.cpp | 18 +++++++++--------- tests/gpu/src/arithm.cpp | 34 ++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/modules/gpu/src/arithm.cpp b/modules/gpu/src/arithm.cpp index b94db38..7c54719 100644 --- a/modules/gpu/src/arithm.cpp +++ b/modules/gpu/src/arithm.cpp @@ -496,34 +496,34 @@ namespace cv { namespace gpu { namespace mathfunc { void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal) { - CV_Assert(src.channels() == 1); + GpuMat src_ = src.reshape(1); double maxVal_; if (!maxVal) maxVal = &maxVal_; - switch (src.type()) + switch (src_.type()) { case CV_8U: - mathfunc::min_max_caller(src, minVal, maxVal); + mathfunc::min_max_caller(src_, minVal, maxVal); break; case CV_8S: - mathfunc::min_max_caller(src, minVal, maxVal); + mathfunc::min_max_caller(src_, minVal, maxVal); break; case CV_16U: - mathfunc::min_max_caller(src, minVal, maxVal); + mathfunc::min_max_caller(src_, minVal, maxVal); break; case CV_16S: - mathfunc::min_max_caller(src, minVal, maxVal); + mathfunc::min_max_caller(src_, minVal, maxVal); break; case CV_32S: - mathfunc::min_max_caller(src, minVal, maxVal); + mathfunc::min_max_caller(src_, minVal, maxVal); break; case CV_32F: - mathfunc::min_max_caller(src, minVal, maxVal); + mathfunc::min_max_caller(src_, minVal, maxVal); break; case CV_64F: - mathfunc::min_max_caller(src, minVal, maxVal); + mathfunc::min_max_caller(src_, minVal, maxVal); break; default: CV_Error(CV_StsBadArg, "Unsupported type"); diff --git a/tests/gpu/src/arithm.cpp b/tests/gpu/src/arithm.cpp index f159d9d..f8b65ac 100644 --- a/tests/gpu/src/arithm.cpp +++ b/tests/gpu/src/arithm.cpp @@ -678,22 +678,23 @@ struct CV_GpuMinMaxTest: public CvTest void run(int) { - for (int type = CV_8U; type <= CV_64F; ++type) - { - int rows = 1, cols = 3; - test(rows, cols, type); - for (int i = 0; i < 4; ++i) + for (int cn = 1; cn <= 4; ++cn) + for (int depth = CV_8U; depth <= CV_64F; ++depth) { - int rows = 1 + rand() % 1000; - int cols = 1 + rand() % 1000; - test(rows, cols, type); + int rows = 1, cols = 3; + test(rows, cols, cn, depth); + for (int i = 0; i < 4; ++i) + { + int rows = 1 + rand() % 1000; + int cols = 1 + rand() % 1000; + test(rows, cols, cn, depth); + } } - } } - void test(int rows, int cols, int type) + void test(int rows, int cols, int cn, int depth) { - cv::Mat src(rows, cols, type); + cv::Mat src(rows, cols, CV_MAKE_TYPE(depth, cn)); cv::RNG rng; for (int i = 0; i < src.rows; ++i) { @@ -702,20 +703,21 @@ struct CV_GpuMinMaxTest: public CvTest } double minVal, maxVal; - if (type != CV_8S) + Mat src_ = src.reshape(1); + if (depth != CV_8S) { cv::Point minLoc, maxLoc; - cv::minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc); + cv::minMaxLoc(src_, &minVal, &maxVal, &minLoc, &maxLoc); } else { // OpenCV's minMaxLoc doesn't support CV_8S type minVal = std::numeric_limits::max(); maxVal = std::numeric_limits::min(); - for (int i = 0; i < src.rows; ++i) - for (int j = 0; j < src.cols; ++j) + for (int i = 0; i < src_.rows; ++i) + for (int j = 0; j < src_.cols; ++j) { - char val = src.at(i, j); + char val = src_.at(i, j); if (val < minVal) minVal = val; if (val > maxVal) maxVal = val; } -- 2.7.4