From a490b64e9b252476b88955ab0e77fa2aa1cdb48c Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Fri, 25 Mar 2016 16:17:58 +0300 Subject: [PATCH 1/3] Add function setRNGSeed and seed setup in python tests --- modules/core/include/opencv2/core.hpp | 8 ++++++++ modules/core/src/rand.cpp | 6 ++++++ modules/python/test/tests_common.py | 1 + 3 files changed, 15 insertions(+) diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 2e47658f73..beeace53bb 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -2170,6 +2170,14 @@ is much faster to use this function to retrieve the generator and then use RNG:: */ CV_EXPORTS RNG& theRNG(); +/** @brief Sets state of default random number generator. + +The function sets state of default random number generator to custom value. +@param new state for default random number generator +@sa RNG, randu, randn +*/ +CV_EXPORTS_W void setRNGSeed(int seed); + /** @brief Generates a single uniformly-distributed random number or an array of random numbers. Non-template variant of the function fills the matrix dst with uniformly-distributed diff --git a/modules/core/src/rand.cpp b/modules/core/src/rand.cpp index 9d95243828..c985fac5a3 100644 --- a/modules/core/src/rand.cpp +++ b/modules/core/src/rand.cpp @@ -734,6 +734,12 @@ cv::RNG& cv::theRNG() return getCoreTlsData().get()->rng; } +void cv::setRNGSeed(int seed) +{ + getCoreTlsData().get()->rng.state = static_cast(seed); +} + + void cv::randu(InputOutputArray dst, InputArray low, InputArray high) { theRNG().fill(dst, RNG::UNIFORM, low, high); diff --git a/modules/python/test/tests_common.py b/modules/python/test/tests_common.py index 3a636b255c..67b5bea2f7 100644 --- a/modules/python/test/tests_common.py +++ b/modules/python/test/tests_common.py @@ -42,6 +42,7 @@ class NewOpenCVTests(unittest.TestCase): return self.image_cache[filename] def setUp(self): + cv2.setRNGSeed(10) self.image_cache = {} def hashimg(self, im): From 362d52a3cbcf407eb8896f32b43ae3fb6baedf44 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Fri, 25 Mar 2016 16:34:45 +0300 Subject: [PATCH 2/3] Fix doxygen warnings --- modules/core/include/opencv2/core.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index beeace53bb..2b5a5ed85e 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -2173,7 +2173,7 @@ CV_EXPORTS RNG& theRNG(); /** @brief Sets state of default random number generator. The function sets state of default random number generator to custom value. -@param new state for default random number generator +@param seed new state for default random number generator @sa RNG, randu, randn */ CV_EXPORTS_W void setRNGSeed(int seed); From 72ed4173dfbe1a2c87dacfd138c13381c13ac8d1 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Tue, 29 Mar 2016 10:54:42 +0300 Subject: [PATCH 3/3] Change setRNGSeed implementaion --- modules/core/src/rand.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/rand.cpp b/modules/core/src/rand.cpp index c985fac5a3..9bfc91d931 100644 --- a/modules/core/src/rand.cpp +++ b/modules/core/src/rand.cpp @@ -736,7 +736,7 @@ cv::RNG& cv::theRNG() void cv::setRNGSeed(int seed) { - getCoreTlsData().get()->rng.state = static_cast(seed); + theRNG() = RNG(static_cast(seed)); }