画面をスキャンして特定の画像を探す、より優れた「より深い」方法を探しています。私の場合、オンラインプロセスを自動化しています。現在、画面をスキャンして「ボックス」を探す方法は次のとおりです。
private boolean boxChecker() {
Robot iris = null;
data.boxFound = false;
try{
iris = new Robot();
}catch (Exception e){}
System.out.println("flash");
BufferedImage TestShot = iris.createScreenCapture(new Rectangle(0,0,width,height));
// finding points
boolean FoundPoint = false;
int FirstX = 0;
int FirstY = 0;
int tempx = (int)width/2 ;
int tempy = 60;
tan = 0;
grey = TestShot.getRGB(tempx, tempy);
black = 0;
System.out.println("before i start, tempx is "+tempx+" and tempy is "+tempy);
try{
do{
int colour = TestShot.getRGB(tempx, tempy);
if (colour != grey ){ // this is the first point here!!
System.out.println("the first point is at "+tempx+" by "+tempy);
tan = colour;
FirstX = tempx;
FirstY = tempy;
FoundPoint = true;
}
else{
tempy++;
}
} while(!FoundPoint);
FoundPoint = false;
do{
int colour = TestShot.getRGB(tempx, tempy);
if (colour == grey ){ // this is the second point here!!
tempx++;
System.out.println("the second point is at "+tempx+" by "+tempy);
FoundPoint = true;
}
else{
tempx--;
}
} while(!FoundPoint);
FoundPoint = false;
do{ // this is for the third point
int colour = TestShot.getRGB(tempx, tempy);
if (colour != tan ){ // this is the third point here!!
black = colour;
System.out.println("the third point is at "+tempx+" by "+tempy);
FoundPoint = true;
}
else{
tempy++;
}
} while(!FoundPoint);
FoundPoint = false;
do{
int colour = TestShot.getRGB(tempx, tempy);
if (colour == grey ){ // this is the fourth point here!!
tempx--;
System.out.println("the fourth point is at "+tempx+" by "+tempy);
FoundPoint = true;
}
else{
tempx++;
}
} while(!FoundPoint);
FoundPoint = false;
do{
int colour = TestShot.getRGB(tempx, tempy);
if (colour == grey ){ // this is the fifth point here!!
tempy++;
System.out.println("the fifth point is at "+tempx+" by "+tempy);
FoundPoint = true;
}
else{
tempy--;
}
} while(!FoundPoint);
FoundPoint = false;
do{
if (FirstX == tempx && FirstY == tempy ){ // this is the sixth point here!!
System.out.println("the sixth point is at "+tempx+" by "+tempy);
FoundPoint = true;
}
else{
tempx--;
}
} while(!FoundPoint);
data.boxFound = true;
return true;
} catch (Exception e){
System.err.println("wrong screen bro");
data.boxFound = false;
return false;
}
}
画面やその他すべてに依存しているため、これが恐ろしい方法であることはわかっていますが、それがより良い方法が必要な理由です。
メモとして、これは私のプログラムではそのまま機能します。