我只是在为以下代码寻找一种有效的方法,因为我收到堆栈溢出错误,我提供了尽可能多的信息,但也许你不需要所有这些解释,但代码本身就足够了,任何帮助都是感谢让我摆脱这个错误;
我正在尝试将运算符(Hueckel 边缘检测运算符)一次应用于 9x9 区域并为整个图像重复它。所以它是一个常规的边缘检测基础。您可以在第二张图片中看到我的意思。
函数 a() 在另一个名为 Hueckel_operator() 的函数中被调用 8 次,hueckel_operator 是一个递归函数,每次都为 x 和 y 参数调用 +5。这意味着 a() 几乎被称为大图像和真正的问题 MyImage[] 这是一个 emgucv Image<> 对象。因为 MyImage[] 应该检查 9x9 矩阵中的每个像素并带上它的值,所以它被调用的次数是函数 a() 的 69 * j 倍。
函数 input_i_y() 带来 y 坐标,还有另一个名为 input_i_x() 的函数带来 9x9 矩阵的 x 坐标。我知道,为了将它们用作另一个函数的参数,创建两个单独的函数是极端的,但我找不到更好的解决方案。HueckelDisk 类根据 x,y 坐标计算 9 个不同的 Hueckel 圆盘的公式。根据拟合精度,我们可以确定是否有边缘。
这是hueckel_operator()的终止条件
if (mod_width + counter4 + 10 >= MyImage.Width && mod_height + counter5 + 10 >= MyImage.Height)
{
goto EXIT2;
}
这是hueckel_operator()的开始和结束
public void hueckel_operator(int counter2, int counter3)
{
counter2 = counter4;
counter3 = counter5;
int mod_width = MyImage.Width % 5;
int mod_height = MyImage.Height % 5;
if (mod_width + counter4 + 10 >= MyImage.Width && mod_height + counter5 + 10 >= MyImage.Height)
{
goto EXIT2;
}
else
{
if (mod_width + counter4 + 10 >= MyImage.Width)
{
if (counter5 == 1)
{
counter5 += 4;
}
else
{
counter5 += 5;
}
counter4 = 1;
}
if (counter4 == 1)
{
counter4 += 4;
}
else if(counter4 != 0)
{
counter4 += 5;
}
if (counter5 == 0 && counter4 == 0)
{
counter4 = 1;
counter5 = 1;
}
}
这是hueckel_operator()的结尾;
出口:
hueckel_operator(counter5, counter4);
EXIT2:
MessageBox.Show("done");
}
这是函数 a()
public double a(int j, int counter6, int counter7)
{
double result = 0;
HueckelDisks hueckel_formula = new HueckelDisks();
counter6 = counter4;
counter7 = counter5;
for (int II = 0; II <= j ; II++)
{
for (KK = 1; KK < 69; KK++)
{
result += hueckel_formula.HueckelDisk(input_i_x(KK),input_i_y(KK),j) * MyImage[point_a, point_b].Intensity;
}
}
return result;
}
public int input_i_y(int y)
{
Tuple<int, int>[] myArray =
{
Tuple.Create(3,1),Tuple.Create(4,1),Tuple.Create(5,1),Tuple.Create(6,1),Tuple.Create(7,1),Tuple.Create(2,2),
Tuple.Create(3,2),Tuple.Create(4,2),Tuple.Create(5,2),Tuple.Create(6,2),Tuple.Create(7,2),Tuple.Create(8,2),
Tuple.Create(1,3),Tuple.Create(2,3),Tuple.Create(3,3),Tuple.Create(4,3),Tuple.Create(5,3),Tuple.Create(6,3),
Tuple.Create(7,3),Tuple.Create(8,3),Tuple.Create(9,3),Tuple.Create(1,4),Tuple.Create(2,4),Tuple.Create(3,4),
Tuple.Create(4,4),Tuple.Create(5,4),Tuple.Create(6,4),Tuple.Create(7,4),Tuple.Create(8,4),Tuple.Create(9,4),
Tuple.Create(1,5),Tuple.Create(1,5),Tuple.Create(2,5),Tuple.Create(3,5),Tuple.Create(4,5),Tuple.Create(5,5),
Tuple.Create(6,5),Tuple.Create(7,5),Tuple.Create(8,5),Tuple.Create(9,5),Tuple.Create(1,6),Tuple.Create(2,6),
Tuple.Create(3,6),Tuple.Create(4,6),Tuple.Create(5,6),Tuple.Create(6,6),Tuple.Create(7,6),Tuple.Create(8,6),
Tuple.Create(8,6),Tuple.Create(1,7),Tuple.Create(2,7),Tuple.Create(3,7),Tuple.Create(4,7),Tuple.Create(5,7),
Tuple.Create(6,7),Tuple.Create(7,7),Tuple.Create(8,7),Tuple.Create(9,7),Tuple.Create(2,8),Tuple.Create(3,8),
Tuple.Create(4,8),Tuple.Create(5,8),Tuple.Create(6,8),Tuple.Create(7,8),Tuple.Create(8,8),Tuple.Create(3,9),
Tuple.Create(4,9),Tuple.Create(5,9),Tuple.Create(6,9),Tuple.Create(7,9),
};
return myArray[y].Item2;
}