當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.DescriptorMatcher_create方法代碼示例

本文整理匯總了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 
開發者ID:hsSam,項目名稱:PracticalPythonAndOpenCV_CaseStudies,代碼行數:28,代碼來源:covermatcher.py

示例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 
開發者ID:AVINASH793,項目名稱:Panoramic-Image-Stitching-using-invariant-features,代碼行數:10,代碼來源:panorama.py

示例3: DescriptorMatcher_create

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import DescriptorMatcher_create [as 別名]
def DescriptorMatcher_create(method):
        return cv2.DescriptorMatcher_create(method) 
開發者ID:jrosebr1,項目名稱:imutils,代碼行數:4,代碼來源:factories.py

示例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) 
開發者ID:shekkizh,項目名稱:ImageProcessingProjects,代碼行數:15,代碼來源:StitchingFromVideo.py

示例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 
開發者ID:shekkizh,項目名稱:ImageProcessingProjects,代碼行數:33,代碼來源:ImageStitching.py

示例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) 
開發者ID:shekkizh,項目名稱:ImageProcessingProjects,代碼行數:15,代碼來源:ImageStitching.py

示例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 
開發者ID:Keep-Passion,項目名稱:ImageStitch,代碼行數:34,代碼來源:ImageUtility.py


注:本文中的cv2.DescriptorMatcher_create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。