简体   繁体   English

比较不断重新填充的二维数组

[英]Comparing 2d Arrays which are continually repopulated

I'm creating a motion detection application for Android. 我正在为Android创建运动检测应用程序。 Although I'm having issues with my detection algorithm: 尽管我的检测算法存在问题:

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);
        }
    }
}

I'm using println() to help me debug, - Currently the console prints "Odd" which (correct me if I'm wrong) is wrong for element(0)? 我正在使用println()来帮助调试,-当前控制台会打印“ Odd”(如果我错了,请更正我),这对于element(0)是错误的吗? And when I next step over the application breaks. 当我下一步操作时,应用程序中断。

Can anyone see what I'm doing wrong, any help would be appreciated 谁能看到我在做什么错,任何帮助将不胜感激

Many Thanks, 非常感谢,

Your logic is reversed. 您的逻辑相反。

If x % 2 returns 0 that means x is divisible by two with no remainder, ie even . 如果x % 2返回0 ,这意味着x由两个没有余数,即, 甚至是整除。

4 % 2 = 0 // even
5 % 2 = 1 // odd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM