Commit 262cdac2 authored by jay's avatar jay
Browse files

yRenaming to differentiate between cpu and gpu implementations

parent 50c7bcd8
Loading
Loading
Loading
Loading
+3 −3
Changes for autocnet/matcher/cpu_decompose.py: 3 added lines, 3 removed lines.
Original line number Diff line number Diff line
import numpy as np
from scipy.spatial.distance import cdist

from autocnet.matcher.feature import FlannMatcher
from autocnet.matcher.feature_matcher import match
from autocnet.matcher.cpu_matcher import FlannMatcher
from autocnet.matcher.cpu_matcher import match
from autocnet.transformation.decompose import coupled_decomposition


@@ -203,6 +203,6 @@ def decompose_and_match(self, k=2, maxiteration=3, size=18, buf_dist=3,**kwargs)
        sidx = skp.query('x >= {} and x <= {} and y >= {} and y <= {}'.format(minsx, maxsx, minsy, maxsy)).index
        didx = dkp.query('x >= {} and x <= {} and y >= {} and y <= {}'.format(mindx, maxdx, mindy, maxdy)).index
        # If the candidates < k, OpenCV throws an error
        if len(sidx) >= k and len(didx) >=k:
        if len(sidx) > k and len(didx) > k:
            match(self, aidx=sidx, bidx=didx)
            match(self, aidx=didx, bidx=sidx)
+5 −5
Changes for autocnet/matcher/cpu_extractor.py: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@ except Exception: # pragma: no cover
    pass


def extract_features(array, method='orb', extractor_parameters={}):
def extract_features(array, extractor_method='sift', extractor_parameters={}):
    """
    This method finds and extracts features from an image using the given dictionary of keyword arguments.
    The input image is represented as NumPy array and the output features are represented as keypoint IDs
@@ -25,7 +25,7 @@ def extract_features(array, method='orb', extractor_parameters={}):
    array : ndarray
            a NumPy array that represents an image

    method : {'orb', 'sift', 'fast', 'surf', 'vl_sift'}
    extractor_method : {'orb', 'sift', 'fast', 'surf', 'vl_sift'}
              The detector method to be used.  Note that vl_sift requires that
              vlfeat and cyvlfeat dependencies be installed.

@@ -45,10 +45,10 @@ def extract_features(array, method='orb', extractor_parameters={}):
                 'surf': cv2.xfeatures2d.SURF_create,
                 'orb': cv2.ORB_create}

    if method == 'vlfeat' and vlfeat != True:
    if extractor_method == 'vlfeat' and vlfeat != True:
        raise ImportError('VLFeat is not available.  Please install vlfeat or use a different extractor.')

    if  method == 'vlfeat':
    if  extractor_method == 'vlfeat':
        keypoint_objs, descriptors  = vl.sift.sift(array,
                                                   compute_descriptor=True,
                                                   float_descriptors=True)
@@ -59,7 +59,7 @@ def extract_features(array, method='orb', extractor_parameters={}):
        # OpenCV requires the input images to be 8-bit
        if not array.dtype == 'int8':
            array = bytescale(array)
        detector = detectors[method](**extractor_parameters)
        detector = detectors[extractor_method](**extractor_parameters)
        keypoint_objs, descriptors = detector.detectAndCompute(array, None)

        keypoints = np.empty((len(keypoint_objs), 7), dtype=np.float32)
+75 −3
Changes for autocnet/matcher/cpu_matcher.py: 75 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,81 @@ FLANN_INDEX_KDTREE = 1 # Algorithm to set centers,
DEFAULT_FLANN_PARAMETERS = dict(algorithm=FLANN_INDEX_KDTREE, trees=3)


def match(self, k=2, **kwargs):
    """
    Given two sets of descriptors, utilize a FLANN (Approximate Nearest
    Neighbor KDTree) matcher to find the k nearest matches.  Nearness is
    the euclidean distance between descriptors.

    The matches are then added as an attribute to the edge object.

    Parameters
    ----------
    k : int
	The number of neighbors to find
    """

    def _add_matches(matches):
        """
        Given a dataframe of matches, either append to an existing
        matches edge attribute or initially populate said attribute.

        Parameters
        ----------
        matches : dataframe
                  A dataframe of matches
        """
        if self.matches is None:
            self.matches = matches
        else:
            df = self.matches
            self.matches = df.append(matches,
                                     ignore_index=True,
                                     verify_integrity=True)

    def mono_matches(a, b, aidx=None, bidx=None):
        """
	    Apply the FLANN match_features

    	Parameters
    	----------
    	a : object
    	    A node object

    	b : object
    	    A node object

    	aidx : iterable
    		An index for the descriptors to subset

    	bidx : iterable
    		An index for the descriptors to subset
    	"""
    	# Subset if requested
        if aidx is not None:
            ad = a.descriptors[aidx]
        else:
            ad = a.descriptors

        if bidx is not None:
            bd = b.descriptors[bidx]
        else:
            bd = b.descriptors

        # Load, train, and match
        fl.add(ad, a['node_id'], index=aidx)
        fl.train()
        matches = fl.query(bd, b['node_id'], k, index=bidx)
        _add_matches(matches)
        fl.clear()

    fl = FlannMatcher()
    mono_matches(self.source, self.destination, **kwargs)
    mono_matches(self.destination, self.source, **kwargs)

    self.matches.sort_values(by=['distance'])


class FlannMatcher(object):
    """
    A wrapper to the OpenCV Flann based matcher class that adds
@@ -122,6 +197,3 @@ class FlannMatcher(object):
        return pd.DataFrame(matched, columns=['source_image', 'source_idx',
                                              'destination_image', 'destination_idx',
                                              'distance']).astype(np.float32)

def cudamatcher():
    pass
+3 −0
Changes for autocnet/matcher/cuda_extractor.py: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@ import warnings
import cudasift as cs

def extract_features(array, nfeatures=None):
    """
    A custom docstring.
    """
    if not nfeatures:
        nfeatures = int(max(array.shape) / 1.75)
    else:
Loading