Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 比较连续重新填充的二维阵列_Java_Android_Arrays_Math_Multidimensional Array - Fatal编程技术网

Java 比较连续重新填充的二维阵列

Java 比较连续重新填充的二维阵列,java,android,arrays,math,multidimensional-array,Java,Android,Arrays,Math,Multidimensional Array,我正在为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

我正在为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);
        }
    }
}
public boolean compareBitmaps()
{
/*我正在创建2 x 2D阵列,这些阵列将不断重新填充
每2帧,该帧的像素数据基于偶数或奇数
(帧收集在ArrayList“BIT”中)
位(0)将存储在compare1中
位(1)将存储在compare2中
位(2)将存储在compare1中,以此类推*/
int[][]compare1=新int[宽度][高度];
int[][]compare2=新int[宽度][高度];
int bmpCount=BIT.size();
布尔noMotion=true;
//这是我用模数%确定奇数或偶数的地方

对于(intx=0;x,您的逻辑是相反的

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


你的逻辑颠倒了

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


谢谢,我没有注意到这个小错误!我已经按照建议交换了打印语句,但应用程序仍将中断regardlessHmm…我不知道
getPixel1()
getPixel2()
要做什么,但如果关键是“位(0)将存储在compare1中”然后您的排序仍然是反向的
x=0
compare2
x=1
compare1
,等等……我在中添加了其他方法。只需嵌套for循环通过x&y并收集每个像素的像素颜色。它们的存储顺序与奇数和偶数的顺序一样重要我从来没有逐像素比较过图像,所以我不能推荐一个好的替代方法。但我可以看到,每次调用
getPixel\uz()
方法时,您都会写入该数组中从
[0][0]
[width][height]的每个值
。您需要重新编写逻辑,以便只获取和存储一个像素…感谢我没有注意到这个小错误!我已按照建议交换了打印语句,但应用程序仍将中断regardlessHmm…我不知道
getPixel1()
getPixel2()
要做什么,但如果“位(0)”是关键的将存储在compare1中”然后您的排序仍然是反向的
x=0
compare2
x=1
compare1
,等等……我在中添加了其他方法。只需嵌套for循环通过x&y并收集每个像素的像素颜色。它们的存储顺序与奇数和偶数的顺序一样重要我从来没有逐像素比较过图像,所以我不能推荐一个好的替代方法。但我可以看到,每次调用
getPixel\uz()
方法时,您都会写入该数组中从
[0][0]
[width][height]的每个值
。您需要重新设计逻辑,以便只获取和存储一个像素…因为您正在实现运动检测类型应用程序,并比较每个偶数和奇数帧,据我所知,我认为它太快,需要消耗大量CPU电源,我的建议是以低速率比较帧,比如15帧之后。对不起,怎么办你的意思是在15帧后进行比较?比如将第0帧与第14帧进行比较,将第15帧与第29帧进行比较等等?只是一个友好的提醒。我注意到你没有接受任何问题的答案。你知道你可以接受答案以表明它解决了你的问题吗?只需单击投票箭头旁边的复选框。这会让社区知道你正在积极参与你的问题。由于你正在实施运动检测类型应用程序并比较每一个偶数和奇数帧,据我所知,我认为它太快并且消耗大量CPU功率,我的建议是以低速率比较帧,比如15帧后。对不起,你说15帧后比较是什么意思ike将第0帧与第14帧、第15帧与第29帧进行比较,以此类推?这只是一个友好的提醒。我注意到你没有接受任何问题的答案。你知道你可以接受答案以表明它解决了你的问题吗?只需单击投票箭头旁边的复选框。这会让社区知道你正在积极参与投票你的问题。
4 % 2 = 0 // even
5 % 2 = 1 // odd