Improve detection algorithms for song select/results screen using
averaged color regions.
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 5.1 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 5.2 KiB |
@ -3,12 +3,13 @@ package sig;
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ColorRegion {
|
||||
Rectangle region;
|
||||
BufferedImage img;
|
||||
|
||||
ColorRegion(BufferedImage img, Rectangle region) {
|
||||
ColorRegion(BufferedImage img, Rectangle region){
|
||||
this.region=region;
|
||||
this.img=img;
|
||||
}
|
||||
@ -37,6 +38,9 @@ public class ColorRegion {
|
||||
int total = 0;
|
||||
for (int x=0;x<region.width;x++) {
|
||||
for (int y=0;y<region.height;y++) {
|
||||
if (region.x+x<0||region.x+x>=region.x+region.width||region.y+y<0||region.y+y>=region.y+region.height) {
|
||||
continue;
|
||||
}
|
||||
total+=new Color(img.getRGB(region.x+x, region.y+y)).getRed();
|
||||
}
|
||||
}
|
||||
@ -46,6 +50,9 @@ public class ColorRegion {
|
||||
int total = 0;
|
||||
for (int x=0;x<region.width;x++) {
|
||||
for (int y=0;y<region.height;y++) {
|
||||
if (region.x+x<0||region.x+x>=region.x+region.width||region.y+y<0||region.y+y>=region.y+region.height) {
|
||||
continue;
|
||||
}
|
||||
total+=new Color(img.getRGB(region.x+x, region.y+y)).getGreen();
|
||||
}
|
||||
}
|
||||
@ -55,6 +62,9 @@ public class ColorRegion {
|
||||
int total = 0;
|
||||
for (int x=0;x<region.width;x++) {
|
||||
for (int y=0;y<region.height;y++) {
|
||||
if (region.x+x<0||region.x+x>=region.x+region.width||region.y+y<0||region.y+y>=region.y+region.height) {
|
||||
continue;
|
||||
}
|
||||
total+=new Color(img.getRGB(region.x+x, region.y+y)).getBlue();
|
||||
}
|
||||
}
|
||||
|
@ -537,26 +537,17 @@ public class MyRobot{
|
||||
|
||||
private boolean OnResultsScreen() throws IOException {
|
||||
//r.x-418, r.y-204
|
||||
/*ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png"));
|
||||
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)),"png",new File("color2.png"));
|
||||
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)),"png",new File("color3.png"));*/
|
||||
if (!FUTURETONE) {
|
||||
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0));
|
||||
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0));
|
||||
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0));
|
||||
//System.out.println(c1+"/"+c2+"/"+c3);
|
||||
return c1.getRed()>=240 && c1.getGreen()>=240 && c1.getBlue()>=240 && c2.getRed()>=7 && c2.getRed()<=60 && c2.getGreen()>=180 && c2.getGreen()<=250 && c2.getBlue()>=150 && c2.getBlue()<=240 &&
|
||||
c3.getRed()>=140 && c3.getRed()<=255 && c3.getGreen()>=140 && c3.getGreen()<=255 && c3.getBlue()>=110 && c3.getBlue()<=240;
|
||||
ColorRegion cr1 = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(18,219,5,5));
|
||||
ColorRegion cr2 = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(38,196,5,5));
|
||||
ColorRegion cr3 = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(498,248,18,22));
|
||||
//System.out.println(cr1+"/"+cr2+"/"+cr3);
|
||||
return cr1.getAllRange(240, 255, 240, 255, 240, 255)&&cr2.getAllRange(7, 60, 180, 250, 150, 240)&&cr3.getAllRange(140, 255, 140, 255, 110, 240);
|
||||
} else {
|
||||
BufferedImage img2 = ImageUtils.toBufferedImage(MYROBOT.currentScreen.getScaledInstance(1280 , 720, Image.SCALE_SMOOTH));
|
||||
Color ft_pixel1 = new Color(img2.getRGB(260, 38));
|
||||
Color ft_pixel2 = new Color(img2.getRGB(86, 38));
|
||||
return (ft_pixel1.getRed()<60&&ft_pixel1.getRed()>=0&&
|
||||
ft_pixel1.getGreen()<90&&ft_pixel1.getGreen()>20&&
|
||||
ft_pixel1.getBlue()<90&&ft_pixel1.getBlue()>20
|
||||
&&ft_pixel2.getRed()<60&&ft_pixel2.getRed()>=0&&
|
||||
ft_pixel2.getGreen()<90&&ft_pixel2.getGreen()>20&&
|
||||
ft_pixel2.getBlue()<90&&ft_pixel2.getBlue()>20);
|
||||
ColorRegion ft_results = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(70,30,70,30));
|
||||
//System.out.println(ft_results);
|
||||
return ft_results.getAllRange(30,150,60,180,60,180);
|
||||
}
|
||||
}
|
||||
|
||||
@ -782,7 +773,7 @@ public class MyRobot{
|
||||
selectedSong=new SongData("LIKE THE WIND",0,0,0);
|
||||
difficulty="H";
|
||||
|
||||
RunTest("test56.png",405,105,17,8,41,63.72f,"EX","",109,453145,false,Mode.FUTURETONE);
|
||||
RunTest("test56.png",405,105,17,8,41,63.72f,"EX","",109,453145,true,Mode.FUTURETONE);
|
||||
RunTest("test55.png",421,50,1,0,3,98.37f,"EXEX","",406,689821,false,Mode.FUTURETONE);
|
||||
RunTest("test54.png",448,129,20,6,35,74.89f,"EXEX","",247,678260,true,Mode.FUTURETONE);
|
||||
RunTest("test53.png",456,163,31,7,47,75.89f,"EXEX","",105,736989,false,Mode.FUTURETONE);
|
||||
@ -887,11 +878,11 @@ public class MyRobot{
|
||||
RunTest("test46.png",452,25,0,0,1,103.16f,"EXEX","HS",260,750134,false,Mode.FUTURETONE);
|
||||
}
|
||||
|
||||
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail, Mode _mode) throws IOException {
|
||||
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail, Mode _mode) throws IOException{
|
||||
RunTest(_img,_cool,_fine,_safe,_sad,_worst,_percent,_difficulty,_mod,_combo,_score,_fail,_mode,false);
|
||||
}
|
||||
|
||||
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail,Mode _mode,boolean debug) throws IOException {
|
||||
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,String _difficulty,String _mod,int _combo,int _score,boolean _fail,Mode _mode,boolean debug) throws IOException{
|
||||
System.out.println("Running test "+_img);
|
||||
long startTime = System.currentTimeMillis();
|
||||
String testdir="testsuite";
|
||||
@ -945,7 +936,7 @@ public class MyRobot{
|
||||
System.out.println("\tPassed ("+(System.currentTimeMillis()-startTime)+"ms)!");
|
||||
}
|
||||
|
||||
public static boolean checkSongSelect() throws IOException {
|
||||
public static boolean checkSongSelect() throws Exception {
|
||||
ColorRegion cr = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(842,635,5,5));
|
||||
onSongSelect = cr.getAllRange(15,45,75,90,200,230);
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class TypeFace2 {
|
||||
debugdir.mkdirs();
|
||||
}
|
||||
|
||||
public Result getAllData(BufferedImage img) throws IOException {
|
||||
public Result getAllData(BufferedImage img) throws Exception {
|
||||
return getAllData(img,false);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ public class TypeFace2 {
|
||||
final static Rectangle FUTURETONE_RECT_SEARCH_SCORE=new Rectangle(866+XOFFSET,543-4,250+XOFFSET+1,32+24);
|
||||
final static Rectangle FUTURETONE_RECT_SEARCH_COMBO=new Rectangle(1023+XOFFSET,402,100+XOFFSET+1,22+8);
|
||||
|
||||
public Result getAllData(BufferedImage img, boolean debug) throws IOException,NumberFormatException,IndexOutOfBoundsException {
|
||||
public Result getAllData(BufferedImage img, boolean debug) throws IOException {
|
||||
BufferedImage img2 = ImageUtils.toBufferedImage(img.getScaledInstance(1280 , 720, Image.SCALE_SMOOTH));
|
||||
Result result = new Result("","",-1,-1,-1,-1,-1,-1f);
|
||||
int[] finalNumbers = new int[5];
|
||||
@ -138,23 +138,18 @@ public class TypeFace2 {
|
||||
|
||||
|
||||
//489,197
|
||||
Color failPixel = null;
|
||||
result.fail = false;
|
||||
switch (result.mode) {
|
||||
case MEGAMIX:{
|
||||
for (int i=0;i<11;i++) {
|
||||
failPixel=new Color(img2.getRGB(489, 187+i));
|
||||
if (failPixel.getRed()<100&&failPixel.getGreen()<100&&failPixel.getBlue()<100) {
|
||||
result.fail = true;
|
||||
break;
|
||||
}
|
||||
ColorRegion failRegion = new ColorRegion(img2,new Rectangle(484,191,5,5));
|
||||
if (failRegion.getAllRange(0, 130, 0, 130, 0, 130)) {
|
||||
result.fail = true;
|
||||
break;
|
||||
}
|
||||
}break;
|
||||
case FUTURETONE:{
|
||||
failPixel=new Color(img2.getRGB(587, 148));
|
||||
if (failPixel.getRed()<240&&failPixel.getRed()>180&&
|
||||
failPixel.getGreen()<200&&failPixel.getGreen()>100&&
|
||||
failPixel.getBlue()>190&&failPixel.getBlue()<240) {
|
||||
ColorRegion failRegion = new ColorRegion(img2,new Rectangle(585,146,5,5));
|
||||
if (failRegion.getAllRange(180, 240, 100, 200, 190, 240)) {
|
||||
result.fail = true;
|
||||
}
|
||||
}break;
|
||||
@ -162,12 +157,18 @@ public class TypeFace2 {
|
||||
|
||||
switch (result.mode) {
|
||||
case MEGAMIX:{
|
||||
Color difficultyPixel = new Color(img2.getRGB(622, 110));
|
||||
result.difficulty = getDifficulty(difficultyPixel);
|
||||
ColorRegion difficultyRegion = new ColorRegion(img2,new Rectangle(620,100,5,5));
|
||||
result.difficulty = getDifficulty(difficultyRegion);
|
||||
if (debug) {
|
||||
System.out.println("Diff:"+result.difficulty+"/"+difficultyRegion);
|
||||
}
|
||||
}break;
|
||||
case FUTURETONE:{
|
||||
Color difficultyPixel = new Color(img2.getRGB(585, 70));
|
||||
result.difficulty = getFutureToneDifficulty(difficultyPixel);
|
||||
ColorRegion difficultyRegion = new ColorRegion(img2,new Rectangle(583,68,5,5));
|
||||
result.difficulty = getFutureToneDifficulty(difficultyRegion);
|
||||
if (debug) {
|
||||
System.out.println("Diff:"+result.difficulty+"/"+difficultyRegion);
|
||||
}
|
||||
}break;
|
||||
}
|
||||
|
||||
@ -216,14 +217,9 @@ public class TypeFace2 {
|
||||
}
|
||||
|
||||
private Mode getMode(BufferedImage img2) {
|
||||
Color ft_pixel1 = new Color(img2.getRGB(260, 38));
|
||||
Color ft_pixel2 = new Color(img2.getRGB(86, 38));
|
||||
if (ft_pixel1.getRed()<60&&ft_pixel1.getRed()>=0&&
|
||||
ft_pixel1.getGreen()<90&&ft_pixel1.getGreen()>20&&
|
||||
ft_pixel1.getBlue()<90&&ft_pixel1.getBlue()>20
|
||||
&&ft_pixel2.getRed()<60&&ft_pixel2.getRed()>=0&&
|
||||
ft_pixel2.getGreen()<90&&ft_pixel2.getGreen()>20&&
|
||||
ft_pixel2.getBlue()<90&&ft_pixel2.getBlue()>20) {
|
||||
ColorRegion ft_results = new ColorRegion(img2,new Rectangle(81,35,80,37));
|
||||
//System.out.println("Mode Check:"+ft_results);
|
||||
if (ft_results.getAllRange(30,150,60,180,60,180)) {
|
||||
return Mode.FUTURETONE;
|
||||
}
|
||||
return Mode.MEGAMIX;
|
||||
@ -258,13 +254,14 @@ public class TypeFace2 {
|
||||
return "";
|
||||
}
|
||||
|
||||
private String getFutureToneDifficulty(Color difficultyPixel) {
|
||||
private String getFutureToneDifficulty(ColorRegion difficultyRegion) {
|
||||
String[] diffs = new String[] {"E","N","H","EX","EXEX"};
|
||||
Color[] cols = new Color[] {new Color(15,63,160),new Color(31,175,13),new Color(157,123,17),new Color(152,13,16),new Color(98,0,165),};
|
||||
int lowestDistance = Integer.MAX_VALUE;
|
||||
int lowestIndex = -1;
|
||||
Color avg = new Color(difficultyRegion.getRed(),difficultyRegion.getGreen(),difficultyRegion.getBlue());
|
||||
for (int i=0;i<cols.length;i++) {
|
||||
int distance = (int)ImageUtils.distanceToColor(difficultyPixel, cols[i]);
|
||||
int distance = (int)ImageUtils.distanceToColor(avg, cols[i]);
|
||||
if (distance<lowestDistance) {
|
||||
lowestDistance = distance;
|
||||
lowestIndex=i;
|
||||
@ -273,13 +270,14 @@ public class TypeFace2 {
|
||||
return diffs[lowestIndex];
|
||||
}
|
||||
|
||||
private String getDifficulty(Color difficultyPixel) {
|
||||
private String getDifficulty(ColorRegion difficultyRegion) {
|
||||
String[] diffs = new String[] {"E","N","H","EX","EXEX"};
|
||||
Color[] cols = new Color[] {new Color(95,243,255),new Color(20,234,0),new Color(251,191,0),new Color(253,14,81),new Color(157,0,227),};
|
||||
int lowestDistance = Integer.MAX_VALUE;
|
||||
int lowestIndex = -1;
|
||||
Color avg = new Color(difficultyRegion.getRed(),difficultyRegion.getGreen(),difficultyRegion.getBlue());
|
||||
for (int i=0;i<cols.length;i++) {
|
||||
int distance = (int)ImageUtils.distanceToColor(difficultyPixel, cols[i]);
|
||||
int distance = (int)ImageUtils.distanceToColor(avg, cols[i]);
|
||||
if (distance<lowestDistance) {
|
||||
lowestDistance = distance;
|
||||
lowestIndex=i;
|
||||
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
BIN
Release/DivaBot/DivaBot/changemonitor.png
Normal file
After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |