隨機數發生器類 (RNG) 並得到均勻分佈的隨機數。
- RNG::RNG()
- RNG::RNG(uint64 state)
-
RNG constructors
These are the RNG constructors. The first form sets the state to some pre-defined value, equal to 2**32-1 in the current implementation. The second form sets the state to the specified value. If the user passed state=0 , the constructor uses the above default value instead, to avoid the singular random number sequence, consisting of all zeros.Parameter: state – the 64-bit value used to initialize the RNG -
-
- unsigned RNG::next()
- Returns the next random number,The method updates the state using MWC algorithm and returns the next 32-bit random number.
-
Returns the next random number sampled from the uniform distribution
Parameters: - a – The lower inclusive boundary of the returned random numbers
- b – The upper non-inclusive boundary of the returned random numbers
- double RNG::gaussian(double sigma)
-
Returns the next random number sampled from the Gaussian distribution
Parameter: sigma – The standard deviation of the distribution - void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, intlineType=8, bool bottomLeftOrigin=false)¶
-
Draws a text string
Parameters: - img – The image
- text – The text string to be drawn
- org – The bottom-left corner of the text string in the image
- fontFace –
The font type, one of FONT_HERSHEY_SIMPLEX , FONT_HERSHEY_PLAIN ,FONT_HERSHEY_DUPLEX , FONT_HERSHEY_COMPLEX , FONT_HERSHEY_TRIPLEX ,FONT_HERSHEY_COMPLEX_SMALL , FONT_HERSHEY_SCRIPT_SIMPLEX orFONT_HERSHEY_SCRIPT_COMPLEX ,
where each of the font id’s can be combined with FONT_HERSHEY_ITALIC to get the slanted letters.
- fontScale – The font scale factor that is multiplied by the font-specific base size
- color – The text color
- thickness – Thickness of the lines used to draw the text
- lineType – The line type; see line for details
- bottomLeftOrigin – When true, the image data origin is at the bottom-left corner, otherwise it’s at the top-left corner
putText( image, "Testing text rendering", org, rng.uniform(0,8), rng.uniform(0,100)*0.05+0.1, randomColor(rng), rng.uniform(1, 10), lineType);
函數 putText 都做了些什麼?在我們的例子中:
- 在 image 上繪製文字 “Testing text rendering” 。
- 文字的左下角將用點 org 指定。
- 字體參數是用一個在 之間的整數來定義。
- 字體的縮放比例是用表達式 rng.uniform(0, 100)x0.05 + 0.1 指定(表示它的範圍是 )。
- 字體的顏色是隨機的 (記爲 randomColor(rng))。
- 字體的粗細範圍是從 1 到 10, 表示爲 rng.uniform(1,10) 。