简体   繁体   English

适用于Android的Canny边缘检测器 - StackOverflow上的递归函数

[英]Canny edge detector for Android — StackOverflow on recursive function

I'm working on an augmented reality app for Android. 我正在为Android增强现实应用程序。 I'm implementing Tom Gibara's canny edge detector class and have replaced BufferedImage, which is not supported by Android, with Bitmap. 我正在实现Tom Gibara的canny边缘检测器类,并用Bitmap替换了Android不支持的BufferedImage。

The method "follow" (posted below) is causing a StackOverflow error for me. 方法“follow”(在下面发布)导致StackOverflow错误。 It's a recursive function, but what baffles me is that it will work correctly for about 10-15 seconds before crashing, on the device. 这是一个递归函数,但令我感到困惑的是,它会在崩溃之前大约10-15秒正常工作。

From Google, it looks like people have successfully implemented this class in Java, but I'm wondering if, for whatever reason, it doesn't work on Android. 从Google看来,人们已经成功地用Java实现了这个类,但我想知道,无论出于何种原因,它在Android上都不起作用。 Gibara's code specifies that it is for single-threaded use only; Gibara的代码指定它仅用于单线程使用; could this be part of the problem? 这可能是问题的一部分吗? If not that, is my error obvious to anyone? 如果不是这样,我的错误是否明显对任何人?

Thank you! 谢谢!

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's default thread stack is much smaller than what you get on a desktop. Android的默认线程堆栈比您在桌面上获得的要小得多。 In current Android builds (2.3), the stack size is set to 12kB I believe. 在当前的Android版本(2.3)中,我认为堆栈大小设置为12kB。 Your recursion is simply too deep. 你的递归太深了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM