Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to seed randn function opencv

I want to seed randn function but I'm not able to do it.

srand(time(NULL));
Mat mymat = Mat::zeroes(1024,1024,CV_32F);
randn(mymat,0,1); 

Should it not give me random mat, named mymat, whose mean = 0, and variance = 1? However, it gives the same mymat in every run.

Here is the link for randn which claims srand to work.

I tried to give different numbers instead of time(NULL), but all have the same output randoms. I have checked the same thing from another machine, it gives the same output with the first machine. So seeding is not working.

Thanks,

like image 365
smttsp Avatar asked Jan 29 '14 13:01

smttsp


1 Answers

You can set seed for OpenCV functions using using the following snippet:

cv::theRNG().state = seed;

There is a subtlety for multithreaded programs - OpenCV uses thread-local random number generators so you need (re)set seed from the same thread.

like image 137
Andrey Kamaev Avatar answered Nov 14 '22 20:11

Andrey Kamaev