RNG随机类
来源:互联网 发布:英雄联盟t恤淘宝 编辑:程序博客网 时间:2024/04/29 21:53
转载自:http://blog.csdn.net/longwinyang/article/details/52934843
本文主要讲解随机数生成器RNG。在opencv中我们有时要随机生成一些数值,用于图像的边缘。
RNG::uniform
int RNG::(int a,int b)
float RNG::uniform(float a,float b)
double RNG::uniform(double a,double b)
随机类RNG:计算机的伪随机数是由随机种子根据一定的计算方法计算出来的数值,所以只要计算方法一定,随机种子一定,那么产生的随机数就是固定的。
RNG rng(12345)
opencv 里RNG类构造函数初始化为固定值后,随机种子也是固定的,所以在相同的平台环境下,编译后每次运行它,显示的随机数是一样的。
例如:
#include<iostream>
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
RNG rng(12345);
int main(void)
{
for (int i = 0; i < 10; i++) {
int a = rng.uniform(1, 100);
cout << a << endl;
}
return 0;
}
只要平台不变,每次生成的都是:
6
33
12
54
71
65
94
11
64
76
请按任意键继续. . .
如果想改变成随机生成的数,使用下面的方法:
#include<iostream>
#include <opencv2/highgui/highgui.hpp>
#include <ctime>
using namespace cv;
using namespace std;
RNG rng((unsigned)time(NULL));
int main(void)
{
for (int i = 0; i < 10; i++) {
int a = rng.uniform(1, 100);
cout << a << endl;
}
return 0;
}
第一次结果:
76
79
3
3
83
2
34
65
97
9
请按任意键继续. . .
第二次结果:
35
46
76
52
32
68
69
42
49
91
请按任意键继续. . .
- RNG随机类
- OpenCV之随机类RNG
- 随机产生线性模型的线条 利用RNG的类
- RNG类
- OpenCV学习入门(四):RNG 伪随机问题
- OpenCV之RNG生成随机数类详解
- opencv 画随机线条 ---tutorial里面有例子,同时了解了RNG
- 随机数字生成器(RNG)和Hash函数组合武器背后的黑暗秘密
- opencv RNG
- rng.uniform
- OpenCV自带例子(六)随机数类RNG使用与窗口文本输出方法
- OpenCV学习之八:RNG类 随机数生成函数的使用
- OpenCV学习笔记(3):点集的最小外接矩形/圆,RNG类
- 用OpenCV的RNG类为图像添加高斯噪声
- CC2430 RNG改进
- opencv函数之RNG
- Opencv中RNG
- (转)随机数产生器RNG
- priority_queue用法
- 12月学习计划
- spark shell启动警告 Unable to load native-hadoop library for your platform
- HDU 5438拓扑+bfs或者dfs
- 自己实践
- RNG随机类
- PAT Basic 1028
- MySQL的binlog日志
- 字典序(头条校招java)
- Windows免安装版 zip包 安装 配置教程 noinstall版
- ~!北京赛車五六码走势技巧~@#%
- Programming dynamic ALV in WebDynpro for ABAP
- 【Scikit-Learn 中文文档】交叉验证
- 均方误差、平方差、方差、均方差、协方差