OpenCV Feature Detection and Description -- Shi-Tomasi Corner Detector

原文链接:https://docs.opencv.org/4.1.2/d4/d8c/tutorial_py_shi_tomasi.html

如有错误欢迎指出~谢谢


Goal

In this chapter,

  • We will learn about the another corner detector: Shi-Tomasi Corner Detector
  • We will see the function: cv.goodFeaturesToTrack()

目标:

在此章节,

  • 我们会学习其他的角点检测: Shi-Tomasi Corner Detector
  • 学习的函数是: cv.goodFeaturesToTrack()

Theory

In last chapter, we saw Harris Corner Detector. Later in 1994, J. Shi and C. Tomasi made a small modification to it in their paper Good Features to Track which shows better results compared to Harris Corner Detector. The scoring function in Harris Corner Detector was given by:

理论:

在上一章中,在1994年晚些时候,我们看到了Harris Corner Detector。J.Shi和C. Tomasi在其论文Good Good to Track中对Harris的观点进行了小的修改,与Harris Harris Detector相比,该方法显示出更好的结果。Harris的计分函数由下式给出:

                                                                     

替代他的是有Shi-Tomasi提出的:

                                                                   

If it is a greater than a threshold value, it is considered as a corner. If we plot it in λ1λ2 space as we did in Harris Corner Detector, we get an image as below:

如果大于阈值,则将其视为角点。如果像在Harris Corner Detector中那样在λ1-λ2空间中绘制它,则会得到如下图像:

                                                           

From the figure, you can see that only when λ1 and λ2 are above a minimum value, λmin, it is conidered as a corner(green region).

从图中可以看出,只有当λ1和λ2高于最小值λmin时,才将其视为拐角(绿色区域)。  

Code

OpenCV has a function, cv.goodFeaturesToTrack(). It finds N strongest corners in the image by Shi-Tomasi method (or Harris Corner Detection, if you specify it). As usual, image should be a grayscale image. Then you specify number of corners you want to find. Then you specify the quality level, which is a value between 0-1, which denotes the minimum quality of corner below which everyone is rejected. Then we provide the minimum euclidean distance between corners detected.

代码:

OpenCV有这样一个函数, cv.goodFeaturesToTrack(). 他可以N个强角点在图像中,这个函数使用了Shi-Tomasi的方法(或者是Harris的,如果你想的特殊化的话)。通常,图像应该是灰度图像。然后,要定义好要找的角点的数量。然后,您指定质量级别,该值是介于0-1之间的值,该值表示每个角落都被拒绝的最低角点质量。然后,我们提供检测到的角之间的最小欧几里得距离。

With all this information, the function finds corners in the image. All corners below quality level are rejected. Then it sorts the remaining corners based on quality in the descending order. Then function takes first strongest corner, throws away all the nearby corners in the range of minimum distance and returns N strongest corners.

利用所有这些信息,该功能可以找到图像中的角。低于质量水平的所有角点均被拒绝。然后,它会根据质量以降序对剩余的角进行排序。然后函数首先获取最强角,然后丢弃最小距离范围内的所有附近角,然后返回N个最强角。

In below example, we will try to find 25 best corners:

在下面的程序中,我们会尝试发现25个最好的角点:

 1 import numpy as np
 2 import cv2 as cv
 3 from matplotlib import pyplot as plt
 4 img = cv.imread('blox.jpg')
 5 gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
 6 corners = cv.goodFeaturesToTrack(gray,25,0.01,10)
 7 corners = np.int0(corners)
 8 for i in corners:
 9     x,y = i.ravel()
10     cv.circle(img,(x,y),3,255,-1)
11 plt.imshow(img),plt.show()
tomasi

See the result below:

结果:

                        

 This function is more appropriate for tracking. We will see that when its time comes.

此功能更适合跟踪。We will see that when its time comes.

我测试过两个算法之前的表现,一些关键的点都是差不多的。但是好像Tomasi的速度更加的快一点。


 **注:补充数学知识**

引用 https://blog.csdn.net/robert_chen1988/article/details/88576194 

* 矩阵的迹 (trace)

    矩阵主对角线的元素的和

* 行列式(determinant)

    矩阵A的行列式是det(A) 

猜你喜欢

转载自www.cnblogs.com/mrAAron/p/11840972.html