11
16
2012
36

输出高斯分布噪声数据到文档

 本小程序是在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;
}
Category: C++ | Tags:

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com