Skip to content

Commit

Permalink
change: 找白点时,修复边界越界的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
陈亮 committed Jan 3, 2018
1 parent 6469120 commit 7f250a7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
33 changes: 18 additions & 15 deletions src/com/skyline/wxjumphack/MyPosFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ public int[] find(BufferedImage image) {
int height = image.getHeight();

int[] ret = {0, 0};
int maxX=Integer.MIN_VALUE;
int minX=Integer.MAX_VALUE;
int maxY=Integer.MIN_VALUE;
int minY=Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int minX = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height*3/4; j++) {
for (int j = height / 4; j < height * 3 / 4; j++) {
int pixel = image.getRGB(i, j);
int r = (pixel & 0xff0000) >> 16;
int g = (pixel & 0xff00) >> 8;
int b = (pixel & 0xff);
if (ToleranceHelper.match(r, g, b, R_TARGET, G_TARGET, B_TARGET, 16) && j > ret[1]) {
maxX=Integer.max(maxX, i);
minX=Integer.min(minX, i);
maxY=Integer.max(maxY, j);
minY=Integer.min(minY, j);
maxX = Integer.max(maxX, i);
minX = Integer.min(minX, i);
maxY = Integer.max(maxY, j);
minY = Integer.min(minY, j);
}
}
}
ret[0]=(maxX+minX)/2;
ret[1]=maxY;
System.out.println(maxX+", "+minX);
ret[0] = (maxX + minX) / 2;
ret[1] = maxY;
System.out.println(maxX + ", " + minX);
System.out.println("pos, x: " + ret[0] + ", y: " + ret[1]);
return ret;
}
Expand All @@ -57,15 +57,17 @@ public static void main(String... strings) throws IOException {
String imgsDesc = root + "imgs/my_pos";
File srcDir = new File(imgsSrc);
System.out.println(srcDir);
long cost = 0;
for (File file : srcDir.listFiles()) {

if(!file.getName().endsWith(".png")){
if (!file.getName().endsWith(".png")) {
continue;
}
System.out.println(file);
BufferedImage img = ImgLoader.load(file.getAbsolutePath());
long t1 = System.nanoTime();
int[] pos = t.find(img);

long t2 = System.nanoTime();
cost += (t2 - t1);
BufferedImage desc = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
desc.getGraphics().drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null); // 绘制缩小后的图
desc.getGraphics().drawRect(pos[0] - 5, pos[1] - 5, 10, 10);
Expand All @@ -76,6 +78,7 @@ public static void main(String... strings) throws IOException {
}
ImageIO.write(desc, "png", descFile);
}
System.out.println("avg time cost: " + (cost / srcDir.listFiles().length / 1_000_000));

}
}
9 changes: 7 additions & 2 deletions src/com/skyline/wxjumphack/NextCenterFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public int[] find(BufferedImage image, int[] exceptedX, int maxY) {
if (i >= exceptedX[0] && i <= exceptedX[1]) {
continue;
}
if(j>=maxY){
if (j >= maxY) {
continue;
}

Expand Down Expand Up @@ -163,10 +163,14 @@ public static void main(String... strings) throws IOException {
String imgsDesc = root + "imgs/next_center";
File srcDir = new File(imgsSrc);
System.out.println(srcDir);
long cost = 0;
for (File file : srcDir.listFiles()) {
System.out.println(file);
BufferedImage img = ImgLoader.load(file.getAbsolutePath());
int[] pos = t.find(img, excepted,2000);
long t1 = System.nanoTime();
int[] pos = t.find(img, excepted, 2000);
long t2 = System.nanoTime();
cost += (t2 - t1);
BufferedImage desc = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = desc.getGraphics();
g.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null);
Expand All @@ -186,6 +190,7 @@ public static void main(String... strings) throws IOException {
}
ImageIO.write(desc, "png", descFile);
}
System.out.println("avg time cost: " + (cost / srcDir.listFiles().length / 1_000_000));

}

Expand Down
14 changes: 9 additions & 5 deletions src/com/skyline/wxjumphack/WhitePointFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public int[] find(BufferedImage image, int x1, int y1, int x2, int y2) {
int width = image.getWidth();
int height = image.getHeight();

x1 = Integer.max(x1, 0);
x2 = Integer.min(x2, width - 1);
y1 = Integer.max(y1, 0);
y2 = Integer.min(y2, height - 1);

for (int i = x1; i <= x2; i++) {
for (int j = y1; j <= y2; j++) {
int pixel = image.getRGB(i, j);
Expand All @@ -36,9 +41,9 @@ public int[] find(BufferedImage image, int x1, int y1, int x2, int y2) {
int minY = Integer.MAX_VALUE;
while (!queue.isEmpty()) {
pos = queue.poll();
int x=pos[0];
int y=pos[1];
if (x< x1 || x> x2 || y < y1 || y> y2 || vMap[x][y]) {
int x = pos[0];
int y = pos[1];
if (x < x1 || x > x2 || y < y1 || y > y2 || vMap[x][y]) {
continue;
}
vMap[x][y] = true;
Expand All @@ -58,7 +63,7 @@ public int[] find(BufferedImage image, int x1, int y1, int x2, int y2) {
}
}

System.out.println("whitePoint: "+maxX+", "+minX+", "+maxY+", "+minY);
System.out.println("whitePoint: " + maxX + ", " + minX + ", " + maxY + ", " + minY);
if (maxX - minX <= 45 && maxX - minX >= 35 && maxY - minY <= 30 && maxY - minY >= 20) {
int[] ret = {(minX + maxX) / 2, (minY + maxY) / 2};
return ret;
Expand All @@ -78,5 +83,4 @@ public static int[] buildArray(int i, int j) {
}



}

0 comments on commit 7f250a7

Please sign in to comment.