Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.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_Multidimensional Array - Fatal编程技术网

Java 在较大的二维阵列中查找较小的二维阵列

Java 在较大的二维阵列中查找较小的二维阵列,java,multidimensional-array,Java,Multidimensional Array,代码的目的:识别屏幕上的按钮/自动获取其坐标,无需人工干预。(代码应该在更大的2D数组中找到2D数组) 我是如何解决的:我将每个RGB像素值存储在一个2D数组中(a[][]也称为大数组)。我将按钮像素/更小的2D数组存储在选项ArrayButton[][]中。 然后对这些步骤进行编码:(阅读本文时请查看下面的数组) 获取smallerray[0][0]=firstsmallerray的编号 通过从[0][0]到[0][end]再到[1][0]到[1][end]等等,检查更大的数组的第一个smal

代码的目的:识别屏幕上的按钮/自动获取其坐标,无需人工干预。(代码应该在更大的2D数组中找到2D数组)

我是如何解决的:我将每个RGB像素值存储在一个2D数组中(
a[][]
也称为大数组)。我将按钮像素/更小的2D数组存储在
选项ArrayButton[][]
中。 然后对这些步骤进行编码:(阅读本文时请查看下面的数组)

  • 获取
    smallerray[0][0]=firstsmallerray的编号
  • 通过从
    [0][0]
    [0][end]
    再到
    [1][0]
    [1][end]
    等等,检查更大的数组的
    第一个smallerray
    编号
  • 如果未找到
    firstsmallerray
    编号,则返回
    -1
    未找到
  • 否则,获取它在较大数组中的位置
  • 获取较小数组的高度(
    smallerray.length
    )和宽度(
    smallerray[0].length
  • 使用
    firstsmallerray
    number、
    smallerray.length
    smallerray[0]。length
    存储在临时数组中
  • 检查
    temp==smallerary
    并获取坐标
  • 我需要帮助的内容:出于某种原因,即使较小的数组位于较大的数组中,但它表示找不到按钮(foundButton返回false)。我花了两天的时间在这上面,找不到哪里出了问题

    因为我使用的数组有200万个以上的RGB值,所以我将给出这些数组作为例子。 更大的阵列:

    [3 3 1 0 9]
    [4 1 5 4 5]
    [7 5 6 2 8]
    [8 2 7 3 5]
    [1 8 7 6 4]
    
    较小的阵列:

    [5 6 2]
    [2 7 3]
    [8 7 6]
    
    我对编码有点在行,所以我可能不理解java/编码术语。再次感谢所有能帮忙的人

    DataStorage DataStorageObject = new DataStorage();
    int[][] optionArrayButton = DataStorageObject.optionArrayButton();
    
    int firstSmallerArrayNumber = optionArrayButton[0][0]; //Step 1
    int heightOfSmallerArray = optionArrayButton.length; //Step 5
    int widthOfSmallerArray = optionArrayButton[0].length; //Step 5
    
    boolean foundButton = false;
    
    //a[][] has the screens rgb values
    for(int yaxisCounter = 0; yaxisCounter < 300; yaxisCounter++) //Step 2
    {
       for(int xaxisCounter = 0; xaxisCounter < 300; xaxisCounter++) //Step 2
       {
           if(a[yaxisCounter][xaxisCounter] == firstSmallerArrayNumber) //Step 4
           {
              int[][] tempArray = new int[heightOfSmallerArray][widthOfSmallerArray];  //Step 6
            //  System.out.println(" " + yaxisCounter + ", " + xaxisCounter);
              for(int ycounterForTemp = 0; ycounterForTemp < heightOfSmallerArray; ycounterForTemp++)  //Step 6
              {
                 for(int xcounterForTemp = 0; xcounterForTemp < widthOfSmallerArray; xcounterForTemp++)  //Step 6
                 {
                    tempArray[ycounterForTemp][xcounterForTemp] = a[yaxisCounter][xaxisCounter];  //Step 6
             //       System.out.println("Storing in temp");
                 }
              }
    
              foundButton = isArrayEqual(tempArray, optionArrayButton); //Step 7
            //  System.out.println("Button found is a " + foundButton + " statement");
    
              if(foundButton)
              {
                  basePointy = yaxisCounter;
                  basePointx = xaxisCounter;
    
             //    System.out.println("Base Point y is: " + basePointy);
             //    System.out.println("Base Point x is: " + basePointx);
    
               }
    
               //If there are any problems this is where it would happen
               else
               {
                 //   System.out.println("Button Found is a : " + "false"  + " statement");
                  //  System.out.println("In the nested Else");
                    continue;
                }
    
    
            }
            else
            {
             //   System.out.println("In the else");
                continue;
            }
        }
    }
    
    //    System.out.println("Button Found is a : " + foundButton + " statement");
    
    DataStorage DataStorageObject=newdatastorage();
    int[][]optionArrayButton=DataStorageObject.optionArrayButton();
    int firstSmallerArrayNumber=optionArrayButton[0][0]//第一步
    int heightOfSmallerArray=optionArrayButton.length//步骤5
    int widthOfsmalerarray=optionArrayButton[0]。长度//步骤5
    布尔foundButton=false;
    //a[][]具有屏幕rgb值
    for(int-yaxisconter=0;yaxisconter<300;yaxisconter++)//步骤2
    {
    for(int-xaxisconter=0;xaxisconter<300;xaxisconter++)//步骤2
    {
    if(a[yaxisconter][xaxisconter]==firstSmallerArrayNumber)//步骤4
    {
    int[][]tempArray=new int[heightOfSmallerArray][widthofsmalerarray];//步骤6
    //System.out.println(“+yaxisconter+”,“+xaxisconter”);
    for(int-ycounterForTemp=0;ycounterForTemp
    使用这种方法:

    int[][] matrix = ...;
    int[][] submatrix = ...;
    
    loopX: for (int x = 0; x < matrix.length - submatrix.length + 1; ++x)
    loopY: for (int y = 0; y < matrix[x].length - submatrix[0].length + 1; ++y)
    {
        for (int xx = 0; xx < submatrix.length; ++xx)
        for (int yy = 0; yy < submatrix[0].length; ++yy)
        {
            if (matrix[x + xx][y + yy] != submatrix[xx][yy])
            {
                continue loopY;
            }
        }
    
        // Found the submatrix!
        System.out.println("Found at: " + x + " " + y);
        break loopX;
    }
    System.out.println("Done");
    
    int[][]矩阵=。。。;
    int[][]子矩阵=。。。;
    loopX:for(int x=0;x


    您的魔法号码
    300
    可疑。也许你的按钮离左边或顶部超过300像素?还要确保使用无损图像。只有一点错误,这就失败了。

    您如何准确识别算法中的按钮?请不要忘记在问题中添加“?”!有些人在页面中搜索“?”,如果“问题”中不存在任何问题,则直接转到下一个(实际)问题。可能相关的问题是:我只是在尝试使用300,但不知道它在那里