Python+OpenCV:图像Shi-Tomasi角点检测器
理论
The scoring function in Harris Corner Detector was given by:
Instead of this, Shi-Tomasi proposed:
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:
示例
####################################################################################################
# 图像Shi-Tomasi角点检测(Shi-Tomasi Corner Detector)
def lmc_cv_image_shi_tomasi_corner_detection():
"""
函数功能: 图像Shi-Tomasi角点检测(Shi-Tomasi Corner Detector)。
"""
stacking_images = []
image_file_name = ['D:/99-Research/Python/Image/CheckerBoard.jpg',
'D:/99-Research/Python/Image/CheckerBoard02.jpg',
'D:/99-Research/Python/Image/CheckerBoard04.jpg',
'D:/99-Research/Python/Image/CheckerBoard07.jpg']
for i in range(len(image_file_name)):
# 读取图像
image = lmc_cv.imread(image_file_name[i])
image = lmc_cv.cvtColor(image, lmc_cv.COLOR_BGR2RGB)
result_image = image.copy()
gray_image = lmc_cv.cvtColor(image, lmc_cv.COLOR_BGR2GRAY)
# find Shi-Tomasi corners
corners = lmc_cv.goodFeaturesToTrack(gray_image, 25, 0.001, 10)
corners = np.int0(corners)
# Now draw them
for j in range(len(corners)):
x, y = corners[j].ravel()
lmc_cv.circle(result_image, center=(x, y), radius=5, color=(255, 0, 255), thickness=3,
lineType=lmc_cv.LINE_8, shift=0)
# stacking images side-by-side
stacking_image = np.hstack((image, result_image))
stacking_images.append(stacking_image)
# 显示图像
for i in range(len(stacking_images)):
pyplot.figure('Shi-Tomasi Corner Detection %d' % (i + 1))
pyplot.subplot(1, 1, 1)
pyplot.imshow(stacking_images[i], 'gray')
pyplot.xticks([])
pyplot.yticks([])
pyplot.show()
# 根据用户输入保存图像
if ord("q") == (lmc_cv.waitKey(0) & 0xFF):
# 销毁窗口
pyplot.close('all')
return