1.Random generator and text with OpenCV随机数发生器&绘制文字
In this tutorial, we intend to userandom valuesfor the drawing parameters. Also, we intend topopulate our image with a big number of geometric figures. Since we will be initializing them in a random fashion, this process will beautomaticand made by usingloops .
Let’s start by checking out the main function. We observe that first thing we do is creating aRandom Number Generator object (RNG):
让我们检视 main 函数。我们发现第一步是实例化一个 Random Number Generator(随机数发生器对象)(RNG):
defined as functions: 正如函数定义的那样
extreme英 [ɪk'stri:m]美[ɪkˈstrim]adj.n.
The line extremes are given by pt1 and pt2.For pt1 we can see that:
线段的端点分别是pt1 ,pt2,对于pt1我们看到:
We know that rng is a Random number generator object.In the codeabove we are calling rng.uniform(a,b). This generates a randomly uniformed distributionbetween the values a and b(inclusive in a, exclusive b).
The explanation above applies for the other functions generatingcircles, ellipses, polygones, etc. The parameters such as center and vertices are also generated randomly.
GetOptimalDFTSize 对于给定的矢量尺寸返回最优DFT尺寸 int cvGetOptimalDFTSize( int size0 ); size0 矢量长度. 函数 cvGetOptimalDFTSize 返回最小值 N that is greater to equal to size0, such that DFT of a vector of size N can be computed fast.
In the current implementation N=2p×3q×5r for some p, q, r. The function returns a negative number if size0 is too large (very close to INT_MAX)
mv – input array or vector of matrices to be merged; all the matrices in mv must have the same size and the same depth.
count – number of input matrices when mv is a plain C array; it must be greater than zero.
dst – output array of the same size and the same depth as mv[0]; The number of channels will be the total number of channels in the matrix array.
The functions mergemerge several arrays to make a single multi-channel array. That is, each element of the output array will be a concatenation of the elements of the input arrays, where elements of i-th input array are treated as mv[i].channels()-element vectors.
concatenation英 [kənˌkætəˈneɪʃn] n.一系列相互关联的事物
array cross-correlationor convolution this technique is very useful for calculating array cross-correlation or convolution using DFT.
DFT这种技术对于计算数组相关性和卷积非常有用。
logarithmic英 [ˌlɒɡə'rɪðmɪk]
美 [ˌlɒɡə'rɪðmɪk]
adj.
C++:void
magnitude
(InputArray
x, InputArray
y, OutputArray
magnitude
)
Python:cv2.magnitude
(x, y
[,
magnitude]
) → magnitude
Parameters:
x – floating-point array of x-coordinates of the vectors.
y – floating-point array of y-coordinates of the vectors; it must have the same size as x.
magnitude – output array of the same size and type as x.
The function magnitude calculates the magnitude of 2D vectors formed from the corresponding elements of x and y arrays:
Because the functions are already in a namespace there is no need for them to contain the cv prefix in their name. As such all the new C++ compatible functions don’t have this and they follow the camel case naming rule. This means the first letter is small (unless it’s a name, like Canny) and the subsequent words start with a capital letter (like copyMakeBorder).
src – input image; the image can have any number of channels, which are processed independently, but the depth should be CV_8U, CV_16U, CV_16S,CV_32F or CV_64F.
dst – output image of the same size and type as src.
ksize – Gaussian kernel size. ksize.width and ksize.height can differ but they both must be positive and odd. Or, they can be zero’s and then they are computed from sigma* .
sigmaX – Gaussian kernel standard deviation in X direction.
sigmaY – Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height , respectively (seegetGaussianKernel() for details); to fully control the result regardless of possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.
borderType – pixel extrapolation method (see borderInterpolate() for details).
The function convolves the source image with the specified Gaussian kernel. In-place filtering is supported.
rrandn
Fills the array with normally distributed random numbers.
dst – output array of random numbers; the array must be pre-allocated and have 1 to 4 channels.
mean – mean value (expectation) of the generated random numbers.
stddev – standard deviation of the generated random numbers; it can be either a vector (in which case a diagonal standard deviation matrix is assumed) or a square matrix.
The function randn fills the matrix dst with normally distributed random numbers with the specified mean vector and the standard deviation matrix. The generated random numbers are clipped to fit the value range of the output array data type.
src2 – second input array of the same size and channel number as src1.
beta – weight of the second array elements.
dst – output array that has the same size and number of channels as the input arrays.
gamma – scalar added to each sum.
dtype – optional depth of the output array; when both input arrays have the same depth, dtype can be set to-1, which will be equivalent to src1.depth().
The function addWeighted calculates the weighted sum of two arrays as follows:
where I is a multi-dimensional index of array elements. In case of multi-channel arrays, each channel is processed independently.
The function can be replaced with a matrix expression:
dst=src1*alpha+src2*beta+gamma;
Note
Saturation is not applied when the output array has the depth CV_32S. You may even get result of an incorrect sign in the case of overflow.