Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I did it.

It looks something like this.

  1. After matching, I filter them by double Lowe's test (good_threshold=0.59, less_good_threshold = 0.675) and get a match percent.

    good = []
    for m, n in matches:
        if m.distance < good_threshold*n.distance:
            good.append(m)
    
    less_good = []
    for m, n in matches:
        if m.distance < less_good_threshold*n.distance:
            less_good.append(m)
    
    match_percent = len(good) / len(less_good) * 100
    
  2. Then I get homography

    if len(matches) < 4: return None

    src_pts = np.float32( [kp1[m.queryIdx].pt for m in matches]).reshape(-1, 1, 2) dst_pts = np.float32( [kp2[m.trainIdx].pt for m in matches]).reshape(-1, 1, 2)

    H, _ = cv.findHomography(src_pts, dst_pts, cv.RANSAC, 5.0)

  3. Then I test homography

    def is_good_homography(H) -> bool: det = H[0][0] * H[1][1] - H[1][0] * H[0][1] if det < 0: return False

    N1 = math.sqrt(H[0][0] * H[0][0] + H[1][0] * H[1][0]) if (N1 > 4 or N1 < 0.1): return False

    N2 = math.sqrt(H[0][1] * H[0][1] + H[1][1] * H[1][1]) if (N2 > 4 or N2 < 0.1): return False

    N3 = math.sqrt(H[2][0] * H[2][0] + H[2][1] * H[2][1]) if (N3 > 0.002): return False

    return True

  4. If match percent and homography are good, the reference image is recognized on photo