Beispiel #1
0
def ArraysToDelfFeatures(locations,
                         scales,
                         descriptors,
                         attention,
                         orientations=None):
    num_features = len(attention)
    assert num_features == locations.shape[0]
    assert num_features == len(scales)
    assert num_features == descriptors.shape[0]

    if orientations is None:
        orientations = np.zeros([num_features], dtype=np.float32)
    else:
        assert num_features == len(orientations)

    delf_features = feature_pb2.DelfFeatures()
    for i in xrange(num_features):
        delf_feature = delf_features.feature.add()
        delf_feature.y = locations[i, 0]
        delf_feature.x = locations[i, 1]
        delf_feature.scale = scales[i]
        delf_feature.orientation = orientations[i]
        delf_feature.strength = attention[i]
        delf_feature.descriptor.CopyFrom(
            datum_io.ArrayToDatum(descriptors[i, ]))

    return delf_features
Beispiel #2
0
def ParseFromString(string):
    """Converts serialized DelfFeatures string to numpy arrays.

  Args:
    string: Serialized DelfFeatures string.

  Returns:
    locations: [N, 2] float array which denotes the selected keypoint
      locations. N is the number of features.
    scales: [N] float array with feature scales.
    descriptors: [N, depth] float array with DELF descriptors.
    attention: [N] float array with attention scores.
    orientations: [N] float array with orientations.
  """
    delf_features = feature_pb2.DelfFeatures()
    delf_features.ParseFromString(string)
    return DelfFeaturesToArrays(delf_features)
Beispiel #3
0
def ArraysToDelfFeatures(locations,
                         scales,
                         descriptors,
                         attention,
                         orientations=None):
    """Converts DELF features to DelfFeatures proto.

  Args:
    locations: [N, 2] float array which denotes the selected keypoint
      locations. N is the number of features.
    scales: [N] float array with feature scales.
    descriptors: [N, depth] float array with DELF descriptors.
    attention: [N] float array with attention scores.
    orientations: [N] float array with orientations. If None, all orientations
      are set to zero.

  Returns:
    delf_features: DelfFeatures object.
  """
    num_features = len(attention)
    assert num_features == locations.shape[0]
    assert num_features == len(scales)
    assert num_features == descriptors.shape[0]

    if orientations is None:
        orientations = np.zeros([num_features], dtype=np.float32)
    else:
        assert num_features == len(orientations)

    delf_features = feature_pb2.DelfFeatures()
    for i in range(num_features):
        delf_feature = delf_features.feature.add()
        delf_feature.y = locations[i, 0]
        delf_feature.x = locations[i, 1]
        delf_feature.scale = scales[i]
        delf_feature.orientation = orientations[i]
        delf_feature.strength = attention[i]
        delf_feature.descriptor.CopyFrom(
            datum_io.ArrayToDatum(descriptors[i, ]))

    return delf_features
Beispiel #4
0
def ParseFromString(string):
    delf_features = feature_pb2.DelfFeatures()
    delf_features.ParseFromString(string)
    return DelfFeaturesToArrays(delf_features)