看代码就差不多会了
#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.youkuaiyun.com/bella_yux/article/details/49717083