From abad2ca76c5e3de98df36cc3ad708d805555656d Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 18 Oct 2016 16:53:37 +0300 Subject: [PATCH] test: fix tolerance cv::rand result is not bitexact for floating-point numbers --- modules/core/perf/perf_convertTo.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/core/perf/perf_convertTo.cpp b/modules/core/perf/perf_convertTo.cpp index 8007361..3738e32 100644 --- a/modules/core/perf/perf_convertTo.cpp +++ b/modules/core/perf/perf_convertTo.cpp @@ -26,12 +26,16 @@ PERF_TEST_P( Size_DepthSrc_DepthDst_Channels_alpha, convertTo, int channels = get<3>(GetParam()); double alpha = get<4>(GetParam()); + int maxValue = 255; + Mat src(sz, CV_MAKETYPE(depthSrc, channels)); - randu(src, 0, 255); + randu(src, 0, maxValue); Mat dst(sz, CV_MAKETYPE(depthDst, channels)); int runs = (sz.width <= 640) ? 8 : 1; TEST_CYCLE_MULTIRUN(runs) src.convertTo(dst, depthDst, alpha); - SANITY_CHECK(dst, alpha == 1.0 ? 1e-12 : 1e-7); + double eps = depthSrc <= CV_32S ? 1e-12 : (FLT_EPSILON * maxValue); + eps = eps * std::max(1.0, fabs(alpha)); + SANITY_CHECK(dst, eps); } -- 2.7.4