Java – Canny edge detector for Android – recursive function on stackoverflow

I'm working on an augmented reality app for Android I'm implementing Tom gibara's Canny edge detector class and replacing bufferedimage with bitmap, which is not supported by Android

The method "follow" (published below) causes a stackoverflow error This is a recursive function, but what puzzles me is that it will work normally about 10-15 seconds before the crash

From Google's point of view, people have successfully implemented this class in Java, but I want to know that it doesn't work on Android for any reason Gibara's code specifies that it is only used for single thread; Could this be part of the problem? If not, is my mistake 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;  
            }  
        }  
    }  
}

Solution

Android's default thread stack is much smaller than what you get on the desktop In the current Android Version (2.3), I think the stack size is set to 12KB Your recursion is too deep

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>