2012-12-11 66 views
0

我正在为Android创建一个运动检测应用程序。虽然我有我的检测算法的问题:比较不断重新填充的2d阵列

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)?当我下一步完成应用程序休息时。

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

非常感谢,

+1

当你在实现运动检测型应用程序,并比较每个偶数和奇数帧,从我的小知识,我认为这是太快,会消耗大量的CPU功率的,我的建议是框架在低速率一些比较像15帧之后的东西。 –

+0

对不起,15帧后你比较什么?就像比较第0帧和第14帧以及第15帧和第29帧一样? – Ledgey1101

+0

只是一个友好的提醒。我注意到你没有接受任何问题的答案。你知道你可以接受答案来证明它解决了你的问题吗?只需点击投票箭头旁边的复选框即可。这让社区知道你正在积极参与你的问题。 –

回答

3

你的逻辑是相反的。

如果x % 2返回0这意味着x整除由两个没有余,即甚至

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

谢谢,我没有注意到那个小!错误,我已经根据建议调换了打印语句,但应用程序仍然会中断,无论 – Ledgey1101

+0

嗯...我不知道getPixel1()和getPixel2()是做什么的,但是如果关键是“ BIT(0)将存储在比较1“,那么你的排序仍然颠倒”x = 0“在”比较2“,”x = 1“在”比较1“等... – Sam

+0

我已经添加了其他方法只需嵌套for循环通过x和y并收集每个像素的像素颜色。只要奇数和偶数是分开存储的顺序并不是必须的 – Ledgey1101