opencv3.0随机数问题

来源:互联网 发布:如花照片软件 编辑:程序博客网 时间:2024/06/08 09:44

opencv3.0生成随机数的办法和旧版本有所不同

1.生成一个普通的随机数(这个是在源码中抠出来的)

    //@code{.cpp}    RNG rng;    // always produces 0    double a = rng.uniform(0, 1);    // produces double from [0, 1)    double a1 = rng.uniform((double)0, (double)1);    // produces float from [0, 1)    double b = rng.uniform(0.f, 1.f);    // produces double from [0, 1)    double c = rng.uniform(0., 1.);    // may cause compiler error because of ambiguity:    //  RNG::uniform(0, (int)0.999999)? or RNG::uniform((double)0, 0.99999)?    double d = rng.uniform(0, 0.999999);

2.用随机数填充一个矩阵,用到以下这个函数

//其中distType可以是RNG::NORMAL(正态分布)或者RNG::UNIFORM(均匀分布)//RNG::UNIFORM(均匀分布)时,参数a,b分别是分布的范围//RNG::NORMAL(正态分布)时,参数a,b分别是均值和方差void fill( InputOutputArray mat, int distType, InputArray a, InputArray b, bool saturateRange = false );
RNG rng;Mat kalman;rng.fill(kalman,RNG::UNIFORM,0,0.1);

总结:有空还是看看源码,没坏处!

0 0
原创粉丝点击