python - 如何使用Python和OpenCV实现BRISK检测特征?

标签 python opencv feature-extraction feature-detection mser

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

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

我该怎么做?

最佳答案

您可以使用局部二进制描述符BRISK执行特征检测和描述,然后使用蛮力FLANN 算法使用 PythonOpenCV 进行特征匹配

在这个例子中,我将通过蛮力算法向您展示特征检测和匹配BRISK

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

在这个例子中,我们使用这些图像:

image1:

enter image description here

image2:

enter image description here

# 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。因此,要使用描述符,我们需要将颜色模式模式从BGR 转换为灰度

现在我们将使用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 算法检测到的特征可以组合起来,以找到不同图像之间相似的对象或模式。

现在我们将使用蛮力算法:

# 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()

输出将是:

enter image description here

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

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

关于python - 如何使用Python和OpenCV实现BRISK检测特征?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62571115/

相关文章:

python - 将 Keras 与 tensorflow 后端一起使用时如何控制内存?

python - OpenCV python : cv2. split() vs 在 BGR 图像中获取 channel 时进行切片

machine-learning - 如何判断两个代码片段功能是否相同?

python - 如何在opencv中计算粗糙度轮廓?

machine-learning - 计算机视觉和机器学习中特征描述符的解释

python - 查找循环网络中的边x python

python - Python中递归打印文件目录

python - 如何使用数据框中一列的 < 或 > 然后使用同一日期的另一列数据?

c++ - opencv:对 `cv::cuda::DescriptorMatcher::createBFMatcher(int)' 的 undefined reference

java - 如何修复 opencv 中的 NullPointerException