I am working on Augmented Reality for Android. I am implementing Tom Gibara's rugged edge detection class and have replaced the BufferedImage, which is not supported by Android, with Bitmap.
The follow method (see below) causes a StackOverflow error for me. This is a recursive function, but what puzzles me is that it will work correctly about 10-15 seconds before the device crashes.
From Google, it seems that people have successfully implemented this class in Java, but I wonder if for some reason it does not work on Android. The Gibara code indicates that it is for single-threaded use only; could this be part of the problem? If this is not so, is my mistake obvious to everyone?
Thanks!
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; } } } }
source share