open cv+C++错误及经验总结(四)

fancy-looking stuff 奇特的东西

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 .

在本章中, 我们会试着赋予这些参数random随机 的数值。 并且, 我们会试图在图像上绘制大量的几何图形. 因为我们将用随机的方式初始化这些图形, 这个过程将很自然的用到loops循环 .

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).

我们知道rng是一个随机数生成器对象。在上面的代码中我们调用了rng.uniform(a,b).这指定了一个在a和b之间的均匀分布(包含a,但不含b)。

The explanation above applies for the other functions generatingcircles, ellipses, polygones, etc. The parameters such as center and vertices are also generated randomly.

上面的解释同样适用于其它的几何图形,比如说参数center(圆心)和vertices(顶点)也是随机的。

 take into account 考虑

The compiler does not take into account the type of the variable to which you assign the result of RNG::uniform . 

编译器并没有考虑指定结果变量的类型

use explicit type cast operators使用显示类型转换符

as in the a1 initialization above.在a1初始化之前

sampled from the Gaussian distribution从高斯分布采样

standard deviation of the distribution.分布的标准差

That is, the mean value of the returned random numbers is zero and the standard deviation is the specified sigma .

返回的随机数的均值是零,随机数的标准差是sigma

saturate使充满,浸透 

monotonic英 [ˌmɒnə'tɒnɪk]  美 [ˌmɒnə'tɒnɪk]adj.单调的,无变化的

convolution英 [ˌkɒnvəˈlu:ʃn]  美 [ˌkɑnvəˈluʃən]n.回旋,盘旋,卷绕

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)

函数返回的最小值N大于等于size0,这样N维数组计算速度最快。目前的实现是N=2p×3q×5r 。如果size0的值非常大(接近整形的最大值),该函数返回一个负数。

图像变换--卷积边界(CopyMakeBorder)

CopyMakeBorder

复制图像并且制作边界。(处理边界卷积)

void cvCopyMakeBorder( const CvArr* src, CvArr* dst, CvPoint offset, int bordertype, CvScalar value=cvScalarAll(0) );
src  输入图像。 dst  输出图像。 offset 输入图像(或者其ROI)欲拷贝到的输出图像长方形的左上角坐标(或者左下角坐标,如果以左下角为原点)。长方形的尺寸要和原图像的尺寸的ROI分之一匹配。 bordertype  已拷贝的原图像长方形的边界的类型:
IPL_BORDER_CONSTANT - 填充边界为固定值,值由函数最后一个参数指定。IPL_BORDER_REPLICATE -边界用上下行或者左右列来复制填充。(其他两种IPL边界类型, IPL_BORDER_REFLECT 和IPL_BORDER_WRAP现已不支持)。
value   如果边界类型为IPL_BORDER_CONSTANT的话,那么此为边界像素的值。

函数cvCopyMakeBorder拷贝输入2维阵列到输出阵列的内部并且在拷贝区域的周围制作一个指定类型的边界。函数可以用来模拟和嵌入在指定算法实现中的边界不同的类型。例如:和opencv中大多数其他滤波函数一样,一些形态学函数内部使用复制边界类型,但是用户可能需要零边界或者填充为1或255的边界。

plain C array 纯C数组

C++: void merge(const Mat* mv, size_t count, OutputArray dst)
C++: void merge(InputArrayOfArrays mv, OutputArray dst)
Python:   cv2. merge (mv [, dst ] ) → dst
C:  void  cvMerge (const CvArr*  src0, const CvArr*  src1, const CvArr*  src2, const CvArr*  src3, CvArr*  dst )
Python:   cv. Merge (src0, src1, src2, src3, dst ) → None
Parameters:
  • 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 merge merge 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:

\texttt{dst} (I) =  \sqrt{\texttt{x}(I)^2 + \texttt{y}(I)^2}

magnitude英 [ˈmægnɪtju:d]

美 [ˈmæɡnɪˌtud, -ˌtjud]n.   

open up英 [ˈəupən ʌp]

美 [ˈopən ʌp]   

美 [vɚˈbos]adj.冗长的,啰唆的,累赘的adv.冗长地,啰唆地,累赘地

英 [kræmd]
美 [kræmd]

adj.  

v.  

relevant

生词本
去背诵
英 [ˈreləvənt]
美 [ˈrɛləvənt]

adj.   

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 ).

Mat I;
IplImage pI = I;
CvMat    mI = I;

complaints英 [kəm'pleɪnts]

美 [kəm'pleɪnts]n.   

work-around

生词本
英 [wə:k əˈraund] 美 [wɚk əˈraʊnd]

 To work around this issue in OpenCV there is introduced a sort of smart pointer.
为了绕开这一问题,OpenCV引进了一种智能指针。
Ptr<IplImage> piI = &I.operator IplImage();
Converting from the C data structures to the Mat is done by passing these inside its constructor. For example:

将C接口的数据结构转换为 Mat 时,可将其作为构造函数的参数传入,例如:

IplImage* pI


Mat K(piL), L;
L = Mat(pI);

   
   

help on

生词本
英 [help ɔn] 美 [hɛlp ɑn]

 

end up

生词本
英 [end ʌp] 美 [ɛnd ʌp]

  

color plane

生词本
英 [ˈkʌlə plein] 美 [ˈkʌlɚ plen]

mess around

生词本
英 [mes əˈraund]
美 [mɛs əˈraʊnd]

 

mess around with

生词本
英 [mes əˈraund wið] 美 [mɛs əˈraʊnd wɪð]

luma component 亮度分量
英 ['fɔ:mjələ]
美 [ˈfɔrmjələ]

n.   

weighted addition function 加权函数

a diagonal standard deviation matrix

a square matrix 方阵

vector

生词本
英 ['vektə(r)]
美 [ˈvɛktɚ]

n.   

vt. 

GaussianBlur

Blurs an image using a Gaussian filter.

C++:  void  GaussianBlur (InputArray  src, OutputArray  dst, Size  ksize, double  sigmaX, double  sigmaY=0, int  borderType=BORDER_DEFAULT  )
Python:   cv2. GaussianBlur (src, ksize, sigmaX [, dst [, sigmaY [, borderType ] ] ] ) → dst
Parameters:
  • src – input image; the image can have any number of channels, which are processed independently, but the depth should be CV_8UCV_16UCV_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 ksizesigmaX, 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.

C++:  void  randn (InputOutputArray  dst, InputArray  mean, InputArray  stddev )
Python:   cv2. randn (dst, mean, stddev ) → None
Parameters:
  • 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.

See also

 

RNGrandu()

英 [ɪn'tækt]
美 [ɪn'tækt]

adj.   

explicitly

生词本
去背诵
英 [ɪk'splɪsɪtlɪ] 美 [ɪk'splɪsɪtlɪ]

adv.

MatIterator_

MatIterator_<uchar> it = planes[0].begin<uchar>(), it_end = planes[0].end<uchar>();

addWeighted

Calculates the weighted sum of two arrays.

C++:  void  addWeighted (InputArray  src1, double  alpha, InputArray  src2, double  beta, double  gamma, OutputArray  dst, int dtype=-1 )
Python:   cv2. addWeighted (src1, alpha, src2, beta, gamma [, dst [, dtype ] ] ) → dst
C:  void  cvAddWeighted (const CvArr*  src1, double  alpha, const CvArr*  src2, double  beta, double  gamma, CvArr*  dst )
Python:   cv. AddWeighted (src1, alpha, src2, beta, gamma, dst ) → None
Parameters:
  • src1 – first input array.
  • alpha – weight of the first array elements.
  • 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:

\texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} +  \texttt{src2} (I)* \texttt{beta} +  \texttt{gamma} )

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.





 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值