Java 我如何使用peak_检测功能-Android studio
我试图使用函数,但遇到了一些错误。我想用这个函数从FastICA实现中实时检测android摄像头的RGB图像的峰值。我在第一个参数中使用了Java 我如何使用peak_检测功能-Android studio,java,android,Java,Android,我试图使用函数,但遇到了一些错误。我想用这个函数从FastICA实现中实时检测android摄像头的RGB图像的峰值。我在第一个参数中使用了Double[]Green=ArrayUtils.toObject(arrayGreen)FastICA的输出工作正常。我使用的是double delta=10编码到第二个参数中即可。我在使用第三个参数时遇到了问题,因为我不明白我需要的第三个参数是什么。 我试图创建一个List index=new ArrayList()但不工作。有人能帮我吗? 提前谢谢 我
Double[]Green=ArrayUtils.toObject(arrayGreen)代码>FastICA的输出工作正常。我使用的是double delta=10将>编码到第二个参数中即可。我在使用第三个参数时遇到了问题,因为我不明白我需要的第三个参数是什么。
我试图创建一个List index=new ArrayList()代码>但不工作。有人能帮我吗?
提前谢谢
我正在尝试的代码:
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public abstract class CustomUtils {
/**
* Detects peaks (calculates local minima and maxima) in the
* vector <code>values</code>. The resulting list contains
* maxima at the first position and minima at the last one.
*
* Maxima and minima maps contain the indice value for a
* given position and the value from a corresponding vector.
*
* A point is considered a maximum peak if it has the maximal
* value, and was preceded (to the left) by a value lower by
* <code>delta</code>.
*
* @param values Vector of values for whom the peaks should be detected
* @param delta The precedor of a maximum peak
* @param indices Vector of indices that replace positions in resulting maps
* @return List of maps (maxima and minima pairs) of detected peaks
*/
public static <U> List<Map<U, Double>> peak_detection(List<Double> values, Double delta, List<U> indices)
{
assert(indices != null);
assert(values.size() != indices.size());
Map<U, Double> maxima = new HashMap<U, Double>();
Map<U, Double> minima = new HashMap<U, Double>();
List<Map<U, Double>> peaks = new ArrayList<Map<U, Double>>();
peaks.add(maxima);
peaks.add(minima);
Double maximum = null;
Double minimum = null;
U maximumPos = null;
U minimumPos = null;
boolean lookForMax = true;
Integer pos = 0;
for (Double value : values) {
if (value > maximum || maximum == null) {
maximum = value;
maximumPos = indices.get(pos);
}
if (value < minimum || minimum == null) {
minimum = value;
minimumPos = indices.get(pos);
}
if (lookForMax) {
if (value < maximum - delta) {
maxima.put(maximumPos, value);
minimum = value;
minimumPos = indices.get(pos);
lookForMax = false;
}
} else {
if (value > minimum + delta) {
minima.put(minimumPos, value);
maximum = value;
maximumPos = indices.get(pos);
lookForMax = true;
}
}
pos++;
}
return peaks;
}
/**
* Detects peaks (calculates local minima and maxima) in the
* vector <code>values</code>. The resulting list contains
* maxima at the first position and minima at the last one.
*
* Maxima and minima maps contain the position for a
* given value and the value itself from a corresponding vector.
*
* A point is considered a maximum peak if it has the maximal
* value, and was preceded (to the left) by a value lower by
* <code>delta</code>.
*
* @param values Vector of values for whom the peaks should be detected
* @param delta The precedor of a maximum peak
* @return List of maps (maxima and minima pairs) of detected peaks
*/
public static List<Map<Integer, Double>> peak_detection(List<Double> values, Double delta)
{
List<Integer> indices = new ArrayList<Integer>();
for (int i=0; i<values.size(); i++) {
indices.add(i);
}
return ANPRUtils.peak_detection(values, delta, indices);
}
}
编辑
在第一个函数中使用第二个函数时,我遇到了以下错误:
第三个参数有点奇怪——它是对应的最小值和最大值的名称列表。假设数据中的位置1处有1,然后将第三个参数与列表(“a”、“B”、“C”)一起传递给它。返回值将是一个映射(“B”->最大值)
这是奇怪的代码,我不知道他们为什么那样做。这似乎是一种很不方便的做事方式。另外,我认为如果index.size()
请注意,函数的2值版本正在传递(1,2,3,4,…n)数组,其中n是数据中的值数。在这种情况下,返回值将是(位置索引->最大值/最小值)的映射。这似乎是您使用此功能的唯一方法。谢谢Gabe Sechan。如果我试图声明List index=new ArrayList();在facetracking函数中,我尝试实现类似于第二个版本的for循环,但我也遇到了错误。我将编辑一个屏幕的错误它返回一个地图。您正在尝试将其存储在一个双[]中。那不行,原因很明显。是的,我知道。使用:List peack=PeakDetect.peak_检测(绿名单、增量、指数);我没有错误,但运行代码时遇到了一个新问题:com.google.android.gms.samples.vision.face.rPPG.PeakDetect.peak_detection(PeakDetect.java:29)上的java.lang.NullPointerException,您对这个问题有什么建议吗?