質問

デバッグのスクリーンショット: http://img1.uploadscreenshot.com/images/orig/12/36121481470-Orig.jpg

x、yに値があることに注意してください(xとyがforループで69で停止した理由はわかりません - xは86に、yから183まで上がったはずです)が、rにはまったく値がありません。 (変数は存在しませんか?何ですか?)これを修正するにはどうすればよいですか?

読みたい場合はコード:

        public float[] cht(int[,] matrix)
    {
        float[] xyrd = new float[4];
        int xthreshold, ythreshold;
        float slope;
        double dir;
        float zone;
        int[] limitsStorage = new int[3] { matrix.GetLength(0), matrix.GetLength(1), matrix.GetLength(0) / 2 - 10 };
        short[,,] accumulator = new short[limitsStorage[0]+1, limitsStorage[1]+1,limitsStorage[2]+1];
        for (int x = 0; x < limitsStorage[0]; x++)
        { //first dimension loop of matrix 100
            for (int y = 0; y < limitsStorage[1]; y++)
            { //second dimension loop of matrix 120
                if (matrix[x, y] == 225)
                {//the data at the for loop location is a 1 and not 0 hit.
                    xthreshold = x - limitsStorage[0] / 2;
                    ythreshold = y - limitsStorage[1] / 2;
                    //forget angle, search slope: float angle = xthreshold > 0 ? ((float)Math.Atan2(xthreshold, ythreshold)) : ((float)Math.Atan2(xthreshold, ythreshold) + 180);
                    slope = xthreshold / ythreshold;
                    //initiate if loops.
                    dir = 180 + Math.Round(Math.Atan2(ythreshold, xthreshold) * 57.2957 / 45, 0) * 45 + 45 * (Math.Round(((Math.Atan2(ythreshold, xthreshold) * 57.2957) % 45) / 45));
                    if (slope > .404 || slope < -.404)
                    {
                        if (slope < 2.3558 || slope > -2.3558)
                        {
                            if (xthreshold > 0)
                            {
                                if (ythreshold > 0)
                                {
                                    //+x+y zone
                                    zone = 45 + 180;
                                }
                                else
                                {
                                    //+x-y zone
                                    zone = 180 - 45;
                                }
                            }
                            else
                            {
                                if (ythreshold > 0)
                                {
                                    //-x+y zone
                                    zone = 360 - 45;
                                }
                                else
                                {
                                    //-x-y zone
                                    zone = 45;
                                }
                            }
                        }
                        else if (ythreshold > 0)
                        {
                            //+y zone
                            zone = 360 - 90;
                        }
                        else
                        {
                            //-y zone
                            zone = 90;
                        }
                    }
                    else if (xthreshold > 0)
                    {
                        //+x zone
                        zone = 180;
                    }
                    else
                    {
                        //-x zone
                        zone = 0;
                    }
                    for (int R = 6; R < limitsStorage[2]; R++)
                    { //Radius loop for scan 44
                        float delta = (float)((1 / R) * 57.2957);
                        for (float Theta = zone - 25; Theta < zone + 25; Theta += delta)
                        {
                            accumulator[(int)(((R * Math.Cos(Theta / 57.2957)) < 0 || (R * Math.Cos(Theta / 57.2957)) > limitsStorage[0]) ? 0 : R * Math.Cos(Theta / 57.2957)), (int)(((R * Math.Sin(Theta / 57.2957)) < 0 || (R * Math.Sin(Theta / 57.2957)) > limitsStorage[1]) ? 0 : R * Math.Sin(Theta / 57.2957)),R]++;
                            //btw, 0,0,R is always the non-center area.
                        }
                    }

                }
            }
        }

        for (int x = 1; x < limitsStorage[0]; x++)
        {
            for (int y = 1; y < limitsStorage[1]; y++)
            {
                for (int r = 6; r < limitsStorage[2]; r++)
                {
                    if (xyrd[3] > accumulator[x, y, r])
                    {
                        xyrd[0] = x;
                        xyrd[1] = y;
                        xyrd[2] = r;
                        xyrd[3] = accumulator[x, y, r];
                    }
                }
            }
        }

        if (accPrint)
        {
            //do something for debugging?
            accPrint = false;
        }
        return xyrd;
    }
役に立ちましたか?

解決

私はちょうどそれに気づきました xy それらの下に小さなロックシンボルがあり、あなたが名前が付けられていることを示しています xy この方法が実行されているクラスで。それらはです xy デバッガーで見ていること。

r ループが宣言されているループを終了したため、適切に範囲外です。

ところで、 xy 途方もなく悪いメンバー変数名であり、途方もなく悪い名前です for タイプのループ変数 int, 、特に、それらが名前付きのメンバー変数があるクラスに含まれている場合 xy.

他のヒント

あなたが宣言する唯一の場所 r の中に for 声明、そうですか?それは意味します r ループが終了するとすぐに範囲外になります。そのため、機能のHE終了時に変数を検査すると、当然のことながら、 r そこにはいません。

告白私は理由がわからない xy コメントに基づいて範囲にあります。それらはクラス変数である可能性がありますが、尋ね手はそうではありません。しかし、それが私が考えることができる唯一の説明です。

動作は奇妙ではありません - 実際にあなたが期待するものを正確に手に入れます。

時計ウィンドウは、正確にあなたに値を表示できることに注意してください 範囲内 ブレークポイントで。

強調表示されたブレークポイントでは、アキュムレータ[x、y、r]のみが範囲にあり、期待した値が正確に表示されます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top