我想在无人机图像中BRISK
使用Python和OpenCV实现特征检测和描述。
由于BRISK
也是一个描述符,我想使用它的描述特征来匹配两个图像。
我该怎么做?
我想在无人机图像中BRISK
使用Python和OpenCV实现特征检测和描述。
由于BRISK
也是一个描述符,我想使用它的描述特征来匹配两个图像。
我该怎么做?
您可以使用Local Binary Descriptor执行特征检测和描述,然后使用或算法使用Python和OpenCV进行特征匹配。 BRISK
Brute Force
FLANN
在这个例子中,我将通过算法向你展示特征检测和匹配。BRISK
Brute 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 上的以下存储库: