Exemplo n.º 1
0
    def computeMapping(self, leftImage, rightImage):
        leftGrey = cv2.cvtColor(leftImage, cv2.COLOR_BGR2GRAY)
        rightGrey = cv2.cvtColor(rightImage, cv2.COLOR_BGR2GRAY)
        orb = cv2.ORB_create()
        leftKeypoints, leftDescriptors = orb.detectAndCompute(leftGrey, None)
        rightKeypoints, rightDescriptors = orb.detectAndCompute(
            rightGrey, None
        )
        bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
        matches = bf.match(leftDescriptors, rightDescriptors)
        matches = sorted(matches, key=lambda x: x.distance)

        nMatches = int(
            float(self.matchPercentSlider.get()) * len(matches) / 100
        )

        if nMatches < 4:
            return None

        matches = matches[:nMatches]
        motionModel = self.motionModelVar.get()
        nRANSAC = int(self.nRANSACSlider.get())
        RANSACThreshold = float(self.RANSACThresholdSlider.get())

        return alignment.alignPair(
            leftKeypoints, rightKeypoints, matches, motionModel, nRANSAC,
            RANSACThreshold
        )
Exemplo n.º 2
0
def computeMapping(leftImage, rightImage):
    leftGrey = cv2.cvtColor(leftImage, cv2.COLOR_BGR2GRAY)
    rightGrey = cv2.cvtColor(rightImage, cv2.COLOR_BGR2GRAY)
    #orb = cv2.ORB_create()#xfeatures2d.SIFT_create()#
    if use_algorithm == "SIFT":
        orb = cv2.xfeatures2d.SIFT_create()
    elif use_algorithm == "SURF":
        orb = cv2.xfeatures2d.SURF_create()
    elif use_algorithm == "ORB":
        orb = cv2.ORB_create(nfeatures=1500)

    leftKeypoints, leftDescriptors = orb.detectAndCompute(leftGrey, None)
    rightKeypoints, rightDescriptors = orb.detectAndCompute(rightGrey, None)

    #bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
    #matches = bf.match(leftDescriptors, rightDescriptors)
    #matches = sorted(matches, key=lambda x: x.distance)

    # Brute-Force matching with SIFT descriptors
    bf = cv2.BFMatcher()

    # Matching the keypoints with k-nearest neighbor (with k=2)
    matches = bf.knnMatch(leftDescriptors, rightDescriptors, k=2)

    #nMatches = int(
    #	float(20) * len(matches) / 100
    #)

    #if nMatches < 4:
    #	return None

    goodMatch = []
    # Performing ratio test to find good matches
    for m, n in matches:
        if m.distance < 0.75 * n.distance:
            goodMatch.append(m)

    #matches = matches[:nMatches]
    motionModel = eTranslate
    nRANSAC = cv2.RANSAC
    RANSACThreshold = float(5.0)

    return alignment.alignPair(leftKeypoints, rightKeypoints, goodMatch,
                               motionModel, nRANSAC, RANSACThreshold)
Exemplo n.º 3
0
 def test_alignPair(self):
     '''Tests TODO 4'''
     M = alignment.alignPair(self.f1, self.f2, self.matches,
                             alignment.eHomography, 1, 1)