Commit 2555707f authored by Jay's avatar Jay Committed by jay
Browse files

Update to matcher to explicitly perform a self-neighbor check using the graph hash

parent 6a5a9c68
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class FlannMatcher(object):
        """
        self._flann_matcher.train()

    def query(self, descriptor, k=3, self_neighbor=True):
    def query(self, descriptor, query_image, k=3):
        """

        Parameters
@@ -62,13 +62,12 @@ class FlannMatcher(object):
        descriptor : ndarray
                     The query descriptor to search for

        query_image : hashable
                      Key of the query image

        k : int
            The number of nearest neighbors to search for

        self_neighbor : bool
                        If the query descriptor is also a member
                        of the KDTree avoid self neighbor, default True.

        Returns
        -------
        matched : dataframe
@@ -76,13 +75,13 @@ class FlannMatcher(object):
                  matched image name, query index, train index, and
                  descriptor distance
        """
        idx = 0
        if self_neighbor:
            idx = 1

        matches = self._flann_matcher.knnMatch(descriptor, k=k)
        matched = []
        for m in matches:
            for i in m[idx:]:
            for i in m:
                if self.image_indices[i.imgIdx] == query_image:
                    continue
                matched.append((self.image_indices[i.imgIdx],
                                i.queryIdx,
                                i.trainIdx,
+6 −4
Original line number Diff line number Diff line
@@ -36,8 +36,10 @@ class TestMatcher(unittest.TestCase):

        fmatcher.train()

        matched = fmatcher.query(self.fd['AS15-M-0296_SML.png'][1], k=2)
        self.assertEqual(10, len(matched))
        matched = fmatcher.query(self.fd['AS15-M-0296_SML.png'][1],'AS15-M-0296_SML.png', k=2)
        matched_to = matched['matched_to']
        self.assertTrue(matched_to[matched_to != 'AS15-M-0296_SML.png'].any())
        self.assertEqual(7, len(matched))

        # Check that self neighbors are being omitted
        distance = matched['distance']
@@ -56,8 +58,8 @@ class TestMatcher(unittest.TestCase):

        fmatcher.train()

        matched = fmatcher.query(self.fd['AS15-M-0296_SML.png'][1], k=3)
        self.assertEqual(20, len(matched))
        matched = fmatcher.query(self.fd['AS15-M-0296_SML.png'][1], 'AS15-M-0296_SML.png', k=3)
        self.assertEqual(12, len(matched))

        # Check that self neighbors are being omitted
        distance = matched['distance']
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ class TestTwoImageMatching(unittest.TestCase):

        for node, attributes in cg.nodes_iter(data=True):
            descriptors = attributes['descriptors']
            matches = fl.query(descriptors, k=2)
            matches = fl.query(descriptors, node,  k=2)
            cg.add_matches(node, matches)

        # Step: And create a C object