Dai*_*ary 3 python opencv feature-extraction feature-detection mser
我想BRISK使用Python和OpenCV实现无人机图像中的特征检测和描述。
由于BRISK也是一个描述符,我想使用它的描述特征来匹配两个图像。
我该怎么做?
您可以使用本地二进制描述符执行特征检测和描述,然后使用Python和OpenCV使用或算法进行特征匹配。 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)
Run Code Online (Sandbox Code Playgroud)
请注意,导入图像时,我们使用该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)
Run Code Online (Sandbox Code Playgroud)
可以组合算法检测到的特征来查找不同图像之间相似的对象或图案。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()
Run Code Online (Sandbox Code Playgroud)
输出将是:
该技术广泛应用于图像恢复应用、运动跟踪、对象检测、识别和跟踪、3D 对象重建等。并且您可以轻松修改加载图像的方式。这样,该技术就可以轻松地应用于您的问题。
要了解有关检测、描述和特征匹配技术、局部特征描述符、局部二进制描述符和特征匹配算法的更多信息,我推荐GitHub上的以下存储库: