[opencv] 123/251: remove some rand functions * make test more reproducible
Nobuhiro Iwamatsu
iwamatsu at moszumanska.debian.org
Sun Aug 27 23:27:34 UTC 2017
This is an automated email from the git hooks/post-receive script.
iwamatsu pushed a commit to annotated tag 3.3.0
in repository opencv.
commit e63d628677c3762f626555f47d6d9f99316e362d
Author: Tomoaki Teshima <tomoaki.teshima at gmail.com>
Date: Thu Jul 20 22:43:11 2017 +0900
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<Point3f>& 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<matrix_Size.height; j++)
- for(int i=0; i<matrix_Size.width*cn; i++)
- pData[i+j*pitch] = rand()%upValue;
-
- matrix = Mat(matrix_Size.height, matrix_Size.width, type, pData, pitch);
- }
-
matrix = randomMat(matrix_Size, type, 0, upValue);
}
diff --git a/modules/dnn/test/test_halide_layers.cpp b/modules/dnn/test/test_halide_layers.cpp
index 6801a7c..f3dd2bf 100644
--- a/modules/dnn/test/test_halide_layers.cpp
+++ b/modules/dnn/test/test_halide_layers.cpp
@@ -612,10 +612,11 @@ TEST_P(Eltwise, Accuracy)
eltwiseParam.set("operation", op);
if (op == "sum" && weighted)
{
+ RNG rng = cv::theRNG();
std::vector<float> 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<float*>(&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<AlignMTB> 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);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/opencv.git
More information about the debian-science-commits
mailing list