Python cv2.DescriptorMatcher_create() Examples

The following are 8 code examples of cv2.DescriptorMatcher_create(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module cv2 , or try the search function .
Example #1
Source File: ImageUtility.py    From ImageStitch with MIT License 6 votes vote down vote up
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 
Example #2
Source File: covermatcher.py    From PracticalPythonAndOpenCV_CaseStudies with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #3
Source File: panorama.py    From Panoramic-Image-Stitching-using-invariant-features with MIT License 5 votes vote down vote up
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 
Example #4
Source File: factories.py    From imutils with MIT License 5 votes vote down vote up
def DescriptorMatcher_create(method):
        return cv2.DescriptorMatcher_create(method) 
Example #5
Source File: factories.py    From imutils with MIT License 5 votes vote down vote up
def DescriptorMatcher_create(matcher):
        """

        :param matcher: string of the type of descriptor matcher to return
        :return: the matcher int
        """
        try:
            extr = _MATCHER_FACTORY[matcher]
        except KeyError:
            raise AttributeError("{} not a supported matcher".format(matcher))

        return cv2.DescriptorMatcher_create(extr) 
Example #6
Source File: StitchingFromVideo.py    From ImageProcessingProjects with MIT License 5 votes vote down vote up
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) 
Example #7
Source File: ImageStitching.py    From ImageProcessingProjects with MIT License 5 votes vote down vote up
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 
Example #8
Source File: ImageStitching.py    From ImageProcessingProjects with MIT License 5 votes vote down vote up
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)