Exemplo n.º 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
Exemplo n.º 2
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