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,6 +3,7 @@ package sig;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ColorRegion {
|
public class ColorRegion {
|
||||||
Rectangle region;
|
Rectangle region;
|
||||||
@ -37,6 +38,9 @@ public class ColorRegion {
|
|||||||
int total = 0;
|
int total = 0;
|
||||||
for (int x=0;x<region.width;x++) {
|
for (int x=0;x<region.width;x++) {
|
||||||
for (int y=0;y<region.height;y++) {
|
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();
|
total+=new Color(img.getRGB(region.x+x, region.y+y)).getRed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,6 +50,9 @@ public class ColorRegion {
|
|||||||
int total = 0;
|
int total = 0;
|
||||||
for (int x=0;x<region.width;x++) {
|
for (int x=0;x<region.width;x++) {
|
||||||
for (int y=0;y<region.height;y++) {
|
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();
|
total+=new Color(img.getRGB(region.x+x, region.y+y)).getGreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,6 +62,9 @@ public class ColorRegion {
|
|||||||
int total = 0;
|
int total = 0;
|
||||||
for (int x=0;x<region.width;x++) {
|
for (int x=0;x<region.width;x++) {
|
||||||
for (int y=0;y<region.height;y++) {
|
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();
|
total+=new Color(img.getRGB(region.x+x, region.y+y)).getBlue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,26 +537,17 @@ public class MyRobot{
|
|||||||
|
|
||||||
private boolean OnResultsScreen() throws IOException {
|
private boolean OnResultsScreen() throws IOException {
|
||||||
//r.x-418, r.y-204
|
//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) {
|
if (!FUTURETONE) {
|
||||||
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)).getRGB(0, 0));
|
ColorRegion cr1 = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(18,219,5,5));
|
||||||
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,40,40)).getRGB(0, 0));
|
ColorRegion cr2 = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(38,196,5,5));
|
||||||
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0));
|
ColorRegion cr3 = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(498,248,18,22));
|
||||||
//System.out.println(c1+"/"+c2+"/"+c3);
|
//System.out.println(cr1+"/"+cr2+"/"+cr3);
|
||||||
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 &&
|
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);
|
||||||
c3.getRed()>=140 && c3.getRed()<=255 && c3.getGreen()>=140 && c3.getGreen()<=255 && c3.getBlue()>=110 && c3.getBlue()<=240;
|
|
||||||
} else {
|
} else {
|
||||||
BufferedImage img2 = ImageUtils.toBufferedImage(MYROBOT.currentScreen.getScaledInstance(1280 , 720, Image.SCALE_SMOOTH));
|
BufferedImage img2 = ImageUtils.toBufferedImage(MYROBOT.currentScreen.getScaledInstance(1280 , 720, Image.SCALE_SMOOTH));
|
||||||
Color ft_pixel1 = new Color(img2.getRGB(260, 38));
|
ColorRegion ft_results = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(70,30,70,30));
|
||||||
Color ft_pixel2 = new Color(img2.getRGB(86, 38));
|
//System.out.println(ft_results);
|
||||||
return (ft_pixel1.getRed()<60&&ft_pixel1.getRed()>=0&&
|
return ft_results.getAllRange(30,150,60,180,60,180);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,7 +773,7 @@ public class MyRobot{
|
|||||||
selectedSong=new SongData("LIKE THE WIND",0,0,0);
|
selectedSong=new SongData("LIKE THE WIND",0,0,0);
|
||||||
difficulty="H";
|
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("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("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);
|
RunTest("test53.png",456,163,31,7,47,75.89f,"EXEX","",105,736989,false,Mode.FUTURETONE);
|
||||||
@ -945,7 +936,7 @@ public class MyRobot{
|
|||||||
System.out.println("\tPassed ("+(System.currentTimeMillis()-startTime)+"ms)!");
|
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));
|
ColorRegion cr = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(842,635,5,5));
|
||||||
onSongSelect = cr.getAllRange(15,45,75,90,200,230);
|
onSongSelect = cr.getAllRange(15,45,75,90,200,230);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class TypeFace2 {
|
|||||||
debugdir.mkdirs();
|
debugdir.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result getAllData(BufferedImage img) throws IOException {
|
public Result getAllData(BufferedImage img) throws Exception {
|
||||||
return getAllData(img,false);
|
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_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);
|
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));
|
BufferedImage img2 = ImageUtils.toBufferedImage(img.getScaledInstance(1280 , 720, Image.SCALE_SMOOTH));
|
||||||
Result result = new Result("","",-1,-1,-1,-1,-1,-1f);
|
Result result = new Result("","",-1,-1,-1,-1,-1,-1f);
|
||||||
int[] finalNumbers = new int[5];
|
int[] finalNumbers = new int[5];
|
||||||
@ -138,23 +138,18 @@ public class TypeFace2 {
|
|||||||
|
|
||||||
|
|
||||||
//489,197
|
//489,197
|
||||||
Color failPixel = null;
|
|
||||||
result.fail = false;
|
result.fail = false;
|
||||||
switch (result.mode) {
|
switch (result.mode) {
|
||||||
case MEGAMIX:{
|
case MEGAMIX:{
|
||||||
for (int i=0;i<11;i++) {
|
ColorRegion failRegion = new ColorRegion(img2,new Rectangle(484,191,5,5));
|
||||||
failPixel=new Color(img2.getRGB(489, 187+i));
|
if (failRegion.getAllRange(0, 130, 0, 130, 0, 130)) {
|
||||||
if (failPixel.getRed()<100&&failPixel.getGreen()<100&&failPixel.getBlue()<100) {
|
|
||||||
result.fail = true;
|
result.fail = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}break;
|
}break;
|
||||||
case FUTURETONE:{
|
case FUTURETONE:{
|
||||||
failPixel=new Color(img2.getRGB(587, 148));
|
ColorRegion failRegion = new ColorRegion(img2,new Rectangle(585,146,5,5));
|
||||||
if (failPixel.getRed()<240&&failPixel.getRed()>180&&
|
if (failRegion.getAllRange(180, 240, 100, 200, 190, 240)) {
|
||||||
failPixel.getGreen()<200&&failPixel.getGreen()>100&&
|
|
||||||
failPixel.getBlue()>190&&failPixel.getBlue()<240) {
|
|
||||||
result.fail = true;
|
result.fail = true;
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
@ -162,12 +157,18 @@ public class TypeFace2 {
|
|||||||
|
|
||||||
switch (result.mode) {
|
switch (result.mode) {
|
||||||
case MEGAMIX:{
|
case MEGAMIX:{
|
||||||
Color difficultyPixel = new Color(img2.getRGB(622, 110));
|
ColorRegion difficultyRegion = new ColorRegion(img2,new Rectangle(620,100,5,5));
|
||||||
result.difficulty = getDifficulty(difficultyPixel);
|
result.difficulty = getDifficulty(difficultyRegion);
|
||||||
|
if (debug) {
|
||||||
|
System.out.println("Diff:"+result.difficulty+"/"+difficultyRegion);
|
||||||
|
}
|
||||||
}break;
|
}break;
|
||||||
case FUTURETONE:{
|
case FUTURETONE:{
|
||||||
Color difficultyPixel = new Color(img2.getRGB(585, 70));
|
ColorRegion difficultyRegion = new ColorRegion(img2,new Rectangle(583,68,5,5));
|
||||||
result.difficulty = getFutureToneDifficulty(difficultyPixel);
|
result.difficulty = getFutureToneDifficulty(difficultyRegion);
|
||||||
|
if (debug) {
|
||||||
|
System.out.println("Diff:"+result.difficulty+"/"+difficultyRegion);
|
||||||
|
}
|
||||||
}break;
|
}break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,14 +217,9 @@ public class TypeFace2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Mode getMode(BufferedImage img2) {
|
private Mode getMode(BufferedImage img2) {
|
||||||
Color ft_pixel1 = new Color(img2.getRGB(260, 38));
|
ColorRegion ft_results = new ColorRegion(img2,new Rectangle(81,35,80,37));
|
||||||
Color ft_pixel2 = new Color(img2.getRGB(86, 38));
|
//System.out.println("Mode Check:"+ft_results);
|
||||||
if (ft_pixel1.getRed()<60&&ft_pixel1.getRed()>=0&&
|
if (ft_results.getAllRange(30,150,60,180,60,180)) {
|
||||||
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) {
|
|
||||||
return Mode.FUTURETONE;
|
return Mode.FUTURETONE;
|
||||||
}
|
}
|
||||||
return Mode.MEGAMIX;
|
return Mode.MEGAMIX;
|
||||||
@ -258,13 +254,14 @@ public class TypeFace2 {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFutureToneDifficulty(Color difficultyPixel) {
|
private String getFutureToneDifficulty(ColorRegion difficultyRegion) {
|
||||||
String[] diffs = new String[] {"E","N","H","EX","EXEX"};
|
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),};
|
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 lowestDistance = Integer.MAX_VALUE;
|
||||||
int lowestIndex = -1;
|
int lowestIndex = -1;
|
||||||
|
Color avg = new Color(difficultyRegion.getRed(),difficultyRegion.getGreen(),difficultyRegion.getBlue());
|
||||||
for (int i=0;i<cols.length;i++) {
|
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) {
|
if (distance<lowestDistance) {
|
||||||
lowestDistance = distance;
|
lowestDistance = distance;
|
||||||
lowestIndex=i;
|
lowestIndex=i;
|
||||||
@ -273,13 +270,14 @@ public class TypeFace2 {
|
|||||||
return diffs[lowestIndex];
|
return diffs[lowestIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDifficulty(Color difficultyPixel) {
|
private String getDifficulty(ColorRegion difficultyRegion) {
|
||||||
String[] diffs = new String[] {"E","N","H","EX","EXEX"};
|
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),};
|
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 lowestDistance = Integer.MAX_VALUE;
|
||||||
int lowestIndex = -1;
|
int lowestIndex = -1;
|
||||||
|
Color avg = new Color(difficultyRegion.getRed(),difficultyRegion.getGreen(),difficultyRegion.getBlue());
|
||||||
for (int i=0;i<cols.length;i++) {
|
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) {
|
if (distance<lowestDistance) {
|
||||||
lowestDistance = distance;
|
lowestDistance = distance;
|
||||||
lowestIndex=i;
|
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 |