cv::RNG是OpenCV中提供的随机数发生器,
随机种子可以用 time(0) 或 cvGetTickCount() 来获取。
举个例子:
#include <opencv2/highgui/highgui.hpp>
int main (int argc, char** argv)
{
//初始化随机种子
//cv::RNG rng(cvGetTickCount());
cv::RNG rng(time(0));
cv::Mat image1(500,500,CV_8UC3,cv::Scalar(rng.uniform(0,255),rng.uniform(0,255),rng.uniform(0,255)));
cv::namedWindow("image 1");
imshow("image 1", image1);
cv::Mat image2(500,500,CV_32FC3,cv::Scalar(rng.uniform(0.0,1.0),rng.uniform(0.0,1.0),rng.uniform(0.0,1.0)));
cv::namedWindow("image 2");
imshow("image 2", image2);
cv::waitKey();
return 0;
}