我正在尝试在航拍图像上实现KAZE
和A-KAZE
使用Python和OpenCV进行特征检测和描述。
代码是什么?
此外,特征匹配应该使用什么描述符?
我正在尝试在航拍图像上实现KAZE
和A-KAZE
使用Python和OpenCV进行特征检测和描述。
代码是什么?
此外,特征匹配应该使用什么描述符?
KAZE
,以及之前的一些最先进的方法,例如SIFT
和SURF
,都是局部特征描述符,并且在某些方面,与描述符相比,它在检测和描述SIFT
方面都表现出更好的性能。A-KAZE
另一方面,它是一种局部二进制描述符,与最先进的方法(例如局部特征描述符:SIFT
、、SURF
和)相比,在速度和性能方面表现出色,KAZE
并且与局部二进制描述符:.ORB
BRISK
回答您的问题,它们都可以与它一起进行Feature Matching,尽管A-KAZE
描述符不适合较小的补丁(例如,最小的图像 - 32x32 补丁),也就是说,为了避免返回没有描述符的关键点,A-KAZE
通常删除关键点。
因此,在 和 之间的选择KAZE
取决于A-KAZE
您的应用程序的上下文。但是,先验A-KAZE
的性能比KAZE
.
在此示例中,我将通过使用Python和OpenCV的算法向您展示特征检测和匹配。A-KAZE
FLANN
首先,加载输入图像和将用于训练的图像。
在此示例中,我们使用这些图像:
image1
:
image2
:
# Imports
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
# Open and convert the input and training-set image from BGR to GRAYSCALE
image1 = cv.imread(filename = 'image1.jpg',
flags = cv.IMREAD_GRAYSCALE)
image2 = cv.imread(filename = 'image2.jpg',
flags = cv.IMREAD_GRAYSCALE)
请注意,在导入图像时,我们使用flags = cv.IMREAD_GRAYSCALE
参数,因为在OpenCV中,默认颜色模式设置为BGR。因此,要使用Descriptors,我们需要将颜色模式模式从BGR转换为grayscale。
现在我们将使用A-KAZE
算法:
# Initiate A-KAZE descriptor
AKAZE = cv.AKAZE_create()
# Find the keypoints and compute the descriptors for input and training-set image
keypoints1, descriptors1 = AKAZE.detectAndCompute(image1, None)
keypoints2, descriptors2 = AKAZE.detectAndCompute(image2, None)
算法检测到的特征A-KAZE
可以结合起来寻找不同图像之间相似的对象或模式。
现在我们将使用FLANN
算法:
# FLANN parameters
FLANN_INDEX_KDTREE = 1
index_params = dict(algorithm = FLANN_INDEX_KDTREE,
trees = 5)
search_params = dict(checks = 50)
# Convert to float32
descriptors1 = np.float32(descriptors1)
descriptors2 = np.float32(descriptors2)
# Create FLANN object
FLANN = cv.FlannBasedMatcher(indexParams = index_params,
searchParams = search_params)
# Matching descriptor vectors using FLANN Matcher
matches = FLANN.knnMatch(queryDescriptors = descriptors1,
trainDescriptors = descriptors2,
k = 2)
# Lowe's ratio test
ratio_thresh = 0.7
# "Good" matches
good_matches = []
# Filter matches
for m, n in matches:
if m.distance < ratio_thresh * n.distance:
good_matches.append(m)
# Draw only "good" matches
output = cv.drawMatches(img1 = image1,
keypoints1 = keypoints1,
img2 = image2,
keypoints2 = keypoints2,
matches1to2 = good_matches,
outImg = None,
flags = cv.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
plt.imshow(output)
plt.show()
输出将是:
要使用描述符执行相同的示例KAZE
,只需初始化此描述符,更改:
AKAZE = cv.AKAZE_create()
至:
KAZE = cv.KAZE_create()
要了解有关检测、描述和特征匹配技术、本地特征描述符、本地二进制描述符和特征匹配算法的更多信息,我推荐GitHub 上的以下存储库: