OpenCV has a randn () function , as well as an RNG class. Below is the Matlab code that you might want to replace, and the equivalent OpenCV code.
Matlab:
matrix2xN = randn(2,N)
OpenCV:
cv::Mat mean = cv::Mat::zeros(1,1,CV_64FC1); cv::Mat sigma= cv::Mat::ones(1,1,CV_64FC1); cv::RNG rng(optional_seed); cv::Mat matrix2xN(2,N,CV_64FC1); rng.fill(matrix2xN, cv::RNG::NORMAL, mean, sigma);
or
cv::Mat mean = cv::Mat::zeros(1,1,CV_64FC1); cv::Mat sigma= cv::Mat::ones(1,1,CV_64FC1); cv::randn(matrix2xN, mean, sigma);
Internally, OpenCV implements randn() using RNG . The downside to using randn() is that you lose control of the seed.
If matrix2xN above had more than one channel, then for each channel a different average / sigma is used. In this case, you will need to increase the number of rows (or columns) on average and sigma to match the number of channels in the 2xN matrix.
source share