openCV(3)-随机数产生用法

看代码就差不多会了

#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/nonfree.hpp>
#include<opencv2/legacy/legacy.hpp>
#include <opencv2/opencv_lib.h>
#include <iostream>
#include <time.h>

using namespace cv;
using namespace std;

int main()
{
    Mat image(600, 600, CV_8UC3);

    RNG rng((unsigned)time(NULL));//用这种方式是系统时间作为种子初始化rng,产生随机数是变的。注意加头文件#include<time.h>
    //RNG &rng = theRNG();//这种方式产生的随机数是不变的

    double x = rng.uniform((double)0, (double)255);//产生一个0-255之间的double型数,下面两个相同理解
    float y = rng.uniform(0.f, 255.f);
    int z = rng.uniform(0, 255);
    cout << x << endl << y << endl << z <<endl;

    system("pause");
    return 0;
}

具体参考博文地址http://blog.csdn.net/bella_yux/article/details/49717083

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值