OpenCV中的Shi-Tomasi角点检测器
Posted 程序媛一枚~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV中的Shi-Tomasi角点检测器相关的知识,希望对你有一定的参考价值。
上一篇博客介绍了Harris角点检测器,这篇博客将介绍另一个角点检测器:Shi-Tomasi角点检测器。
-
Shi-Tomasi角点检测器是Harris角点检测器的优化,效果更好;
-
cv2.goodFeaturesToTrack(),通过Shi-Tomasi方法(或者Harris角点检测)在图像中找到N个最强的角点。并且在跟踪对象方面性能很好。
1. 效果图
原图 VS Harris角点检测器效果如下:
原图 VS Shi-Tomasi角点检测效果图如下:
可以看出Shi-Tomasi确实效果要好一些,所有角点均被成功检测;
2. 源码
# Shi-Tomasi角点检测是Harris角点检测的优化,更准确,会检测出N个最强角点;
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('images/polygon.jpg')
plt.subplot(1, 2, 1)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.xticks([])
plt.yticks([])
plt.title("origin")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
corners = cv2.goodFeaturesToTrack(gray, 25, 0.01, 10)
corners = np.int0(corners)
for i in corners:
x, y = i.ravel()
cv2.circle(img, (x, y), 3, 255, -1)
plt.subplot(1,2,2)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.xticks([])
plt.yticks([])
plt.title("Shi-Tomasi res")
plt.show()
参考
以上是关于OpenCV中的Shi-Tomasi角点检测器的主要内容,如果未能解决你的问题,请参考以下文章
Shi-Tomasi角点检测及光流法追踪——复现VINS前端视觉数据处理