Generating random numbers

Random number generation is one of the most widely used algorithms in computer vision, especially when it comes to testing an existing algorithm with random values between given ranges. When using the OpenCV library, you can use the following functions to produce values or matrices containing random values:

  • The randn function can be used to fill a matrix or an array with random numbers with a given mean value and standard deviation. Here's how this function is used:
randn(rmat, mean, stddev); 
  • The randu function, similar to the randn function, is used to fill an array with random values, however, instead of mean and standard deviation, this function uses a lower band and higher band (both inclusive) for the produced random values. Here's an example:
randu(rmat, lowBand, highBand);
  • The randShuffle function, as it can be guessed from its title, is used to randomly shuffle the contents of an array or matrix. It is used as simply as it is depicted in the following example:
randShuffle(array); 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.30.62