Commit 678f3925 authored by Alexey Spizhevoy's avatar Alexey Spizhevoy

added is_signed into numeric_limits_gpu, fixed incorrect min max finding for floating values

parent 6ad158db
......@@ -524,20 +524,20 @@ void cv::gpu::minMax(const GpuMat& src, double* minVal, double* maxVal, const Gp
typedef void (*Caller)(const DevMem2D, double*, double*, PtrStep);
static const Caller callers[2][7] =
{ { min_max_multipass_caller<unsigned char>, min_max_multipass_caller<signed char>,
min_max_multipass_caller<unsigned short>, min_max_multipass_caller<signed short>,
{ { min_max_multipass_caller<unsigned char>, min_max_multipass_caller<char>,
min_max_multipass_caller<unsigned short>, min_max_multipass_caller<short>,
min_max_multipass_caller<int>, min_max_multipass_caller<float>, 0 },
{ min_max_caller<unsigned char>, min_max_caller<signed char>,
min_max_caller<unsigned short>, min_max_caller<signed short>,
{ min_max_caller<unsigned char>, min_max_caller<char>,
min_max_caller<unsigned short>, min_max_caller<short>,
min_max_caller<int>, min_max_caller<float>, min_max_caller<double> } };
typedef void (*MaskedCaller)(const DevMem2D, const PtrStep, double*, double*, PtrStep);
static const MaskedCaller masked_callers[2][7] =
{ { min_max_mask_multipass_caller<unsigned char>, min_max_mask_multipass_caller<signed char>,
min_max_mask_multipass_caller<unsigned short>, min_max_mask_multipass_caller<signed short>,
{ { min_max_mask_multipass_caller<unsigned char>, min_max_mask_multipass_caller<char>,
min_max_mask_multipass_caller<unsigned short>, min_max_mask_multipass_caller<short>,
min_max_mask_multipass_caller<int>, min_max_mask_multipass_caller<float>, 0 },
{ min_max_mask_caller<unsigned char>, min_max_mask_caller<signed char>,
min_max_mask_caller<unsigned short>, min_max_mask_caller<signed short>,
{ min_max_mask_caller<unsigned char>, min_max_mask_caller<char>,
min_max_mask_caller<unsigned short>, min_max_mask_caller<short>,
min_max_mask_caller<int>, min_max_mask_caller<float>,
min_max_mask_caller<double> } };
......@@ -615,9 +615,9 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point
switch (src.type())
{
case CV_8U: min_max_loc_caller<unsigned char>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_8S: min_max_loc_caller<signed char>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_8S: min_max_loc_caller<char>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_16U: min_max_loc_caller<unsigned short>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_16S: min_max_loc_caller<signed short>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_16S: min_max_loc_caller<short>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_32S: min_max_loc_caller<int>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_32F: min_max_loc_caller<float>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_64F:
......@@ -634,9 +634,9 @@ void cv::gpu::minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point
switch (src.type())
{
case CV_8U: min_max_loc_multipass_caller<unsigned char>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_8S: min_max_loc_multipass_caller<signed char>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_8S: min_max_loc_multipass_caller<char>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_16U: min_max_loc_multipass_caller<unsigned short>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_16S: min_max_loc_multipass_caller<signed short>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_16S: min_max_loc_multipass_caller<short>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_32S: min_max_loc_multipass_caller<int>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
case CV_32F: min_max_loc_multipass_caller<float>(src, minVal, maxVal, minLoc_, maxLoc_, valbuf, locbuf); break;
default: CV_Error(CV_StsBadArg, "minMaxLoc: unsupported type");
......@@ -683,9 +683,9 @@ int cv::gpu::countNonZero(const GpuMat& src, GpuMat& buf)
switch (src.type())
{
case CV_8U: return count_non_zero_caller<unsigned char>(src, buf);
case CV_8S: return count_non_zero_caller<signed char>(src, buf);
case CV_8S: return count_non_zero_caller<char>(src, buf);
case CV_16U: return count_non_zero_caller<unsigned short>(src, buf);
case CV_16S: return count_non_zero_caller<signed short>(src, buf);
case CV_16S: return count_non_zero_caller<short>(src, buf);
case CV_32S: return count_non_zero_caller<int>(src, buf);
case CV_32F: return count_non_zero_caller<float>(src, buf);
case CV_64F:
......@@ -698,9 +698,9 @@ int cv::gpu::countNonZero(const GpuMat& src, GpuMat& buf)
switch (src.type())
{
case CV_8U: return count_non_zero_multipass_caller<unsigned char>(src, buf);
case CV_8S: return count_non_zero_multipass_caller<signed char>(src, buf);
case CV_8S: return count_non_zero_multipass_caller<char>(src, buf);
case CV_16U: return count_non_zero_multipass_caller<unsigned short>(src, buf);
case CV_16S: return count_non_zero_multipass_caller<signed short>(src, buf);
case CV_16S: return count_non_zero_multipass_caller<short>(src, buf);
case CV_32S: return count_non_zero_multipass_caller<int>(src, buf);
case CV_32F: return count_non_zero_multipass_caller<float>(src, buf);
}
......
......@@ -58,6 +58,7 @@ namespace cv
__device__ static type infinity() { return type(); }
__device__ static type quiet_NaN() { return type(); }
__device__ static type signaling_NaN() { return T(); }
static const bool is_signed;
};
template<> struct numeric_limits_gpu<bool>
......@@ -71,6 +72,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = false;
};
template<> struct numeric_limits_gpu<char>
......@@ -84,6 +86,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = (char)-1 == -1;
};
template<> struct numeric_limits_gpu<unsigned char>
......@@ -97,6 +100,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = false;
};
template<> struct numeric_limits_gpu<short>
......@@ -110,6 +114,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = true;
};
template<> struct numeric_limits_gpu<unsigned short>
......@@ -123,6 +128,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = false;
};
template<> struct numeric_limits_gpu<int>
......@@ -136,6 +142,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = true;
};
......@@ -150,6 +157,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = false;
};
template<> struct numeric_limits_gpu<long>
......@@ -163,6 +171,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = true;
};
template<> struct numeric_limits_gpu<unsigned long>
......@@ -176,6 +185,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = false;
};
template<> struct numeric_limits_gpu<float>
......@@ -189,6 +199,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = true;
};
template<> struct numeric_limits_gpu<double>
......@@ -202,6 +213,7 @@ namespace cv
__device__ static type infinity();
__device__ static type quiet_NaN();
__device__ static type signaling_NaN();
static const bool is_signed = true;
};
}
}
......
This diff is collapsed.
......@@ -701,7 +701,7 @@ struct CV_GpuMinMaxTest: public CvTest
for (int i = 0; i < src.rows; ++i)
{
Mat row(1, src.cols * src.elemSize(), CV_8U, src.ptr(i));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(255));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(256));
}
double minVal, maxVal;
......@@ -714,7 +714,7 @@ struct CV_GpuMinMaxTest: public CvTest
else
{
minVal = std::numeric_limits<double>::max();
maxVal = std::numeric_limits<double>::min();
maxVal = -std::numeric_limits<double>::max();
for (int i = 0; i < src.rows; ++i)
for (int j = 0; j < src.cols; ++j)
{
......@@ -747,7 +747,7 @@ struct CV_GpuMinMaxTest: public CvTest
for (int i = 0; i < src.rows; ++i)
{
Mat row(1, src.cols * src.elemSize(), CV_8U, src.ptr(i));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(255));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(256));
}
cv::Mat mask(src.size(), CV_8U);
......@@ -765,7 +765,7 @@ struct CV_GpuMinMaxTest: public CvTest
{
// OpenCV's minMaxLoc doesn't support CV_8S type
minVal = std::numeric_limits<double>::max();
maxVal = std::numeric_limits<double>::min();
maxVal = -std::numeric_limits<double>::max();
for (int i = 0; i < src_.rows; ++i)
for (int j = 0; j < src_.cols; ++j)
{
......@@ -826,7 +826,7 @@ struct CV_GpuMinMaxLocTest: public CvTest
for (int i = 0; i < src.rows; ++i)
{
Mat row(1, src.cols * src.elemSize(), CV_8U, src.ptr(i));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(255));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(256));
}
double minVal, maxVal;
......@@ -838,7 +838,7 @@ struct CV_GpuMinMaxLocTest: public CvTest
{
// OpenCV's minMaxLoc doesn't support CV_8S type
minVal = std::numeric_limits<double>::max();
maxVal = std::numeric_limits<double>::min();
maxVal = -std::numeric_limits<double>::max();
for (int i = 0; i < src.rows; ++i)
for (int j = 0; j < src.cols; ++j)
{
......@@ -895,7 +895,7 @@ struct CV_GpuCountNonZeroTest: CvTest
for (int i = 0; i < src.rows; ++i)
{
Mat row(1, src.cols * src.elemSize(), CV_8U, src.ptr(i));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(255));
rng.fill(row, RNG::UNIFORM, Scalar(0), Scalar(256));
}
int n_gold = cv::countNonZero(src);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment