ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

OpenCV Feature Detection and Description -- Harris Corner Detection Harris角点检测

2019-11-10 18:01:04  阅读:413  来源: 互联网

标签:Description corners 角点 Detection Harris Corner cv 函数


原文链接 https://docs.opencv.org/4.1.2/dc/d0d/tutorial_py_features_harris.html

阅读文档学习opencv 如有问题,大家指出~~


Goal

In this chapter,

  • We will understand the concepts behind Harris Corner Detection.
  • We will see the functions: cv.cornerHarris()cv.cornerSubPix()  

目标:

  (1)理解Harris角点检测

  (2)知道这几个函数 cv.cornerHarris(), cv.cornerSubPix() 

 

Theory

In last chapter, we saw that corners are regions in the image with large variation in intensity in all the directions. One early attempt to find these corners was done by Chris Harris & Mike Stephens in their paper A Combined Corner and Edge Detector in 1988, so now it is called Harris Corner Detector. He took this simple idea to a mathematical form. It basically finds the difference in intensity for a displacement of (u,v) in all directions. This is expressed as below:

理论:

在上一个章节中,我们知道了角点在每个方向上的变化都是巨大的。在早期就有Chris Harris 和 Mike Stephens 就做到了,在他们的论文(《A Combined Corner and Edge Detecor 》在1988年)中。所以现在的人把这样的角点叫做Harris角点检测。他把这个简单的想法变成了数学公式,它基本找到了所有方向上(u,v)位移的差异。表示如下:

 

Window function is either a rectangular window or gaussian window which gives weights to pixels underneath.

窗口函数可以是矩形窗口或高斯窗口,可以为其下方的像素赋予权重。

**备注:**

window function: 窗函数,在信号处理的过程中,我们经常使用FFT(傅立叶变换)来把信号从时域转换到频域。在转换之前,需要有一个函数来截取信号,这个函数我们经常使用的就是窗函数。

那么为什么要截取信号呢?因为信号不可能被无限的测量和运算。只能在一定周期下截取,用窗函数截取的信号,会对以后的FFT有帮助,减少频谱能量的泄漏。

**end**

We have to maximize this function E(u,v) for corner detection. That means, we have to maximize the second term. Applying Taylor Expansion to above equation and using some mathematical steps (please refer any standard text books you like for full derivation), we get the final equation as:

 

我们必须最大化此函数E(u,v)进行拐角检测。这意味着,我们必须最大化第二项。将泰勒展开式应用于上述方程式,并有一些数学步骤(请参考您喜欢的任何标准教科书以进行完整推导),得出的最终方程式为:

                                             其中 

 

Here, Ix and Iy are image derivatives in x and y directions respectively. (Can be easily found out using cv.Sobel()).

在此,Ix和Iy分别是在x和y方向上的图像导数。 (可以使用cv.Sobel()函数轻松找到)。

 

**备注:**

引用:https://blog.csdn.net/u011534057/article/details/77775974  https://blog.csdn.net/c337134154/article/details/50086547 这两个博客里面讲解了怎么推导的,实际上就是二元函数泰勒展开,取一介近似。怎么推导不是文章重点,不赘述

**end**

Then comes the main part. After this, they created a score, basically an equation, which will determine if a window can contain a corner or not.

然后是主要部分。此后,他们创建了一个分数,基本上是一个等式,它将确定一个窗口是否可以包含一个角。

其中 

  • det(M)=λ1λ2
  • trace(M)=λ1+λ2
  • λ1+λ2是矩阵M的特征值

 

So the values of these eigen values decide whether a region is corner, edge or flat.

  • When |R| is small, which happens when λ1 and λ2 are small, the region is flat.
  • When R<0, which happens when λ1>>λ2 or vice versa, the region is edge.
  • When R is large, which happens when λ1 and λ2 are large and λ1∼λ2, the region is a corner.

根据λ1,λ2的值我们可以把其分为三类:

1.λ1,λ2都很小且近似,E在所以方向接近于常数;

2.λ1>>λ2,或者λ2>>λ1, E将在某一方向上很大;

3.λ1,λ2都很大且近似,E将在所有方向上很大;

 

It can be represented in a nice picture as follows:

下面有张很好理解的图片:

 

 

So the result of Harris Corner Detection is a grayscale image with these scores. Thresholding for a suitable give you the corners in the image. We will do it with a simple image.

因此,Harris Corner Detection的结果是具有这些值的灰度图像。合适的阈值可作为提供图像的角点。我们将用一个简单的图像来做到这一点。


 

下面就是怎么使用cv.cornerHarris的例子。不做翻译。

 

 

 

 

Corner with SubPixel Accuracy

Sometimes, you may need to find the corners with maximum accuracy. OpenCV comes with a function cv.cornerSubPix() which further refines the corners detected with sub-pixel accuracy. Below is an example. As usual, we need to find the harris corners first. Then we pass the centroids of these corners (There may be a bunch of pixels at a corner, we take their centroid) to refine them. Harris corners are marked in red pixels and refined corners are marked in green pixels. For this function, we have to define the criteria when to stop the iteration. We stop it after a specified number of iteration or a certain accuracy is achieved, whichever occurs first. We also need to define the size of neighbourhood it would search for corners.

亚像素精度的角点

有时,你可能需要以最大的精度去找角点。 OpenCV带有一个函数cv.cornerSubPix(),该函数进一步细化了像素以亚像素精度检测。下面是一个例子。一样的,我们需要先找到Harris corner。然后我们传递这些角的质心(在角处可能有一堆像素,我们取它们的质心)以细化它们。 Harris角用红色像素标记,精制角用绿色像素标记。对于此功能,我们必须定义何时停止迭代的条件。我们会在指定的迭代次数或达到一定的精度之后(以先到者为准)停止它。我们还需要定义搜索拐角的邻域的大小。

 

 

**备注:**

上面讲述了寻找角点的函数 cornerHarris()

用法上要注意些什么?单通道,灰度 ;在什么场合下使用? 我感觉是在灰度下有明显不一样的情况下使用,或者说为了使用这个函数,要进行一定的处理,制造出好的识别场景

**end**

 

标签:Description,corners,角点,Detection,Harris,Corner,cv,函数
来源: https://www.cnblogs.com/mrAAron/p/11831102.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有