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()用来帮助我调试, - 目前控制台打印“奇数”(如果我错了,请纠正我)对于元素(0)是错误的?当我下一步越过应用程序时。

谁能看到我做错了什么,任何帮助将不胜感激

非常感谢,

4

1 回答 1

3

你的逻辑颠倒了。

如果x % 2返回0,则表示x可被 2 整除,没有余数,即even

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