- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
代码的用途:无需人工干预即可自动识别屏幕上的按钮/获取其坐标。 (代码应该在更大的二维数组中找到一个二维数组)。
我是如何尝试解决它的:我将每个 RGB 像素值存储在二维数组中(a[][]
也称为大阵)。我将按钮像素/较小的 2Darray 存储在 optionArrayButton[][]
中。然后对这些步骤进行编码:(阅读本文时请查看下面的数组)。
SmallerArray[0][0] = firstSmallerArray
的数字[0][0]
到 [0][end]
然后 检查 FirstSmallerArray
数字的更大数组[1][0]
到 [1][end]
等等。firstSmallerArray
编号,则返回 -1
或 not Found
。smallerArray.length
) 和宽度 (smallerArray[0].length
)。firstSmallerArray
数字、smallerArray.length
和 smallerArray[0].length
存储在临时数组中。temp == smallerArray
并获取坐标。我需要什么帮助: 出于某种原因,即使较小的数组在较大的数组内,它也说找不到按钮(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");
最佳答案
使用这种方法:
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");
您的魔数(Magic Number) 300
可疑。也许您的按钮距离左侧或顶部超过 300 像素?还要确保使用无损图像。只有 1 位错误,这失败了。
关于java - 在较大的二维数组中查找较小的二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20828033/
我正在通过 PHP 将 .csv 中的两行插入到表中。 我还会跟踪任何错误,如果发生错误,我不会提交事务。插入表后,我检索结果行的 ID(全部在一个事务中提交),并且 csv 的第一行对应于第二个 I
一个应用程序托管一个具有三个接口(interface)的 Web 服务,用于三个单独且独立的操作,所有这些操作都在应用程序的不同组件中实现,彼此独立,例如在不同的包等中,所以他们对彼此了解不多,只共享
我希望在单击特定表格数据单元格时同时选中单选按钮和单选按钮单击事件。我已经使用以下方法实现了这一点: $(document).ready(function() { $("td").click(
JSFiddle:https://jsfiddle.net/oyp1zxaq/ 本质上,我只是想在较大的 div 中放置四个具有定义宽度的较小 div,但我希望它们在其中间隔开。 我想知道是否有一种方
我在一个布局中有两个 View 。我将分别称它们为 View A 和 View B。 ┌──────┐ │┌─┐┌─┐│ ││A││B││ │└─┘└─┘│ └──────┘ 父布局(包括View A
我是一名优秀的程序员,十分优秀!