我在我的应用程序中使用Digital Persona SDK来进行指纹识别,当我在少于250个fmds上使用identify函数时,它工作正常。
Engine.Candidate candidates[] = m_engine.Identify(searchedFmd, 0, fmdArray, DEFAULT_THRESHOLD, 1); //fmdArray < 250
但当fmdArray > 250时,它给我一个本地运行时错误。
A/art: art/runtime/indirect_reference_table.cc:132] JNI ERROR (app bug): local reference table overflow (max=512)
现在,我在几台安卓设备上运行这个应用,得出的结论是,当我的应用在安卓7上运行时,我的应用用fmdArray > 250就会崩溃,但安卓8却能正常运行。在8中,我可以预先对4000个fmds进行检查,而且工作正常。
但我需要在一个特定的设备上运行这段代码,那就是运行Android 7。
我试着在几个线程中运行它,只有250个fmds。但在单次运行后,SDK又出现了另一个问题。在第二次运行时,它不工作。
我是这样做的:首先,我得到一个我想识别的指纹捕获。
Reader.CaptureResult capture = m_reader.Capture(fidFormat, UrUSDK.DefaultImageProcessing, m_DPI, timeout);
// In second run, code after this line is not executed.
// My guees its not coming back from native. No exeptions. No errors.
...
Fmd scannedFmd = m_engine.CreateFmd(capture.image, fmdFormat);
...
int index = identifyFinger(fmds, scannedFmd);
...
private int identifyFinger(List<Fmd> fmdSearchArray, Fmd scannedFmd) {
List<List<Fmd>> lists = splitToChunks(fmdSearchArray);
AtomicInteger index = new AtomicInteger(-1);
List<Callable<Void>> threads = new ArrayList<>(lists.size());
AtomicInteger iteratorIndex = new AtomicInteger(0);
for (int i = 0; i < lists.size(); i++) {
int currentChunk = i;
Callable<Void> thread = () -> {
System.out.println(Thread.currentThread().getName() + " with chunk: " + iteratorIndex.getAndIncrement());
Fmd[] fmds = lists.get(currentChunk).toArray(new Fmd[IDENTIFY_BOUNDARY]);
try {
Engine.Candidate[] candidates = m_engine.Identify(scannedFmd, 0, fmds, threshold, 1);
if (candidates.length > 0) {
index.set(candidates[0].fmd_index + (currentChunk * IDENTIFY_BOUNDARY));
}
} catch (UareUException e) {
}
System.out.println(Thread.currentThread().getName() + " with chunk: " + currentChunk + " finished!");
return null;
};
threads.add(thread);
}
try {
List<Future<Void>> futures = executorService.invokeAll(threads);
System.out.println("All threads finished: " + index.get());
return index.get();
} catch (InterruptedException e) {
e.printStackTrace();
return -1;
}
}
...
private List<List<Fmd>> splitToChunks(List<Fmd> fmdSearchArray) {
int size = fmdSearchArray.size();
List<List<Fmd>> lists;
if (size > IDENTIFY_BOUNDARY) {
int chunks = size / IDENTIFY_BOUNDARY;
if (size % IDENTIFY_BOUNDARY > 0) {
chunks++;
}
lists = new ArrayList<>(chunks);
for (int i = 0; i < chunks; i++) {
if (i + 1 == chunks) {
lists.add(new ArrayList<>(fmdSearchArray.subList(i * IDENTIFY_BOUNDARY, size)));
break;
}
lists.add(new ArrayList<>(fmdSearchArray.subList(i * IDENTIFY_BOUNDARY, (i + 1) * IDENTIFY_BOUNDARY)));
}
} else {
lists = new ArrayList<>(1);
lists.add(fmdSearchArray);
}
return lists;
}
这段代码的问题是,它只运行了一次。但在另一次尝试中,它并没有从Caprture调用的原生代码中返回。
所以我的问题是:我如何克服这个问题,让它在我的java代码中工作?或者至少解决的方向是什么?
其根本原因是 Identify
函数在每一个返回的 Candidate
推送到结果数组后。它应该在推送后释放引用,这样它对(有限的)本地引用表的使用就会保持不变。你应该提交一个关于这个问题的 bug。
目前最简单的变通方法是将你的 fmdArray
成250个大小的块,并称 Identify
对于每个块。