Skip to content

Commit ce6b06e

Browse files
committed
Merge pull request opencv#9203 from tomoaki0705:eliminateRandFromTest
2 parents f01c029 + e63d628 commit ce6b06e

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

modules/calib3d/test/test_undistort_points.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@ CV_UndistortTest::~CV_UndistortTest() {}
2929

3030
void CV_UndistortTest::generate3DPointCloud(vector<Point3f>& points, Point3f pmin, Point3f pmax)
3131
{
32-
const Point3f delta = pmax - pmin;
32+
RNG rng_Point = ::theRNG(); // fix the seed to use "fixed" input 3D points
3333
for (size_t i = 0; i < points.size(); i++)
3434
{
35-
Point3f p(float(rand()) / RAND_MAX, float(rand()) / RAND_MAX,
36-
float(rand()) / RAND_MAX);
37-
p.x *= delta.x;
38-
p.y *= delta.y;
39-
p.z *= delta.z;
40-
p = p + pmin;
41-
points[i] = p;
35+
float _x = rng_Point.uniform(pmin.x, pmax.x);
36+
float _y = rng_Point.uniform(pmin.y, pmax.y);
37+
float _z = rng_Point.uniform(pmin.z, pmax.z);
38+
points[i] = Point3f(_x, _y, _z);
4239
}
4340
}
4441
void CV_UndistortTest::generateCameraMatrix(Mat& cameraMatrix)

modules/core/test/test_eigen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ bool Core_EigenTest::check_full(int type)
389389
{
390390
const int MAX_DEGREE = 7;
391391

392-
srand((unsigned int)time(0));
392+
RNG rng = ::theRNG(); // fix the seed
393393

394394
for (int i = 0; i < ntests; ++i)
395395
{
396-
int src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE)+1.));
396+
int src_size = (int)(std::pow(2.0, (rng.uniform(0, MAX_DEGREE) + 1.)));
397397

398398
cv::Mat src(src_size, src_size, type);
399399

modules/core/test/test_ippasync.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,6 @@ PARAM_TEST_CASE(IPPAsyncShared, Channels, hppAccelType)
110110

111111
sts = hppQueryMatrixAllocParams(accel, (hpp32u)(matrix_Size.width*cn), (hpp32u)matrix_Size.height, HPP_DATA_TYPE_8U, &pitch, &size);
112112

113-
if (pitch!=0 && size!=0)
114-
{
115-
uchar *pData = (uchar*)_aligned_malloc(size, 4096);
116-
117-
for (int j=0; j<matrix_Size.height; j++)
118-
for(int i=0; i<matrix_Size.width*cn; i++)
119-
pData[i+j*pitch] = rand()%upValue;
120-
121-
matrix = Mat(matrix_Size.height, matrix_Size.width, type, pData, pitch);
122-
}
123-
124113
matrix = randomMat(matrix_Size, type, 0, upValue);
125114
}
126115

modules/dnn/test/test_halide_layers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,11 @@ TEST_P(Eltwise, Accuracy)
612612
eltwiseParam.set("operation", op);
613613
if (op == "sum" && weighted)
614614
{
615+
RNG rng = cv::theRNG();
615616
std::vector<float> coeff(1 + numConv);
616617
for (int i = 0; i < coeff.size(); ++i)
617618
{
618-
coeff[i] = ((float)rand() / RAND_MAX) * 4 - 2;
619+
coeff[i] = rng.uniform(-2.0f, 2.0f);
619620
}
620621
eltwiseParam.set("coeff", DictValue::arrayReal<float*>(&coeff[0], coeff.size()));
621622
}

modules/photo/test/test_hdr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ TEST(Photo_AlignMTB, regression)
141141
int errors = 0;
142142

143143
Ptr<AlignMTB> align = createAlignMTB(max_bits);
144+
RNG rng = ::theRNG();
144145

145146
for(int i = 0; i < TESTS_COUNT; i++) {
146-
Point shift(rand() % max_shift, rand() % max_shift);
147+
Point shift(rng.uniform(0, max_shift), rng.uniform(0, max_shift));
147148
Mat res;
148149
align->shiftMat(img, res, shift);
149150
Point calc = align->calculateShift(img, res);

0 commit comments

Comments
 (0)