1

我正在尝试在航拍图像上实现KAZEA-KAZE使用PythonOpenCV进行特征检测和描述。

代码是什么?

此外,特征匹配应该使用什么描述符?

4

1 回答 1

11

KAZE,以及之前的一些最先进的方法,例如SIFTSURF,都是局部特征描述符,并且在某些方面,与描述符相比,它在检测描述SIFT方面都表现出更好的性能。A-KAZE另一方面,它是一种局部二进制描述符,与最先进的方法(例如局部特征描述符SIFT、、SURF和)相比,在速度和性能方面表现出色,KAZE并且与局部二进制描述符:.ORBBRISK

回答您的问题,它们都可以与它一起进行Feature Matching,尽管A-KAZE描述符不适合较小的补丁(例如,最小的图像 - 32x32 补丁),也就是说,为了避免返回没有描述符的关键点,A-KAZE通常删除关键点。

因此,在 和 之间的选择KAZE取决于A-KAZE您的应用程序的上下文。但是,先验A-KAZE的性能比KAZE.

在此示例中,我将通过使用PythonOpenCV的算法向您展示特征检测和匹配A-KAZEFLANN

首先,加载输入图像和将用于训练的图像。

在此示例中,我们使用这些图像:

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 上的以下存储库:

于 2021-01-23T21:32:18.387 回答