diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 488e3e984040dd5d012ba3c4bbfbf96729496b0e..591d50ade6a038c26f0ec694f6ff425dd091ccb3 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 54bb753a150b0ea4fa5bb652686622d066576de9..73dff184b52828c127e698cb749167ea0750e67b 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 3a636b255c8e01f3c43dd3001c27df533003f7c4..67b5bea2f7c76ef29375a3947cffe39452f411d2 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):