0

Android 用のモーション検出アプリケーションを作成しています。検出アルゴリズムに問題がありますが:

public boolean compareBitmaps()
{

    /*I'm creating 2 x 2D arrays which will continually be repopulated 
    every 2 frames with the pixel data of that frame based on even or odd
    (frames are collected in an ArrayList 'BIT') 
    BIT(0) will be stored in compare1
    BIT(1) will be stored in compare2
    BIT(2) will be stored in compare1 and so on...*/

    int [][] compare1 = new int[width][height];
    int [][] compare2 = new int[width][height];
    int bmpCount = BIT.size();

    boolean noMotion = true;

    //This is where I determine wheter even or odd using the modulus %
    for (int x=0; x<bmpCount; x++)
        if(x%2!=0)
        {

                System.out.println("Odd");
                getPixels1(compare1, x);

        }
        else
        {

                System.out.println("Even");
                getPixels2(compare2, x);

        }

        //Here I'm looking to continually compare the returned pixel colours
        // of the 2D arrays
        if(!Arrays.deepEquals(compare1, compare2))
        {
            System.out.println("No Motion");
            return noMotion = false;

        }
        else
        {
        return noMotion = true;
        }
}

private void getPixels1(int[][] compare1, int x) 
{
    for(int i = 0; i<width; i++)
    {
        for(int j=0; j<height; j++)
        {

            compare1[j][i] = BIT.get(x).getPixel(j, i);

        }
    }
}

private void getPixels2(int[][] compare2, int x) 
{
    for(int i = 0; i<width; i++)
    {
        for(int j=0; j<height; j++)
        {
            compare2[j][i] = BIT.get(x).getPixel(j, i);
        }
    }
}

私はprintln()デバッグを支援するために使用しています。そして、次のステップでアプリケーションが壊れます。

誰でも私が間違っていることを見ることができますか、助けていただければ幸いです

どうもありがとう、

4

1 に答える 1

3

あなたの論理は逆です。

ifx % 2が返される場合は、が 2 で割り切れ、余りがないこと0を意味します。x

4 % 2 = 0 // even
5 % 2 = 1 // odd
于 2012-12-11T19:33:22.363 に答える