我想使用OpenImaj Library从图像中提取 BOVW 。
我在实现 BagOfVisualWords 类的 extractFeatureFromQuantised 方法时遇到了错误
Exception in thread "main" java.lang.IllegalArgumentException: length must be > 0
at org.openimaj.util.array.SparseBinSearchIntArray.<init>
(SparseBinSearchIntArray.java:94)
at org.openimaj.util.array.SparseBinSearchIntArray.<init>
(SparseBinSearchIntArray.java:85)
at org.openimaj.feature.SparseIntFV.<init>(SparseIntFV.java:64)
at org.openimaj.image.feature.local.aggregate.BagOfVisualWords.
extractFeatureFromQuantised (BagOfVisualWords.java:106)
该方法中使用的以下实体
(BagOfVisualWords.java:106)
public static <L extends Location>
SparseIntFV
extractFeatureFromQuantised(Collection<QuantisedLocalFeature<L>> qfeatures)
{
final SparseIntFV fv = new SparseIntFV();
for (final QuantisedLocalFeature<L> qf : qfeatures) {
fv.values.increment(qf.id, 1);
}
return fv;
}
(SparseIntFV.java:64)
public SparseIntFV() {
values = new SparseBinSearchIntArray(0);
}
/**
* Construct empty FV with given number of bins
* @param nbins the number of bins in each dimension
*/
public SparseIntFV(int nbins) {
values = new SparseBinSearchIntArray(nbins);
}
在 org.openimaj.util.array.SparseBinSearchIntArray。
/**
* Construct the array with the given length
* @param length the length
*/
public SparseBinSearchIntArray(int length) {
this(length, DEFAULT_CAPACITY);
}
/**
* Construct the array with the given length and capacity for non-zero elements
* @param length the length
* @param capacity the capacity
*/
public SparseBinSearchIntArray(int length, int capacity) {
if (length <= 0) throw new IllegalArgumentException("length must be > 0");
if (capacity <= 0) throw new IllegalArgumentException
("capacity must be > 0");
this.length = length;
this.keys = new int[capacity];
this.values = new int[capacity];
}