第一种方式:
#include<iostream>
#include<opencv2\opencv.hpp>
using namespace cv;
using namespace std;
#define PI 3.1415926
double AverageRandom(double min, double max)//生成一个平均分布的随机数
{
int minInteger = (int)(min * 10000);
int maxInteger = (int)(max * 10000);
int randInteger = rand()*rand();
int diffInteger = maxInteger - minInteger;
int resultInteger = randInteger % diffInteger + minInteger;
return resultInteger / 10000.0;
}
double Normal2(double x, double y, double miu1, double miu2, Mat matrix, float detCov) //二维正态分布密度函数
{
float a = matrix.at<float>(0, 0);
float b = matrix.at<float>(0, 1);
float c = matrix.at<float>(1, 0);
float d = matrix.at<float>(1, 1);
double A = 2 * PI*detCov;
double B = a*(x - miu1)*(x - miu1) + (b + c)*(x - miu1)*(y - miu2) + d*(y - miu2)*(y - miu2);
//cout << "==" << 1.0 /