Reputation: 534
While initialising the particles, i need to add some gaussian noise to it. For example
particle.x(i) = rect(1)+mgd(1,1,0,10);
here rect(1)
gives the position, and mgd function is providing the noise
The details about the mgd function are:
x=mgd(N,d,rmean,covariance)
x=mgd(N,d,mu,sigmax)
N
samples from a d-dimension
Gaussian distributionMy value of N
and d are always 1, How can I implement the mgd
function in opencv c++?
Upvotes: 1
Views: 1279
Reputation: 10850
Take a look at standard library "random", it includes methods for different distributions, including normal distribution.
In the case of uncorrelated variables, you can use independent 1D random number for each dimension (see KeillRandor's answer), otherwise it is not correct. For implementation you can look at MATLAB's code, to do it, type in script editor
mvnrnd
then right mouse click on just typed command and select open mvrnd in context menu. You'll see the MATLAB code for mvnrnd function.
Upvotes: 1
Reputation: 3858
OpenCV comes with a nice Random Number Generator class and also many useful functions. To initialize a d-dimensional vector with random gaussian noise, just do:
int d = 10; // dimension
float m = 0, cov = 0.1; // mean and covariance
vector<float> X(d,.0f); // your d-dimensional vector
cv::randn(X,m,cov); // <-
Cheers!
Upvotes: 1