我正在研究一种算法来拍摄图像并分离黑白像素块,不幸的是,它似乎总是溢出堆栈。这是可疑的类:
package me.dylan.eat;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class Cell {
public Point location = new Point(0, 0);
public Cell(int x, int y) {
location.x = x;
location.y = y;
}
public void recurseNeighbors(ArrayList<Cell> universe, BufferedImage img) {
if (!universe.contains(this)) {
universe.add(this);
ArrayList<Cell> neighbors = CellUtil.assimilateNeighbors(location, img, new Rectangle(0,0,0,0));
//get all neighbors of the same color
for (Cell c : neighbors) {
if (!universe.contains(c)) {
c.recurseNeighbors(universe, img);
}
}
}
}
}
编辑:图像是 640x480,是不是太大了?在第 23 行抛出异常。