if (!ocl_sum(_src, stddev, OCL_OP_SUM_SQR, _mask))
return false;
- double total = 1.0 / (haveMask ? countNonZero(_mask) : _src.total());
+ int nz = haveMask ? countNonZero(_mask) : (int)_src.total();
+ double total = nz != 0 ? 1.0 / nz : 0;
int k, j, cn = _src.channels();
for (int i = 0; i < cn; ++i)
{
}
}
+OCL_TEST(MeanStdDev_, ZeroMask)
+{
+ Size size(5, 5);
+ UMat um(size, CV_32SC1), umask(size, CV_8UC1, Scalar::all(0));
+ Mat m(size, CV_32SC1), mask(size, CV_8UC1, Scalar::all(0));
+
+ Scalar cpu_mean, cpu_stddev;
+ Scalar gpu_mean, gpu_stddev;
+
+ OCL_OFF(cv::meanStdDev(m, cpu_mean, cpu_stddev, mask));
+ OCL_ON(cv::meanStdDev(um, gpu_mean, gpu_stddev, umask));
+
+ for (int i = 0; i < 4; ++i)
+ {
+ EXPECT_NEAR(cpu_mean[i], gpu_mean[i], 0.1);
+ EXPECT_NEAR(cpu_stddev[i], gpu_stddev[i], 0.1);
+ }
+}
+
//////////////////////////////////////// Log /////////////////////////////////////////
typedef ArithmTestBase Log;
#endif // IMPLEMENT_PARAM_CLASS
#define OCL_TEST_P TEST_P
+#define OCL_TEST_F(name, ...) typedef name OCL_##name; TEST_F(OCL_##name, __VA_ARGS__)
+#define OCL_TEST(name, ...) TEST(OCL_##name, __VA_ARGS__)
#define OCL_OFF(fn) cv::ocl::setUseOpenCL(false); fn
#define OCL_ON(fn) cv::ocl::setUseOpenCL(true); fn