added support of multichannel matrices in gpu::minMax
This commit is contained in:
parent
282e01cb4a
commit
13d18d65a8
@ -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<unsigned char>(src, minVal, maxVal);
|
||||
mathfunc::min_max_caller<unsigned char>(src_, minVal, maxVal);
|
||||
break;
|
||||
case CV_8S:
|
||||
mathfunc::min_max_caller<signed char>(src, minVal, maxVal);
|
||||
mathfunc::min_max_caller<signed char>(src_, minVal, maxVal);
|
||||
break;
|
||||
case CV_16U:
|
||||
mathfunc::min_max_caller<unsigned short>(src, minVal, maxVal);
|
||||
mathfunc::min_max_caller<unsigned short>(src_, minVal, maxVal);
|
||||
break;
|
||||
case CV_16S:
|
||||
mathfunc::min_max_caller<signed short>(src, minVal, maxVal);
|
||||
mathfunc::min_max_caller<signed short>(src_, minVal, maxVal);
|
||||
break;
|
||||
case CV_32S:
|
||||
mathfunc::min_max_caller<int>(src, minVal, maxVal);
|
||||
mathfunc::min_max_caller<int>(src_, minVal, maxVal);
|
||||
break;
|
||||
case CV_32F:
|
||||
mathfunc::min_max_caller<float>(src, minVal, maxVal);
|
||||
mathfunc::min_max_caller<float>(src_, minVal, maxVal);
|
||||
break;
|
||||
case CV_64F:
|
||||
mathfunc::min_max_caller<double>(src, minVal, maxVal);
|
||||
mathfunc::min_max_caller<double>(src_, minVal, maxVal);
|
||||
break;
|
||||
default:
|
||||
CV_Error(CV_StsBadArg, "Unsupported type");
|
||||
|
@ -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<double>::max();
|
||||
maxVal = std::numeric_limits<double>::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<char>(i, j);
|
||||
char val = src_.at<char>(i, j);
|
||||
if (val < minVal) minVal = val;
|
||||
if (val > maxVal) maxVal = val;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user