【发布时间】:2013-12-29 17:28:12
【问题描述】:
代码的目的:识别屏幕上的按钮/自动获取其坐标,无需人工干预。 (代码应该在更大的二维数组中找到一个二维数组)。
我是如何解决这个问题的:我将每个 RGB 像素值存储在一个二维数组中(a[][] 也称为大数组)。我将按钮像素/较小的 2Darray 存储在 optionArrayButton[][] 中。
然后对这些步骤进行编码:(阅读本文时请查看下面的数组)。
- 获取
SmallerArray[0][0] = firstSmallerArray号码的号码 - 通过
[0][0]到[0][end]然后[1][0]到[1][end]等等来检查FirstSmallerArray的更大数组。 - 如果找不到
firstSmallerArray号码,则返回-1或not Found。 - Else 获取它在更大数组中的位置。
- 获取 Smaller Array 的高度 (
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");
【问题讨论】:
-
您在算法中识别按钮的准确程度如何?
-
请不要忘记添加“?”提问!有些人在页面中搜索“?”如果“问题”中不存在,则直接转到下一个(实际)问题。
标签: java multidimensional-array