1

所以在我的情况下,我应该向 computeQuantisedFeatures 方法提供两个参数,第二个是类型

        List<LocalFeature<Location, ? extends ArrayFeatureVector<byte[]>>>

我尝试传递我的类型的 imagekeypoints 列表

    LocalFeatureList<Keypoint>

并且

    List<LocalFeature<KeypointLocation, ByteFV>> features = null;
    for (java.util.Iterator<Keypoint> iter = imageKeypoints.iterator(); iter.hasNext();)
    {features.add((LocalFeature<KeypointLocation, ByteFV>)iter.next());}

但我总是得到著名的错误

    The method computeQuantisedFeatures(HardAssigner<T,?,?>, List<LocalFeature<L,? 
    extends ArrayFeatureVector<T>>>) in the type BagOfVisualWords is not applicable for
    the arguments (HardAssigner<byte[],capture#3-of ?,capture#4-of ?>, 
    List<LocalFeature<KeypointLocation,ByteFV>>)
4

2 回答 2

1

注意:我将此答案基于此处Keypoint的来源。

这个问题源于泛型不是 covariant的事实。该方法需要 a List<LocalFeature<L, ? extends ArrayFeatureVector<T>>>,但您提供的是List<Keypoint>. 如果该方法List<? extends LocalFeature<L, ? extends ArrayFeatureVector<T>>>取而代之,那将是一个合法的调用。

最简单的解决方案是将 的内容复制imagekeypoints到新创建的内容中,List<LocalFeature<KeypointLocation, ByteFV>>然后将其传递给调用。

于 2013-03-11T16:38:25.657 回答
1

正如 Paul Bellora 所指出的,这实际上是该方法的泛型中的一个错误。我刚刚提交了一个修复程序,该修复程序将1.1.1-SNAPSHOT很快在版本中提供。临时解决方案是在您的类中实现正确版本的computeQuantisedFeatures方法,如下所示:

public static <L extends Location, T> List<QuantisedLocalFeature<L>> computeQuantisedFeatures(
    HardAssigner<T, ?, ?> assigner,
    List<? extends LocalFeature<L, ? extends ArrayFeatureVector<T>>> features)
{
    final List<QuantisedLocalFeature<L>> out = new ArrayList<QuantisedLocalFeature<L>>(features.size());

    for (final LocalFeature<L, ? extends ArrayFeatureVector<T>> f : features) {
        final int idx = assigner.assign(f.getFeatureVector().values);
        out.add(new QuantisedLocalFeature<L>(f.getLocation(), idx));
    }

    return out;
}
于 2013-03-12T12:44:46.170 回答