本文整理汇总了Python中cv2.DescriptorMatcher_create方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.DescriptorMatcher_create方法的具体用法?Python cv2.DescriptorMatcher_create怎么用?Python cv2.DescriptorMatcher_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.DescriptorMatcher_create方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: match
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DescriptorMatcher_create [as 别名]
def match(self, key_a, fea_a, key_b, fea_b):
# Compute the raw matches and initialize the list of actual matches
matcher = cv2.DescriptorMatcher_create(self.distance_method)
raw_matches = matcher.knnMatch(fea_b, fea_a, 2)
matches = []
# Loop over the raw matches
for match in raw_matches:
# Ensure the distance is within a certain ratio of each other
if len(match) == 2 and match[0].distance < match[1].distance * self.ratio:
matches.append((match[0].trainIdx, match[0].queryIdx))
# Check to see if there are enough matches to process
if len(matches) > self.min_matches:
# Construct the two sets of points
poi_a = np.float32([key_a[i] for (i, _) in matches])
poi_b = np.float32([key_b[j] for (_, j) in matches])
# Compute the homography between the two sets of points and compute the ratio of matched points
(_, status) = cv2.findHomography(poi_a, poi_b, cv2.RANSAC, 4.0)
# Return the ratio of the number of matched keypoints to the total number of keypoints
return float(status.sum()) / status.size
# No matches were found
return -1.0
示例2: get_Allpossible_Match
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DescriptorMatcher_create [as 别名]
def get_Allpossible_Match(self,featuresA,featuresB):
# compute the all matches using euclidean distance and opencv provide
#DescriptorMatcher_create() function for that
match_instance = cv2.DescriptorMatcher_create("BruteForce")
All_Matches = match_instance.knnMatch(featuresA, featuresB, 2)
return All_Matches
示例3: DescriptorMatcher_create
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DescriptorMatcher_create [as 别名]
def DescriptorMatcher_create(method):
return cv2.DescriptorMatcher_create(method)
示例4: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DescriptorMatcher_create [as 别名]
def __init__(self, image, ratio = 0.75, reprojThresh = 4.0):
self.leftImage = image
self.ratio = ratio
self.reprojThresh = reprojThresh
self.surfFeature = cv2.xfeatures2d.SURF_create(500, extended = False, upright = False)
#HessianThreshold = 500
#No orientation calculation
#64 dimension feature vector
self.matcher = cv2.DescriptorMatcher_create('BruteForce')
self.leftKps, self.leftDescriptor = self.detectAndDescribe(image)
示例5: matchKeypoints
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DescriptorMatcher_create [as 别名]
def matchKeypoints(self, kpsA, kpsB, featuresA, featuresB,
ratio, reprojThresh):
# compute the raw matches and initialize the list of actual
# matches
matcher = cv2.DescriptorMatcher_create("BruteForce")
rawMatches = matcher.knnMatch(featuresA, featuresB, 2)
matches = []
# loop over the raw matches
for m in rawMatches:
# ensure the distance is within a certain ratio of each
# other (i.e. Lowe's ratio test)
if len(m) == 2 and m[0].distance < m[1].distance * ratio:
matches.append((m[0].trainIdx, m[0].queryIdx))
# computing a homography requires at least 4 matches
if len(matches) > 4:
# construct the two sets of points
ptsA = np.float32([kpsA[i] for (_, i) in matches])
ptsB = np.float32([kpsB[i] for (i, _) in matches])
# compute the homography between the two sets of points
(H, status) = cv2.findHomography(ptsA, ptsB, cv2.RANSAC,
reprojThresh)
# return the matches along with the homograpy matrix
# and status of each matched point
return (matches, H, status)
# otherwise, no homograpy could be computed
return None
示例6: __init__
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DescriptorMatcher_create [as 别名]
def __init__(self, image, ratio = 0.75, reprojThresh = 4.0):
self.leftImage = image
self.ratio = ratio
self.reprojThresh = reprojThresh
self.surfFeature = cv2.xfeatures2d.SURF_create(500, extended = False, upright = True)
#HessianThreshold = 500
#No orientation calculation
#64 dimension feature vector
self.matcher = cv2.DescriptorMatcher_create('BruteForce')
self.leftKps, self.leftDescriptor = self.detectAndDescribe(image)
示例7: matchDescriptors
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import DescriptorMatcher_create [as 别名]
def matchDescriptors(self, featuresA, featuresB):
'''
功能:匹配特征点
:param featuresA: 第一张图像的特征点描述符
:param featuresB: 第二张图像的特征点描述符
:return:返回匹配的对数matches
'''
if self.isGPUAvailable == False: # CPU Mode
# 建立暴力匹配器
if self.featureMethod == "surf" or self.featureMethod == "sift":
matcher = cv2.DescriptorMatcher_create("BruteForce")
# 使用KNN检测来自A、B图的SIFT特征匹配对,K=2,返回一个列表
rawMatches = matcher.knnMatch(featuresA, featuresB, 2)
matches = []
for m in rawMatches:
# 当最近距离跟次近距离的比值小于ratio值时,保留此匹配对
if len(m) == 2 and m[0].distance < m[1].distance * self.searchRatio:
# 存储两个点在featuresA, featuresB中的索引值
matches.append((m[0].trainIdx, m[0].queryIdx))
elif self.featureMethod == "orb":
matcher = cv2.DescriptorMatcher_create("BruteForce-Hamming")
rawMatches = matcher.match(featuresA, featuresB)
matches = []
for m in rawMatches:
matches.append((m.trainIdx, m.queryIdx))
# self.printAndWrite(" The number of matches is " + str(len(matches)))
else: # GPU Mode
if self.featureMethod == "surf":
matches = self.npToListForMatches(myGpuFeatures.matchDescriptors(np.array(featuresA), np.array(featuresB), 2, self.searchRatio))
elif self.featureMethod == "orb":
matches = self.npToListForMatches(myGpuFeatures.matchDescriptors(np.array(featuresA), np.array(featuresB), 3, self.orbMaxDistance))
return matches