您的位置:首页 > 编程语言 > C语言/C++

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

2014-02-20 17:39 381 查看
fancy-looking stuff 奇特的东西1.Random generator andtext with OpenCV随机数发生器&绘制文字In this tutorial, we intend to userandom valuesfor the drawing parameters. Also, we intend topopulate ourimage 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 randomlyuniformed 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 initializationabove.在a1初始化之前sampled from the Gaussian distribution从高斯分布采样standard deviation of the distribution.分布的标准差Thatis, the mean value of the returned random numbers is zero and the standard deviation is the specified sigma .返回的随机数的均值是零,随机数的标准差是sigmasaturate使充满,浸透

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(constMat* mv, size_t count, OutputArray dst)C++: void merge(InputArrayOfArrays mv,OutputArray dst)Python: cv2.merge(mv[,dst]) → dstC: void cvMerge(constCvArr* 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 musthave 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 severalarrays to make a single multi-channel array.That is, each element of the output array will be a concatenationof the elements of the input arrays, where elements of i-th input array are treated as mv[i].channels()-elementvectors.concatenation英 [kənˌkætəˈneɪʃn]n.一系列相互关联的事物array cross-correlationorconvolution 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 of2D vectors formed from the corresponding elements of x and y arrays:

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

[ˈmæɡnɪˌtud, -ˌtjud]n.巨大,广大; 重大,重要; 量级; (地震)级数

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

[ˈopən ʌp]开发; 打开; <非正>开门; 切开

verbose 英 [vəˈbəʊs]

[vɚˈbos]adj.冗长的,啰唆的,累赘的adv.冗长地,啰唆地,累赘地Interoperability with open cv1与open cv1同时使用

crammed

生词本去背诵[kræmd][kræmd]adj.塞满的,挤满的; 大口地吃; 快速贪婪地吃v.把…塞满; 填入; 临时抱佛脚(cram的过去式)

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 prefixin 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 startwith a capital letter (like copyMakeBorder).因为所有库中函数都已在此名字空间中,所以无需加 cv 作为前缀。据此所有新的C++兼容函数都无此前缀,并且遵循驼峰命名准则。也就是第一个字母为小写(除非是单个单词作为函数名,如Canny)并且后续单词首字母大写(如 copyMakeBorder ).Nowfor converting the Mat objectyou can use either the IplImage orthe CvMat operators.While in the C interface you used to work with pointers here it’s no longer the case.In the C++ interface we have mostly Mat objects.These objects may be freely converted to both IplImage and CvMat withsimple assignment. For example:你可以使用 IplImage 或 CvMat 操作符来转换 Mat 对象。在C接口中,你习惯于使用指针,但此处将不再需要。在C++接口中,我们大多数情况下都是用 Mat对象。此对象可通过简单的赋值操作转换为 IplImage 和 CvMat 。示例如下:
Mat I;
IplImage pI = I;
CvMat    mI = I;

complaints英 [kəm'pleɪnts]

[kəm'pleɪnts]n.抱怨(complaint的名词复数 ); 诉苦; 投诉; 疾病

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 isdone 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 亮度分量

formula

生词本去背诵['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_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 candiffer 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 iszero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height ,respectively (seegetGaussianKernel() fordetails); 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() fordetails).
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 withnormally 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 alsoRNG, randu()

intact

生词本去背诵[ɪ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, intdtype=-1)Python: cv2.addWeighted(src1,alpha, src2, beta, gamma[, dst[, dtype]]) →dstC: void cvAddWeighted(constCvArr* 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 canbe 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;
NoteSaturation 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: