From 64f02aa72d730fbf68b33e7b97f13fc2225889ea Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Tue, 29 Mar 2016 17:59:48 +0300 Subject: [PATCH] Backport of setRNGSeed implementation and python test randomness fix --- modules/core/include/opencv2/core/core.hpp | 3 +++ modules/core/src/rand.cpp | 5 +++++ modules/python/test/tests_common.py | 1 + 3 files changed, 9 insertions(+) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 488e3e9840..591d50ade6 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -2593,6 +2593,9 @@ CV_EXPORTS_W double kmeans( InputArray data, int K, CV_OUT InputOutputArray best //! returns the thread-local Random number generator CV_EXPORTS RNG& theRNG(); +//! sets state of the thread-local Random number generator +CV_EXPORTS_W void setRNGSeed(int seed); + //! returns the next unifomly-distributed random number of the specified type template static inline _Tp randu() { return (_Tp)theRNG(); } diff --git a/modules/core/src/rand.cpp b/modules/core/src/rand.cpp index 54bb753a15..73dff184b5 100644 --- a/modules/core/src/rand.cpp +++ b/modules/core/src/rand.cpp @@ -806,6 +806,11 @@ RNG& theRNG() } +void cv::setRNGSeed(int seed) +{ + theRNG() = RNG(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): -- GitLab