Commit 74e53e3f authored by kberry's avatar kberry
Browse files

Added adaptive_non_max_suppression to outlier_detector.py

parent c4a50ff6
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
import cv2
import numpy as np
import pandas as pd


def self_neighbors(matches):
@@ -150,3 +151,27 @@ def compute_homography(kp1, kp2, outlier_algorithm=cv2.RANSAC, reproj_threshold=
    return transformation_matrix, mask


# TODO: document me
# right now, this is going to work on the un-merged dataframes... NOPE. I confused what was where again. Need the
# graph for keypoint information...
def adaptive_non_max_suppression(keypoints, n=20, robust=0.9):
    minimum_suppression_radius = {}
    for i, kp1 in enumerate(keypoints):
        x1, y1 = kp1.pt
        temp = []
        for kp2 in keypoints: #includes kp1 for now
            if kp1.response < robust*kp2.response:
                x2, y2 = kp2.pt
                temp.append(np.sqrt((x2-x1)**2 + (y2-y1)**2))
        if(len(temp) > 0):
            minimum_suppression_radius[i] = np.min(np.array(temp))
        else:
            minimum_suppression_radius[i] = [np.nan]
    df = pd.DataFrame(list(minimum_suppression_radius.items()), columns=['keypoint_number', 'radius'])
    new_df = df.sort_values(by='radius', ascending=False).head(n)
    return new_df




+5 −0
Original line number Diff line number Diff line
@@ -49,6 +49,11 @@ class TestTwoImageMatching(unittest.TestCase):
        for node, attributes in cg.nodes_iter(data=True):
            self.assertIn(len(attributes['keypoints']), range(490, 511))

        # Step: apply ANMS
        for node, attributes in cg.nodes_iter(data=True):
            print(od.adaptive_non_max_suppression(attributes['keypoints']))
        self.assertTrue(False)

        # Step: Then apply a FLANN matcher
        fl = FlannMatcher()
        for node, attributes in cg.nodes_iter(data=True):