gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:06:10 26 4
gpt4 key购买 nike

我正在为 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() 来帮助我调试, - 目前控制台打印“Odd”,这(如果我错了请纠正我)对于 element(0) 来说是错误的?当我下一步执行该应用程序时,它会崩溃。

任何人都可以看到我做错了什么,任何帮助将不胜感激

非常感谢,

最佳答案

你的逻辑搞反了。

如果x % 2返回0,则意味着x可以被二整除,没有余数,即偶数

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

关于java - 比较不断重新填充的二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13827133/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com