2

我想在无人机图像中BRISK使用PythonOpenCV实现特征检测和描述。

由于BRISK也是一个描述符,我想使用它的描述特征来匹配两个图像。

我该怎么做?

4

1 回答 1

5

您可以使用Local Binary Descriptor执行特征检测和描述,然后使用或算法使用PythonOpenCV进行特征匹配 BRISKBrute ForceFLANN

在这个例子中,我将通过算法向你展示特征检测和匹配。BRISKBrute Force

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

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

image1

在此处输入图像描述

image2

在此处输入图像描述

# Imports
import cv2 as cv
import matplotlib.pyplot as plt

# 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

现在我们将使用BRISK算法:

# Initiate BRISK descriptor
BRISK = cv.BRISK_create()

# Find the keypoints and compute the descriptors for input and training-set image
keypoints1, descriptors1 = BRISK.detectAndCompute(image1, None)
keypoints2, descriptors2 = BRISK.detectAndCompute(image2, None)

算法检测到的特征BRISK可以结合起来寻找不同图像之间相似的对象或模式。

现在我们将使用Brute Force算法:

# create BFMatcher object
BFMatcher = cv.BFMatcher(normType = cv.NORM_HAMMING,
                         crossCheck = True)

# Matching descriptor vectors using Brute Force Matcher
matches = BFMatcher.match(queryDescriptors = descriptors1,
                          trainDescriptors = descriptors2)

# Sort them in the order of their distance
matches = sorted(matches, key = lambda x: x.distance)

# Draw first 15 matches
output = cv.drawMatches(img1 = image1,
                        keypoints1 = keypoints1,
                        img2 = image2,
                        keypoints2 = keypoints2,
                        matches1to2 = matches[:15],
                        outImg = None,
                        flags = cv.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)

plt.imshow(output)
plt.show()

输出将是:

在此处输入图像描述

该技术广泛用于图像恢复应用、运动跟踪、对象检测、识别和跟踪、3D 对象重建等。您可以轻松修改加载图像的方式。通过这种方式,这种技术可以很容易地应用于您的问题。

要了解有关检测描述特征匹配技术、本地特征描述符本地二进制描述符和特征匹配算法的更多信息,我推荐GitHub 上的以下存储库:

于 2021-01-23T19:51:28.930 回答