Ejemplo n.º 1
0
def compareRANSACMethod(name, img1: ImageWithPoints, img2: ImageWithPoints):
    '''Compares different methods for outlier detection.'''
    pts_match_1, pts_match_2, match_good = ho.matchKeypoints(img1.kp, img1.des, img2.kp, img2.des)
    H, mask = cv2.findHomography(pts_match_1, pts_match_2, cv2.RANSAC, 4)
    mask = mask.ravel() > 0.5
    # printResults(name+"|CV2-RANSAC", H, pts_match_1, pts_match_2, mask)
    printResults(name+"|CV2-RANSAC", H, img1.points, img2.points, None)

    H, mask = cv2.findHomography(pts_match_1, pts_match_2, cv2.LMEDS, 4)
    mask = mask.ravel() > 0.5
    # printResults(name+"|CV2-LMEDS", H, pts_match_1, pts_match_2, mask)
    printResults(name+"|CV2-LMEDS", H, img1.points, img2.points, None)

    H, mask = cv2.findHomography(pts_match_1, pts_match_2, cv2.RHO, 4)
    mask = mask.ravel() > 0.5
    # printResults(name+"|CV2-RHO", H, pts_match_1, pts_match_2, mask)
    printResults(name+"|CV2-RHO", H, img1.points, img2.points, None)

    H, mask = ho.ransac(pts_match_1, pts_match_2, 4)
    H, mask = ho.findHomographyCV(pts_match_1, pts_match_2, 0, mask=mask)
    # printResults(name+"|RANSAC", H, pts_match_1, pts_match_2, mask)
    printResults(name+"|RANSAC", H, img1.points, img2.points, None)

    H, mask = ho.msac(pts_match_1, pts_match_2, 4)
    H, mask = ho.findHomographyCV(pts_match_1, pts_match_2, 0, mask=mask)
    # printResults(name+"|MSAC", H, pts_match_1, pts_match_2, mask)
    printResults(name+"|MSAC", H, img1.points, img2.points, None)
Ejemplo n.º 2
0
def compareLearningRate2(name, img1: ImageWithPoints, img2: ImageWithPoints):
    pts_match_1, pts_match_2, match_good = ho.matchKeypoints(img1.kp, img1.des, img2.kp, img2.des)
    _, mask = ho.findHomographyCV(pts_match_1, pts_match_2, 4)

  
    H = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    H, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=200, method=0, H=H, mask=mask, learning_rate=0.3)
    printResults(name+"|lr=0.3|200", H, pts_match_1, pts_match_2, mask)
    
    H = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    H, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=500, method=0, H=H, mask=mask, learning_rate=0.3)
    printResults(name+"|lr=0.3|500", H, pts_match_1, pts_match_2, mask)
    
    H = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    H, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=200, method=0, H=H, mask=mask, learning_rate=0.5)
    printResults(name+"|lr=0.5|200", H, pts_match_1, pts_match_2, mask)

    H = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    H, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=500, method=0, H=H, mask=mask, learning_rate=0.5)
    printResults(name+"|lr=0.5|500", H, pts_match_1, pts_match_2, mask)
    

    H = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    H, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=200, method=0, H=H, mask=mask, learning_rate=0.7)
    printResults(name+"|lr=0.7|200", H, pts_match_1, pts_match_2, mask)
    
    H = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    H, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=500, method=0, H=H, mask=mask, learning_rate=0.7)
    printResults(name+"|lr=0.7|500", H, pts_match_1, pts_match_2, mask)
Ejemplo n.º 3
0
def compareAndShow(img1: ImageWithPoints, img2: ImageWithPoints):
    pts_match_1, pts_match_2, match_good = ho.matchKeypoints(img1.kp, img1.des, img2.kp, img2.des)
    H_tf, mask_tf = ho.findHomography(pts_match_1, pts_match_2, 4)
    H_cv, mask_cv = ho.findHomographyCV(pts_match_1, pts_match_2, 4)

    image = ho.polyline(img2.points, img2.image, color=(0, 0, 255))

    image_tf = ho.polyline(ho.project(H_tf, img1.points), image, color=(255, 0, 0))
    image_cv = ho.polyline(ho.project(H_cv, img1.points), image, color=(0, 255, 0))

    while True:
        cv2.imshow('image', image)
        cv2.imshow('tf', image_tf)
        cv2.imshow('cv', image_cv)
        k = cv2.waitKey(10) & 0xFF
        if k == 27:
            break
Ejemplo n.º 4
0
def compareEpochs(name, img1: ImageWithPoints, img2: ImageWithPoints):
    pts_match_1, pts_match_2, match_good = ho.matchKeypoints(img1.kp, img1.des, img2.kp, img2.des)

    H_0, mask_0 = ho.findHomography(pts_match_1, pts_match_2, 2, epochs=0, learning_rate=0.3, method=2)
    H_1, mask_1 = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=2, learning_rate=0.3, method=0, H=H_0, mask=mask_0)
    H_2, mask_2 = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=8, learning_rate=0.3, method=0, H=H_1, mask=mask_0)
    H_3, mask_3 = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=10, learning_rate=0.3, method=0, H=H_2, mask=mask_0)
    H_4, mask_4 = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=20, learning_rate=0.3, method=0, H=H_3, mask=mask_0)

    H_cv, mask_cv = ho.findHomographyCV(pts_match_1, pts_match_2, 4)

    printResults(name+"|0 epochs", H_0, pts_match_1, pts_match_2, mask_0)
    printResults(name+"|2 epochs", H_1, pts_match_1, pts_match_2, mask_0)
    printResults(name+"|10 epochs", H_2, pts_match_1, pts_match_2, mask_0)
    printResults(name+"|20 epochs", H_3, pts_match_1, pts_match_2, mask_0)
    printResults(name+"|40 epochs", H_4, pts_match_1, pts_match_2, mask_0)
    printResults(name+"|0 epochs", H_0, img1.points, img2.points, None)
    printResults(name+"|2 epochs", H_1, img1.points, img2.points, None)
    printResults(name+"|10 epochs", H_2, img1.points, img2.points, None)
    printResults(name+"|20 epochs", H_3, img1.points, img2.points, None)
    printResults(name+"|40 epochs", H_4, img1.points, img2.points, None)
    printResults(name+"|cv", H_cv, img1.points, img2.points, None)
Ejemplo n.º 5
0
def compareWithout(name, img1: ImageWithPoints, img2: ImageWithPoints):
    '''Comparation with OpenCV. Both methods use the same keypoints. Our system does not use a prior SVD to find an estimation.'''
    pts_match_1, pts_match_2, match_good = ho.matchKeypoints(img1.kp, img1.des, img2.kp, img2.des)

    H_0 = np.asarray([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    # H_0, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=0,learning_rate=0.3,ransac=2)
    H_cv, mask_0 = ho.findHomographyCV(pts_match_1, pts_match_2, 4)

    printResults(name+"|cv", H_cv, pts_match_1, pts_match_2, mask_0)
    # printResults(name+"|cv", H_cv, img1.points, img2.points, None)

    H_0, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=100, learning_rate=0.3, method=0, H=H_0, mask=mask_0)
    printResults(name+"|100 epochs", H_0, pts_match_1, pts_match_2, mask_0)
    # printResults(name+"|100 epochs", H_0, img1.points, img2.points, None)
    # H_0 = H_0 / H_0[2, 2]
    # print(np.linalg.norm(H_0- H_cv))

    H_0, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=100, learning_rate=0.3, method=0, H=H_0, mask=mask_0)
    # printResults(name+"|200 epochs", H_0, pts_match_1, pts_match_2, mask_0)
    # printResults(name+"|200 epochs", H_0, img1.points, img2.points, None)
    # H_0 = H_0 / H_0[2, 2]
    # print(np.linalg.norm(H_0- H_cv))

    H_0, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=100, learning_rate=0.3, method=0, H=H_0, mask=mask_0)
    printResults(name+"|300 epochs", H_0, pts_match_1, pts_match_2, mask_0)
    # printResults(name+"|300 epochs", H_0, img1.points, img2.points, None)
    # H_0 = H_0 / H_0[2, 2]
    # print(np.linalg.norm(H_0- H_cv))

    H_0, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=100, learning_rate=0.3, method=0, H=H_0, mask=mask_0)
    # printResults(name+"|400 epochs", H_0, pts_match_1, pts_match_2, mask_0)
    # printResults(name+"|400 epochs", H_0, img1.points, img2.points, None)
    # H_0 = H_0 / H_0[2, 2]
    # print(np.linalg.norm(H_0- H_cv))

    H_0, _ = ho.findHomography(pts_match_1, pts_match_2, 4, epochs=100, learning_rate=0.3, method=0, H=H_0, mask=mask_0)
    printResults(name+"|500 epochs", H_0, pts_match_1, pts_match_2, mask_0)