LoginSignup
1
1

More than 5 years have passed since last update.

OpenCVで乱数生成する (cv::RNG)

Last updated at Posted at 2015-07-17

OpenCVで乱数を生成する (cv::RNG)

乱数の生成はstdやboostでも行うことはできるが,OpenCVでも可能.
一様乱数,正規分布の2つであれば,cv::RNGを用いることで簡単に生成ができる.詳しくは公式ドキュメントを参照.


cv::RNG rng(GetTickCount());//乱数生成器を初期化.引数はSeed(ここでは時刻を与えるGetTickCount()[要windows.h]を用いる).
for(auto i=0; i<100; i++)
{
    double rand_uni = rng.uniform(double(0), double(1));//値の範囲を指定.
    double rand_gau = rng.gaussian(1.0); //標準偏差を指定.

    std::cout << "Uniform: " << rand_uni << std::endl 
              << "Gaussian: " << rand_gau << std::endl; 
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1