From e63d628677c3762f626555f47d6d9f99316e362d Mon Sep 17 00:00:00 2001 From: Tomoaki Teshima Date: Thu, 20 Jul 2017 22:43:11 +0900 Subject: [PATCH] remove some rand functions * make test more reproducible --- modules/calib3d/test/test_undistort_points.cpp | 13 +++++-------- modules/core/test/test_eigen.cpp | 4 ++-- modules/core/test/test_ippasync.cpp | 11 ----------- modules/dnn/test/test_halide_layers.cpp | 3 ++- modules/photo/test/test_hdr.cpp | 3 ++- 5 files changed, 11 insertions(+), 23 deletions(-) diff --git a/modules/calib3d/test/test_undistort_points.cpp b/modules/calib3d/test/test_undistort_points.cpp index 0eb3552..51600ae 100644 --- a/modules/calib3d/test/test_undistort_points.cpp +++ b/modules/calib3d/test/test_undistort_points.cpp @@ -29,16 +29,13 @@ CV_UndistortTest::~CV_UndistortTest() {} void CV_UndistortTest::generate3DPointCloud(vector& points, Point3f pmin, Point3f pmax) { - const Point3f delta = pmax - pmin; + RNG rng_Point = ::theRNG(); // fix the seed to use "fixed" input 3D points for (size_t i = 0; i < points.size(); i++) { - Point3f p(float(rand()) / RAND_MAX, float(rand()) / RAND_MAX, - float(rand()) / RAND_MAX); - p.x *= delta.x; - p.y *= delta.y; - p.z *= delta.z; - p = p + pmin; - points[i] = p; + float _x = rng_Point.uniform(pmin.x, pmax.x); + float _y = rng_Point.uniform(pmin.y, pmax.y); + float _z = rng_Point.uniform(pmin.z, pmax.z); + points[i] = Point3f(_x, _y, _z); } } void CV_UndistortTest::generateCameraMatrix(Mat& cameraMatrix) diff --git a/modules/core/test/test_eigen.cpp b/modules/core/test/test_eigen.cpp index 6a9e99e..bd51c74 100644 --- a/modules/core/test/test_eigen.cpp +++ b/modules/core/test/test_eigen.cpp @@ -389,11 +389,11 @@ bool Core_EigenTest::check_full(int type) { const int MAX_DEGREE = 7; - srand((unsigned int)time(0)); + RNG rng = ::theRNG(); // fix the seed for (int i = 0; i < ntests; ++i) { - int src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE)+1.)); + int src_size = (int)(std::pow(2.0, (rng.uniform(0, MAX_DEGREE) + 1.))); cv::Mat src(src_size, src_size, type); diff --git a/modules/core/test/test_ippasync.cpp b/modules/core/test/test_ippasync.cpp index 5ba9f60..5069a81 100644 --- a/modules/core/test/test_ippasync.cpp +++ b/modules/core/test/test_ippasync.cpp @@ -110,17 +110,6 @@ PARAM_TEST_CASE(IPPAsyncShared, Channels, hppAccelType) sts = hppQueryMatrixAllocParams(accel, (hpp32u)(matrix_Size.width*cn), (hpp32u)matrix_Size.height, HPP_DATA_TYPE_8U, &pitch, &size); - if (pitch!=0 && size!=0) - { - uchar *pData = (uchar*)_aligned_malloc(size, 4096); - - for (int j=0; j coeff(1 + numConv); for (int i = 0; i < coeff.size(); ++i) { - coeff[i] = ((float)rand() / RAND_MAX) * 4 - 2; + coeff[i] = rng.uniform(-2.0f, 2.0f); } eltwiseParam.set("coeff", DictValue::arrayReal(&coeff[0], coeff.size())); } diff --git a/modules/photo/test/test_hdr.cpp b/modules/photo/test/test_hdr.cpp index 705eb04..d1e1bb5 100644 --- a/modules/photo/test/test_hdr.cpp +++ b/modules/photo/test/test_hdr.cpp @@ -141,9 +141,10 @@ TEST(Photo_AlignMTB, regression) int errors = 0; Ptr align = createAlignMTB(max_bits); + RNG rng = ::theRNG(); for(int i = 0; i < TESTS_COUNT; i++) { - Point shift(rand() % max_shift, rand() % max_shift); + Point shift(rng.uniform(0, max_shift), rng.uniform(0, max_shift)); Mat res; align->shiftMat(img, res, shift); Point calc = align->calculateShift(img, res); -- 2.7.4