本小程序是在VS2008和OpenCV的平台下编写的,产生高斯噪声并且输出到txt文件。
// GaussianTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <fstream> //注意这个是输出到文件上用到的头文件
#include "opencv.hpp" //opencv库
//#include "opencv.h"
//#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std; //用到的命名空间
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
//opencv利用时间为种子产生高斯随机数,注意在产生同一批数据时,种子不能变
RNG rng;
rng(getTickCount());
double data = 0,Sigma = 1;
ofstream ofs("D:\\test.txt");//打开或创建test.txt
for (int i = 0;i < 1000;i++)
{
data = rng.gaussian(sqrt(Sigma));
ofs<<data<<endl;
}
ofs.close();
return 0;
}