4
我正在为Android设计增强现实应用程序。我正在实施Tom Gibara的canny edge detector class,并用Bitmap替换了Android不支持的BufferedImage。Android的Canny边缘检测器 - 递归函数的StackOverflow
方法“跟随”(发布如下)正在为我造成StackOverflow错误。这是一个递归函数,但让我感到困惑的是它会在设备上崩溃前正常工作大约10-15秒。
从谷歌看来,人们已经成功地在Java中实现了这个类,但是我想知道,无论出于何种原因,它不适用于Android。 Gibara的代码指定它仅用于单线程;这可能是问题的一部分吗?如果不是这样,我的错误对任何人都是明显的吗?
谢谢!
private void follow(int x1, int y1, int i1, int threshold) {
int x0 = x1 == 0 ? x1 : x1 - 1;
int x2 = x1 == width - 1 ? x1 : x1 + 1;
int y0 = y1 == 0 ? y1 : y1 - 1;
int y2 = y1 == height -1 ? y1 : y1 + 1;
data[i1] = magnitude[i1];
for (int x = x0; x <= x2; x++) {
for (int y = y0; y <= y2; y++) {
int i2 = x + y * width;
if ((y != y1 || x != x1) && data[i2] == 0
&& magnitude[i2] >= threshold) {
follow(x, y, i2, threshold);
return;
}
}
}
}
谢谢!我会四处寻找适合Android手机的合适堆栈深度。对于任何对解决方案感兴趣的人,请查看该项目的Android源代码:http://www.jarkman.co.uk/catalog/robots/sketchy.htm 他将这行代码添加到他的follow函数中,每次调用时传递一个深度变量。 if(depth> mFollowStackDepth) \t \t \t return; – Allison 2011-01-31 19:51:27