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

来源:互联网 发布:js 设置div display 编辑:程序博客网 时间:2024/05/23 18:10

g  gpu. GPU-accelerated Computer Vision¶

http://www.opencv.org.cn/opencvdoc/2.3.2/html/modules/gpu/doc/gpu.html

如何判断一个函数的导数图像?





求解上图的导数图像是下图哪个?
第三个,函数第一部分图像在区间[-无穷大,3]时,单调递增,此时函数的导数大于零;函数在区间[3,5]时,是单调递减函数,此时函数的导数小于零;函数在区间[5,+正无穷大]时,是单调递增函数,此时函数的导数大于零。综合上述分析,只有第三个图是符合题意的。

LLaplace Operator

Theory

  1. In the previous tutorial we learned how to use the Sobel Operator. It was based on the fact that in the edge area, the pixel intensity shows a “jump” or a high variation of intensity. Getting the first derivative of the intensity, we observed that an edge is characterized by a maximum, as it can be seen in the figure:

    Previous theory
  2. And...what happens if we take the second derivative?

    Second derivative

    You can observe that the second derivative is zero! So, we can also use this criterion to attempt to detect edges in an image. However, note that zeros will not only appear in edges (they can actually appear in other meaningless locations); this can be solved by applying filtering where needed.

Laplacian Operator

  1. From the explanation above, we deduce that the second derivative can be used todetect edges. Since images are “2D”, we would need to take the derivative in both dimensions. Here, the Laplacian operator comes handy.
  2. The Laplacian operator is defined by:

Laplace(f) = \dfrac{\partial^{2} f}{\partial x^{2}} + \dfrac{\partial^{2} f}{\partial y^{2}}

  1. The Laplacian operator is implemented in OpenCV by the function Laplacian. In fact, since the Laplacian uses the gradient of images, it calls internally the Sobeloperator to perform its computation.

Canny Edge Detector

Theory

  1. The Canny Edge detector was developed by John F. Canny in 1986. Also known to many as the optimal detector, Canny algorithm aims to satisfy three main criteria:
    • Low error rate: Meaning a good detection of only existent edges.标识出尽可能多的实际边缘,同时尽可能的减少噪声产生的误报。
    • Good localization: The distance between edge pixels detected and real edge pixels have to be minimized.标识出的边缘要与图像中的实际边缘尽可能接近。
    • Minimal response: Only one detector response per edge.图像中的边缘只能标识一次。(最小响应)
    • Find the gradient strength and direction with:计算梯度的幅值和方向
    • The direction is rounded to one of four possible angles (namely 0, 45, 90 or 135)梯度方向近似到四个可能角度之一(一般 0, 45, 90, 135)

suppression

生词本
去背诵
英 [səˈpreʃn]
美 [səˈprɛʃən]

n.   

analogous

生词本
英 [əˈnæləgəs]
美 [əˈnæləɡəs]

adj.  

gradient strength

  1. Non-maximum suppression is applied. This removes pixels that are not considered to be part of an edge. Hence, only thin lines (candidate edges) will remain.

  2. Hysteresis: The final step. Canny does use two thresholds (upper and lower):

    1. If a pixel gradient is higher than the upper threshold, the pixel is accepted as an edge
    2. If a pixel gradient value is below the lower threshold, then it is rejected.
    3. If the pixel gradient is between the two thresholds, then it will be accepted only if it is connected to a pixel that is above the upper threshold.

    Canny recommended a upper:lower ratio between 2:1 and 3:1.

  3. For more details, you can always consult your favorite Computer Vision book.

  1. 非极大值 抑制。 这一步排除非边缘像素, 仅仅保留了一些细线条(候选边缘)。

  2. 滞后阈值: 最后一步,Canny 使用了滞后阈值,滞后阈值需要两个阈值(高阈值和低阈值):

    1. 如果某一像素位置的幅值超过  阈值, 该像素被保留为边缘像素。
    2. 如果某一像素位置的幅值小于  阈值, 该像素被排除。
    3. 如果某一像素位置的幅值在两个阈值之间,该像素仅仅在连接到一个高于  阈值的像素时被保留。

    Canny 推荐的 : 阈值比在 2:1 到3:1之间。

  3. 想要了解更多细节,你可以参考任何你喜欢的计算机视觉书籍。

Cartesian

生词本
英 [kɑ:ˈti:ziən]
美 [kɑrˈtiʒən]

adj.

n.

polar

生词本
去背诵
英 [ˈpəʊlə(r)]
美 [ˈpolɚ]

adj.  

n.

Hough Line Transform

Goal

In this tutorial you will learn how to:

  • Use the OpenCV functions HoughLines and HoughLinesP to detect lines in an image.使用opencv函数HoughLines和HoughLinesP检测图像中的直线。

Theory

Note

 

The explanation below belongs to the book Learning OpenCV by Bradski and Kaehler.

Hough Line Transform

  1. The Hough Line Transform is a transform used to detect straight lines.霍夫线性变换是一个用于检测直线的变换。
  2. To apply the Transform, first an edge detection pre-processing is desirable.进行霍夫变换前,首先要进行边缘检测。

How does it work?

  1. As you know, a line in the image space can be expressed with twovariables.For example:众所周知,图像空间中的直线能够用两个变量表达。

    1. In the Cartesian coordinate system: Parameters: (m,b).笛卡尔坐标系(斜率和截距)
    2. In the Polar coordinate system: Parameters: (r,\theta) 极坐标系统(极径和极角)
    Line variables

    For Hough Transforms, we will express lines in the Polar system. Hence, a line equation can be written as:

    在霍夫变换中,我们用极坐标来表示直线,直线方程如下表达:

    y = \left ( -\dfrac{\cos \theta}{\sin \theta} \right ) x + \left ( \dfrac{r}{\sin \theta} \right )

Arranging the terms: r = x \cos \theta + y \sin \theta 整理
  1. In general for each point (x_{0}, y_{0}), we can define the family of lines that goes through that point as:对于每一个点(x0,y0),我们定义一个线族,每一条线都穿过这个点。

    一般来说对于点 (x_{0}, y_{0}), 我们可以将通过这个点的一族直线统一定义为:(官方翻译)

    r_{\theta} = x_{0} \cdot \cos \theta  + y_{0} \cdot \sin \theta

    Meaning that each pair (r_{\theta},\theta) represents each line that passes by (x_{0}, y_{0}).意思是,每一组点(r_{\theta},\theta)都代表一条线,这条线经过(x0,y0)。

    这就意味着每一对 (r_{\theta},\theta) 代表一条通过点 (x_{0}, y_{0}) 的直线.(官方翻译)

    sinusoid

    英 ['saɪnəsɔɪd]  美 ['saɪnəˌsɔɪd]
    n.  

  2. If for a given (x_{0}, y_{0}) we plot the family of lines that goes through it, we get a sinusoid. For instance, for x_{0} = 8 and y_{0} = 6 we get the following plot (in a plane \theta - r):

    如果对于一个给定点 (x_{0}, y_{0}) 我们在极坐标对极径极角平面绘出所有通过它的直线, 将得到一条正弦曲线. 例如, 对于给定点 x_{0} = 8 and y_{0} = 6 我们可以绘出下图 (在平面 \theta - r):(官方翻译)

    Polar plot of a the family of lines of a point

    We consider only points such that r > 0 and 0< \theta < 2 \pi.

    由于显卡的能力增强,现在的 OpenCV 已经有新的形态了,即大量的运算位于显卡上。

    intersect
    英 [ˌɪntə'sekt]
    美 [ˌɪntɚˈsɛkt]


    v

    vt.& vi.



  3. 3.cWe can do the same operation above for all the points in an image. If the curves of two different pointsintersectin the plane \theta - r, that means that both points belong to a same line. For instance, following with the example above and drawing the plot for two more points: x_{1} = 9y_{1} = 4 and x_{2} = 12y_{2} = 3, we get:

    我们为图像中所有的点重复以上的操作。如果两个不同点的弧度在平面 \theta - r相交,这意味着,这两个点属于同一条线。例如,按照上面的例子画图,x_{1} = 9y_{1} = 4 and x_{2} = 12y_{2} = 3, we get:

    我们可以对图像中所有的点进行上述操作.如果两个不同点进行上述操作后得到的曲线在平面 \theta - r相交, 这就意味着它们通过同一条直线. 例如, 接上面的例子我们继续对点: x_{1} = 9y_{1} = 4 和点x_{2} = 12y_{2} = 3 绘图, 得到下图:        (官方翻译)

    Polar plot of the family of lines for three points

    The three plots intersect in one single point (0.925, 9.6), these coordinates are the parameters (\theta, r) or the line in which (x_{0}, y_{0})(x_{1}, y_{1}) and (x_{2}, y_{2}) lay.

    这三条曲线在\theta - r平面相交于点(0.925,9.6),坐标表示参数对(\theta, r) 或者是说点 (x_{0}, y_{0}), 点 (x_{1}, y_{1}) 和点 (x_{2}, y_{2}) 组成的平面内的的直线.

  4. What does all the stuff above mean? It means that in general, a line can bedetected by finding the number of intersections between curves.The more curves intersecting means that the line represented by that intersection have more points. In general, we can define a threshold of the minimum number of intersections needed to detect a line.

    那么以上的材料要说明什么呢? 这意味着一般来说, 一条直线能够通过在平面 \theta - r 寻找交于一点的曲线数量来 检测. 越多曲线交于一点也就意味着这个交点表示的直线由更多的点组成. 一般来说我们可以通过设置直线上点的 阈值 来定义多少条曲线交于一点我们才认为 检测 到了一条直线.

  5. This is what the Hough Line Transform does. It keepstrack of the intersection between curves of every point in the image. If the number of intersections is above some threshold, then it declares it as a line with the parameters (\theta, r_{\theta}) of the intersection point.

    这就是霍夫线变换要做的. 它追踪图像中每个点对应曲线间的交点. 如果交于一点的曲线的数量超过了 阈值, 那么可以认为这个交点所代表的参数对 (\theta, r_{\theta}) 在原图像中为一条直线.

Standard and Probabilistic Hough Line Transform

OpenCV implements two kind of Hough Line Transforms:Opencv完成两种霍夫变换

  1. The Standard Hough Transform标准霍夫变换
  • It consists in pretty much what we just explained in the previous section. It gives you as result a vector of couples (\theta, r_{\theta})原理在上面的部分已经说明了. 它能给我们提供一组参数对 (\theta, r_{\theta}) 的集合来表示检测到的直线
  • In OpenCV it is implemented with the function HoughLines
  1. The Probabilistic Hough Line Transform 统计概率霍夫变换
  • A more efficient implementation of the Hough Line Transform.It gives as output the extremes of the detected lines (x_{0}, y_{0}, x_{1}, y_{1})它输出检测到的直线的端点 (x_{0}, y_{0}, x_{1}, y_{1})
  • In OpenCV it is implemented with the function HoughLinesP


For sake of efficiency, OpenCV implements a 

Hough Circle Transform  还没明白

detection method slightly trickier than the standard Hough Transform:The Hough gradient method. For more details, please check the book Learning OpenCV or your favorite Computer Vision bibliography
出于上面提到的对运算效率的考虑, OpenCV实现的是一个比标准霍夫圆变换更为灵活的检测方法: 霍夫梯度法, 也叫2-1霍夫变换(21HT), 它的原理依据是圆心一定是在圆上的每个点的模向量上, 这些圆上点模向量的交点就是圆心, 霍夫梯度法的第一步就是找到这些圆心, 这样三维的累加平面就又转化为二维累加平面. 第二部根据所有候选中心的边缘非0像素对其的支持程度来确定半径. 21HT方法最早在Illingworth的论文The Adaptive Hough Transform中提出并详细描述, 也可参照Yuen在1990年发表的A Comparative Study of Hough Transform Methods for Circle Finding, Bradski的《学习OpenCV》一书则对OpenCV中具体对算法的具体实现有详细描述并讨论了霍夫梯度法的局限性.
Remapping重映射

interpolation

生词本
英 [ɪnˌtɜ:pə'leɪʃn]
美 [ɪnˌtɚpəˈleʃən]

n. 

Affine Transformations仿射变换

warpAffine

Applies an affine transformation to an image.

C++: void warpAffine(InputArray src, OutputArray dst, InputArray M, Sizedsize, int flags=INTER_LINEAR, int borderMode=BORDER_CONSTANT, const Scalar&borderValue=Scalar())
Python: cv2.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]]) → dst
C: void cvWarpAffine(const CvArr* src, CvArr* dst, const CvMat* map_matrix, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, CvScalar fillval=cvScalarAll(0))
Python: cv.WarpAffine(src, dst, mapMatrix, flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, fillval=(0, 0, 0, 0)) → None
C: void cvGetQuadrangleSubPix(const CvArr* src, CvArr* dst, const CvMat*map_matrix)
Python: cv.GetQuadrangleSubPix(src, dst, mapMatrix) → None
Parameters:
  • src – input image.
  • dst – output image that has the size dsize and the same type as src .
  • M – 2\times 3 transformation matrix.
  • dsize – size of the output image.
  • flags – combination of interpolation methods (see resize()) and the optional flag WARP_INVERSE_MAP that means that M is the inverse transformation ( \texttt{dst}\rightarrow\texttt{src} ).
  • borderMode – pixel extrapolation method (seeborderInterpolate()); when borderMode=BORDER_TRANSPARENT , it means that the pixels in the destination image corresponding to the “outliers” in the source image are not modified by the function.
  • borderValue – value used in case of a constant border; by default, it is 0.

The function warpAffine transforms the source image using the specified matrix:

\texttt{dst} (x,y) =  \texttt{src} ( \texttt{M} _{11} x +  \texttt{M} _{12} y +  \texttt{M} _{13}, \texttt{M} _{21} x +  \texttt{M} _{22} y +  \texttt{M} _{23})

when the flag WARP_INVERSE_MAP is set. Otherwise, the transformation is first inverted with invertAffineTransform() and then put in the formula above instead of M . The function cannot operate in-place.

See also

 

warpPerspective()resize()remap()getRectSubPix(),transform()

Note

 

cvGetQuadrangleSubPix is similar to cvWarpAffine, but the outliers are extrapolated using replication border mode.

isotropic

生词本
英 [ˌaɪsə'trɒpɪk]
美 [ˌaɪsə'trɒpɪk]

adj. 

getRotationMatrix2D

Calculates an affine matrix of 2D rotation.

C++: Mat getRotationMatrix2D(Point2f center, double angle, double scale)
Python: cv2.getRotationMatrix2D(center, angle, scale) → retval
C: CvMat* cv2DRotationMatrix(CvPoint2D32f center, double angle, doublescale, CvMat* map_matrix)
Python: cv.GetRotationMatrix2D(center, angle, scale, mapMatrix) → None
Parameters:
  • center – Center of the rotation in the source image.
  • angle – Rotation angle in degrees. Positive values mean counter-clockwise rotation (the coordinate origin is assumed to be the top-left corner).
  • scale – Isotropic scale factor.
  • map_matrix – The output affine transformation, 2x3 floating-point matrix.

The function calculates the following matrix:

\begin{bmatrix} \alpha &  \beta & (1- \alpha )  \cdot \texttt{center.x} -  \beta \cdot \texttt{center.y} \\ - \beta &  \alpha &  \beta \cdot \texttt{center.x} + (1- \alpha )  \cdot \texttt{center.y} \end{bmatrix}

where

\begin{array}{l} \alpha =  \texttt{scale} \cdot \cos \texttt{angle} , \\ \beta =  \texttt{scale} \cdot \sin \texttt{angle} \end{array}

The transformation maps the rotation center to itself. If this is not the target, adjust the shift.

equalize  英 ['i:kwəlaɪz]  美 [ˈikwəˌlaɪz]

vt.& vi.   

representation 英 [ˌreprɪzenˈteɪʃn]  美 [ˌrɛprɪzɛnˈteʃən]

n.   

quantify   英 ['kwɒntɪfaɪ]美 ['kwɑ:ntɪfaɪ]

vt. 
Take a look at the figure below: The green circles indicate the underpopulated intensities.

spread   英 [spred]  美 [sprɛd]

vt.& vi.   

n. 

vt.   

vi.   

adj.   

accomplish  英 [ə'kʌmplɪʃ]  美 [əˈkɑmplɪʃ]

vt.   

cumulative  英 ['kju:mjələtɪv] 美 [ˈkjumjəˌletɪv, -jələtɪv]

adj.   

remapping英 [rɪ'mæpɪŋ]  美 [rɪ'mæpɪŋ]

重测图

What is an Image Histogram?

  • It is agraphical representationof theintensity distributionof an image.图像中强度分布的图形表达式
  • It quantifies the number of pixels for each intensity value considered.
  • 它(直方图)统计每种强度值的像素个数。
../../../../../_images/Histogram_Equalization_Theory_0.jpg

What is Histogram Equalization?直方图均衡

  • It is a method that improves the contrast in an image,in order tostretch out the intensity range.
  • 它是一种方法,通过拉伸(图像)强度分布,提升图像的对比度,
  • To make it clearer, from the image above, you can see that the pixels seem clustered around the middle of 
  • the available range of intensities. What Histogram Equalization does is to stretch out this range. Take a
  •  look at the figure below: The green circles indicate the underpopulated intensities. After applying the 
  • equalization, we get an histogram like the figure in the center. The resulting image is shown in the 
  • picture at right.
  • 从上面的图像,我们看到,像素值都聚集强度分布的中间区域。直方图均衡就是拉伸这个中间区域。我们看下图:绿色
  • 圆圈表示低强度分布区域。通过均衡,我们得到中间所示的直方图。结果图像显示在其右侧。
../../../../../_images/Histogram_Equalization_Theory_1.jpg

How does it work?

  • Equalization implies mapping one distribution (the given histogram) to another distribution 

    (a wider and more uniform distribution of intensity values) so the intensity values are spreaded 

    over the whole range.

    均衡将分布从一个映射到另一个,所以强灰度值被分布到整个区域。

  • To accomplish the equalization effect, the remapping should be the cumulative distribution function 

    (cdf) (more details, refer to Learning OpenCV). For the histogram H(i), its cumulative distribution

     H^{'}(i) is:

    为了完成均衡,映射是建增的分布函数。直方图H(i),它的整体分布是:

    要使用其作为映射函数, 我们必须对最大值为255 (或者用图像的最大强度值) 的累积分布 H^{'}(i) 进行归一化. 

    同上例, 累积分布函数为:

    H^{'}(i) = \sum_{0 \le j < i} H(j)

    To use this as a remapping function, we have to normalize H^{'}(i) such that the maximum value is 255 

    ( or the maximum value for the intensity of the image ). From the example above, the cumulative 

    function is:

    使用这个作为重映射函数,我们将最大值进行均匀分布,从上面的例子来看,

    ../../../../../_images/Histogram_Equalization_Theory_2.jpg
  • Finally, we use a simple remapping procedure to obtain the intensity values of the equalized image:

    最后,我们使用一个简便的重映射过程去获得均衡化图像的直方图。

    equalized( x, y ) = H^{'}( src(x,y) )

blur()

Histogram Calculation直方图计算

Goal

correspondent

生词本
去背诵
英 [ˌkɒrəˈspɒndənt]
美 [ˌkɔrɪˈspɑndənt, ˌkɑr-]

n. 

In this tutorial you will learn how to:

  • Use the OpenCV function split to divide an image into its correspondent planes.
  • 使用函数split将图像分成相应的平面。分割成单通道数组
  • To calculate histograms of arrays of images by using the OpenCV function calcHist。
  • 使用calcHist函数统计每组图像的直方图。计算图像阵列的直方图
  • To normalize an array by using the function normalize
  • 使用函数normalize均匀化数组。归一化数组

Note

 

In the last tutorial (Histogram Equalization) we talked about a particular kind of histogram called 

Image histogram. Now we will considerate it in itsmore general concept. Read on!

在上一篇中(直方图均衡化)我们介绍了一种特殊直方图叫做图像直方图。现在我们从更加广义的角度来考虑直方图的概念,继续往下读。


What are histograms?

  • Histograms are collected counts of data organized into a set of predefined bins

    直方图就是将统计好的数据存入bins数组,直方图是对数据的集合统计,并将统计结果分布于一系列预定义的bins中。

  • When we say data we are not restricting it to be intensity values (as we saw in the previous Tutorial). 

    The data collected can be whatever feature you find useful to describe your image.

    当我们谈到数据,我们没有严格的说是灰度值,

    统计数据可能是任何能有效描述图像的特征。

  • Let’s see an example. Imagine that a Matrix contains information of an image (i.e. intensity in the 

    range 0-255):

    先看一个例子吧。 假设有一个矩阵包含一张图像的信息 (灰度值 0-255):

    ../../../../../_images/Histogram_Calculation_Theory_Hist0.jpg
  • What happens if we want to count this datain an organized way? Since we know that the range of information 

    value for this case is 256 values, we can segment our range in subparts (called bins) like:

    如果我们按照某种方式去统计这些数字,会发生什么情况呢?既然已知数字的范围包含256个值,我们可以将这个范围分割

    成子区域。

    \begin{array}{l}[0, 255] = { [0, 15] \cup [16, 31] \cup ....\cup [240,255] } \\range = { bin_{1} \cup bin_{2} \cup ....\cup bin_{n = 15} }\end{array}

    and we can keep count of the number of pixels that fall in the range of each bin_{i}. Applying this to the 

    example above we get the image below ( axis x represents the bins and axis y the number of pixels in each 

    of them).

    我们可以将像素的统计数放入相应的bin区域。将其应用到下面的例子中。(x轴表示bins,y轴表示相应bins区域的像素数)


    ../../../../../_images/Histogram_Calculation_Theory_Hist1.jpg
  • This was just a simple example of how an histogram works and why it is useful. An histogram can keep count

     not only of color intensities, but of whatever image features that we want to measure (i.e. gradients, 

    directions, etc).

    这仅仅是用来说明直方图如何工作的一个实例。一个直方图不仅可以统计色彩强度,而且可以统计任何我们想要度量的图像特

    性(比如:梯度,方向等等)。


  • Let’s identify some parts of the histogram:让我们来搞清楚直方图的一些具体细节:

    1. dims: The number of parameters you want to collect data of. In our example, dims = 1 because we are only 
    2. counting the intensity values of each pixel (in a greyscale image).
    3. 我们想要统计的特征的数目。(在上例中,dims = 1因为我们仅仅统计了灰度值(灰度级图像)
    4. bins: It is the number of subdivisions in each dim. In our example, bins = 16
    5. 每一维的分区数,我们的示例是16(每个特征空间子区段的数目)
    6. range: The limits for the values to be measured. In this case: range = [0,255]
    7. 我们所度量的值的范围,本例是【0-255】(每个特征空间的取值范围)
  • What if you want to count two features? In this case your resulting histogram would be a 3D plot (in which x 

    and y would be bin_{x}and bin_{y} for each feature and z would be the number of counts for each combination of 

    (bin_{x}, bin_{y}). The same would apply for more features (of course it gets trickier)

    怎样去统计两个特征呢?在这种情况下,直方图就是3维的了,x轴和y轴分别代表一个特征,z轴是调入(binx, biny)组合

    的样本数。同样的方法适用于更高维的情形(当然会变得很复杂)。

    segment

    生词本
    去背诵
    英 [ˈsegmənt]
    美 [ˈsɛɡmənt]

    n.   

    vt.&vi. 

    what if

    生词本
    英 [hwɔt if]美 [hwɑt ɪf]


What OpenCV offers you

For simple purposes, OpenCV implements the function calcHist, which calculates the histogram of a set of 

arrays (usually images or image planes). It can operate with up to 32 dimensions. We will see it in the 

code below!

opencv提供了一个简单的计算数组集(通常是图像或分割后的通道)的直方图函数calcHist。支持高达32维的直方图。下面的代码演示了

如何使用该函数计算直方图。

Code

  • What does this program do?

    • Loads an image
    • Splits the image into its R, G and B planes using the function split
    • Calculate the Histogram of each 1-channel plane by calling the function calcHist计算各单通道图像的直方图
    • Plot the three histograms in a window在一个窗口叠加显示3张直方图

Histogram Comparison

In this tutorial you will learn how to:

  • Use the function compareHist toget a numerical parameter that express how well two histograms match with each other.
  • 使用函数获得一个数字参数来表示两个直方图的对比(相似度)。
  • Use different metrics to compare histograms
  • 使用不同的方法(对比标准)去度量这两个直方图。

Theory

  • To compare two histograms ( H_{1} and H_{2} ), first we have to choose a metric (d(H_{1}, H_{2})) to expresshow well 

    both histograms match.

    对比这两个直方图,首先我们要选择一个衡量直方图相似度的对比标准()

  • OpenCV implements the function compareHist to perform a comparison. It also offers 4 different metrics to 

    compute the matching:

    opencv 使用函数compareHist来完成对比。opencv 还提供了4中不同的对比标准去计算相似度

    1. Correlation ( CV_COMP_CORREL )

      d(H_1,H_2) =  \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}

      where

      \bar{H_k} =  \frac{1}{N} \sum _J H_k(J)

      and N is the total number of histogram bins.

    2. Chi-Square ( CV_COMP_CHISQR )

      d(H_1,H_2) =  \sum _I  \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}

    3. Intersection ( method=CV_COMP_INTERSECT )

      d(H_1,H_2) =  \sum _I  \min (H_1(I), H_2(I))

    4. Bhattacharyya distance ( CV_COMP_BHATTACHARYYA )

      d(H_1,H_2) =  \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}

Code

  • What does this program do?

    • Loads a base image and 2 test images to be compared with it.
    • Generate 1 image that is the lower half of the base image
    • Convert the images to HSV format
    • Calculate the H-S histogram for all the images and normalize them in order to compare them.
    • Compare the histogram of the base image with respect to the 2 test histograms, the histogram of the lower half base image and with the same base image histogram.
    • Display the numerical matching parameters obtained.
    •  at sight 第一眼
    • To tell truth 讲实话
    • at a loss 不知所措
    • out of control失去控制
It is reported that a bus went out of control on a highwaysouth of the city last night.名(south前有介词或定冠词)、副词(south前有无)
word = news消息,不可数,
the driver was at a loss when word came that he was forbidden to drive for speeding.
There is a Liu chang(表达人不清晰,a表示某一个概念,相当于some=a certain) in our class , but i am afraid he isn't the one you want.
As is known to all, the (普通名词+专有名词=专有名词)People's(普通名词) Republic of China (专有名词)is the biggest(最高级) developing country in the world.
We are now living in the(特指) "information(普通名词) age(普通名词)"(普通名词+普通名词=表示一个时代),a  time(所有时代之一) of new discoveries(复数) and great changes.
make time抽出时间 make time in her day for regular sport.
On February 27, 2011, Premier Wen Jiabao  hold an  online chat with Internet users across the country(特指中国) and overseas.the third time the leader had participated in the event.
we work together to achieve our common purpose :a world that is safer ,cleaner more thanthe one we found.
China held a ceremory to commemorate anniversary of xinhai Revolution  at the (普通名词+专有名词)Great Hall of the People in Beijing.
As (\)cities (名复数表泛指)grow, so does the number of buildings that characterize them: office factories . shopping centers and high-rise apartment buildings.
in danger of ...处于危险之中
People who drink and drive are a danger both to themselves and to others. They are in  danger of losing their lives.
According to recent reports the rare animals, the crocodile, will be in 




























































0 0
原创粉丝点击