Add ypointer caching to results screen parsing.

secondmonitor
sigonasr2 4 years ago
parent 6ba35d6b38
commit d49eee4830
  1. BIN
      DivaBot/rectangle0.png
  2. BIN
      DivaBot/rectangle1.png
  3. BIN
      DivaBot/rectangle2.png
  4. 3
      DivaBot/src/sig/MyRobot.java
  5. 149
      DivaBot/src/sig/TypeFace2.java

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

@ -942,6 +942,7 @@ public class MyRobot{
} }
System.exit(1); System.exit(1);
} }
TypeFace2.deepCopyDefaultYPointers();
System.out.println("\tPassed ("+(System.currentTimeMillis()-startTime)+"ms)!"); System.out.println("\tPassed ("+(System.currentTimeMillis()-startTime)+"ms)!");
} }
@ -956,6 +957,7 @@ public class MyRobot{
System.out.println("Switching to Megamix"); System.out.println("Switching to Megamix");
SongData.loadSongsFromFile(); SongData.loadSongsFromFile();
LASTMODE_FUTURETONE=false; LASTMODE_FUTURETONE=false;
TypeFace2.deepCopyDefaultYPointers();
} }
} else } else
{ {
@ -968,6 +970,7 @@ public class MyRobot{
System.out.println("Switching to Future Tone"); System.out.println("Switching to Future Tone");
SongData.loadSongsFromFile(); SongData.loadSongsFromFile();
LASTMODE_FUTURETONE=true; LASTMODE_FUTURETONE=true;
TypeFace2.deepCopyDefaultYPointers();
} }
} else { } else {
stillOnSongSelect=0; stillOnSongSelect=0;

@ -65,14 +65,24 @@ 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 final static int[] DEFAULT_YPOINTERS = new int[] {-1,-1,-1,-1,-1,-1,-1,-1};
public static int[] ypointers = new int[] {-1,-1,-1,-1,-1,-1,-1,-1};
public static void deepCopyDefaultYPointers() {
ypointers = new int[DEFAULT_YPOINTERS.length];
for (int i=0;i<DEFAULT_YPOINTERS.length;i++) {
ypointers[i]=DEFAULT_YPOINTERS[i];
}
}
public Result getAllData(BufferedImage img, boolean debug) throws IOException { 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];
Rectangle[] ranges = null; int pointerAccumulator = 0;
//result.isResult=MyRobot.IsResultsScreenshot(ImageUtils.toBufferedImage(img2.getScaledInstance(1227, 690, Image.SCALE_SMOOTH))); Rectangle[] ranges = null;
result.mode = getMode(img2); result.mode = getMode(img2);
@ -110,7 +120,8 @@ public class TypeFace2 {
} }
finalNumbers[i]=extractNumbersFromImage(img2.getSubimage( finalNumbers[i]=extractNumbersFromImage(img2.getSubimage(
r.x,r.y,r.width,r.height),debug); r.x,r.y,r.width,r.height),debug,pointerAccumulator);
ypointers[pointerAccumulator++] = ypointer;
//System.out.println(finalNumbers[i]); //System.out.println(finalNumbers[i]);
if (finalNumbers[i]==-1) { if (finalNumbers[i]==-1) {
return result; return result;
@ -130,6 +141,7 @@ public class TypeFace2 {
percent = extractFutureTonePercentFromImage(img2,debug); percent = extractFutureTonePercentFromImage(img2,debug);
}break; }break;
} }
ypointers[pointerAccumulator++] = ypointer;
if (percent<0) { if (percent<0) {
return result; return result;
} }
@ -186,30 +198,34 @@ public class TypeFace2 {
case MEGAMIX:{ case MEGAMIX:{
//1109,435 //1109,435
result.combo = extractNumbersFromImage(img2.getSubimage( result.combo = extractNumbersFromImage(img2.getSubimage(
MEGAMIX_RECT_SEARCH_COMBO.x,MEGAMIX_RECT_SEARCH_COMBO.y,MEGAMIX_RECT_SEARCH_COMBO.width,MEGAMIX_RECT_SEARCH_COMBO.height),debug); MEGAMIX_RECT_SEARCH_COMBO.x,MEGAMIX_RECT_SEARCH_COMBO.y,MEGAMIX_RECT_SEARCH_COMBO.width,MEGAMIX_RECT_SEARCH_COMBO.height),debug,pointerAccumulator);
if (result.combo<0) { if (result.combo<0) {
return result; return result;
} }
ypointers[pointerAccumulator++] = ypointer;
result.score = extractScoreNumbersFromImage(img2.getSubimage( result.score = extractScoreNumbersFromImage(img2.getSubimage(
MEGAMIX_RECT_SEARCH_SCORE.x,MEGAMIX_RECT_SEARCH_SCORE.y,MEGAMIX_RECT_SEARCH_SCORE.width,MEGAMIX_RECT_SEARCH_SCORE.height),debug); MEGAMIX_RECT_SEARCH_SCORE.x,MEGAMIX_RECT_SEARCH_SCORE.y,MEGAMIX_RECT_SEARCH_SCORE.width,MEGAMIX_RECT_SEARCH_SCORE.height),debug,pointerAccumulator);
if (result.score<0) { if (result.score<0) {
return result; return result;
} }
ypointers[pointerAccumulator++] = ypointer;
}break; }break;
case FUTURETONE:{ case FUTURETONE:{
//1109,435 //1109,435
result.combo = extractNumbersFromImage(img2.getSubimage( result.combo = extractNumbersFromImage(img2.getSubimage(
FUTURETONE_RECT_SEARCH_COMBO.x,FUTURETONE_RECT_SEARCH_COMBO.y,FUTURETONE_RECT_SEARCH_COMBO.width,FUTURETONE_RECT_SEARCH_COMBO.height),debug); FUTURETONE_RECT_SEARCH_COMBO.x,FUTURETONE_RECT_SEARCH_COMBO.y,FUTURETONE_RECT_SEARCH_COMBO.width,FUTURETONE_RECT_SEARCH_COMBO.height),debug,pointerAccumulator);
if (result.combo<0) { if (result.combo<0) {
return result; return result;
} }
ypointers[pointerAccumulator++] = ypointer;
result.score = extractFutureToneScoreNumbersFromImage(img2.getSubimage( result.score = extractFutureToneScoreNumbersFromImage(img2.getSubimage(
FUTURETONE_RECT_SEARCH_SCORE.x,FUTURETONE_RECT_SEARCH_SCORE.y,FUTURETONE_RECT_SEARCH_SCORE.width,FUTURETONE_RECT_SEARCH_SCORE.height),debug); FUTURETONE_RECT_SEARCH_SCORE.x,FUTURETONE_RECT_SEARCH_SCORE.y,FUTURETONE_RECT_SEARCH_SCORE.width,FUTURETONE_RECT_SEARCH_SCORE.height),debug,pointerAccumulator);
if (result.score<0) { if (result.score<0) {
return result; return result;
} }
ypointers[pointerAccumulator++] = ypointer;
}break; }break;
} }
@ -315,29 +331,6 @@ public class TypeFace2 {
for (int y=0;y<18;y++) { for (int y=0;y<18;y++) {
Color fontCol = new Color(futuretone_percentfont.getRGB(x+i*18,y)); Color fontCol = new Color(futuretone_percentfont.getRGB(x+i*18,y));
Color pixelCol = new Color(img.getRGB(xpointer-18+x+1, y+ypointer)); Color pixelCol = new Color(img.getRGB(xpointer-18+x+1, y+ypointer));
/*if (fontCol.equals(Color.RED) && pixelCol.getRed()<50
&& pixelCol.getGreen()<150 && pixelCol.getBlue()>150) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.RED.getRGB());
}
} else
if (fontCol.equals(Color.GREEN) && (pixelCol.getRed()>50
|| pixelCol.getGreen()>170 || pixelCol.getBlue()<150)) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.GREEN.getRGB());
}
} else
if (debug) {
test.setRGB(x, y, pixelCol.getRGB());
}*/
if (fontCol.equals(Color.RED)) { if (fontCol.equals(Color.RED)) {
if (lightColorCheck(pixelCol)) { if (lightColorCheck(pixelCol)) {
@ -425,29 +418,6 @@ public class TypeFace2 {
for (int y=0;y<18;y++) { for (int y=0;y<18;y++) {
Color fontCol = new Color(futuretone_percentfont.getRGB(x+i*18,y)); Color fontCol = new Color(futuretone_percentfont.getRGB(x+i*18,y));
Color pixelCol = new Color(img.getRGB(xpointer-18+x+1, y+ypointer)); Color pixelCol = new Color(img.getRGB(xpointer-18+x+1, y+ypointer));
/*if (fontCol.equals(Color.RED) && pixelCol.getRed()<50
&& pixelCol.getGreen()<150 && pixelCol.getBlue()>150) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.RED.getRGB());
}
} else
if (fontCol.equals(Color.GREEN) && (pixelCol.getRed()>50
|| pixelCol.getGreen()>170 || pixelCol.getBlue()<150)) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.GREEN.getRGB());
}
} else
if (debug) {
test.setRGB(x, y, pixelCol.getRGB());
}*/
if (fontCol.equals(Color.RED)) { if (fontCol.equals(Color.RED)) {
if (lightColorCheck(pixelCol)) { if (lightColorCheck(pixelCol)) {
@ -548,29 +518,6 @@ public class TypeFace2 {
for (int y=0;y<29;y++) { for (int y=0;y<29;y++) {
Color fontCol = new Color(percentfont.getRGB(x+i*24,y)); Color fontCol = new Color(percentfont.getRGB(x+i*24,y));
Color pixelCol = new Color(img.getRGB(xpointer-24+x+1, y+ypointer)); Color pixelCol = new Color(img.getRGB(xpointer-24+x+1, y+ypointer));
/*if (fontCol.equals(Color.RED) && pixelCol.getRed()<50
&& pixelCol.getGreen()<150 && pixelCol.getBlue()>150) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.RED.getRGB());
}
} else
if (fontCol.equals(Color.GREEN) && (pixelCol.getRed()>50
|| pixelCol.getGreen()>170 || pixelCol.getBlue()<150)) {
//Breaks a rule.
ruleBreak=true;
if (!debug) {
break colorloop;
} else {
test.setRGB(x, y, Color.GREEN.getRGB());
}
} else
if (debug) {
test.setRGB(x, y, pixelCol.getRGB());
}*/
if (fontCol.equals(Color.RED)) { if (fontCol.equals(Color.RED)) {
if (lightColorCheck(pixelCol)) { if (lightColorCheck(pixelCol)) {
@ -771,22 +718,25 @@ public class TypeFace2 {
&& pixel.getGreen()<178 && pixel.getBlue()>100; && pixel.getGreen()<178 && pixel.getBlue()>100;
} }
public int extractNumbersFromImage(BufferedImage img) throws IOException { public int extractNumbersFromImage(BufferedImage img,boolean debug,int iteration) throws IOException {
return extractNumbersFromImage(img,false);
}
public int extractNumbersFromImage(BufferedImage img,boolean debug) throws IOException {
this.img=img; this.img=img;
File f = null; File f = null;
BufferedImage test = null; BufferedImage test = null;
xpointer=MEGAMIX_RECT_SEARCH_COOL.width-1; xpointer=MEGAMIX_RECT_SEARCH_COOL.width-1;
ypointer=0; ypointer=0;
String total = ""; String total = "";
boolean startPointer=ypointers[iteration]>=0;
if (startPointer) {
ypointer=ypointers[iteration];
System.out.println("Found a saved ypointer of "+ypointer);
}
trialloop: trialloop:
while (ypointer<8) { while (ypointer<8) {
xpointer=MEGAMIX_RECT_SEARCH_COOL.width-1; xpointer=MEGAMIX_RECT_SEARCH_COOL.width-1;
while (xpointer>22) { while (xpointer>22) {
int distance = 0;
int foundIndex = -1; int foundIndex = -1;
//Compare the 22x21 range. //Compare the 22x21 range.
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
@ -855,9 +805,14 @@ public class TypeFace2 {
if (total.length()>0) { if (total.length()>0) {
break trialloop; break trialloop;
} }
if (startPointer) {
startPointer=false;
ypointer=0;
System.out.println("Could not find with saved ypointer. Switching back to old ypointer.");
} else {
ypointer++; ypointer++;
} }
}
if (total.equals("")) { if (total.equals("")) {
return -1; return -1;
} else { } else {
@ -865,13 +820,20 @@ public class TypeFace2 {
} }
} }
public int extractFutureToneScoreNumbersFromImage(BufferedImage img,boolean debug) throws IOException { public int extractFutureToneScoreNumbersFromImage(BufferedImage img,boolean debug,int iteration) throws IOException {
this.img=img; this.img=img;
File f = null; File f = null;
BufferedImage test = null; BufferedImage test = null;
xpointer=FUTURETONE_RECT_SEARCH_SCORE.width-1; xpointer=FUTURETONE_RECT_SEARCH_SCORE.width-1;
ypointer=0; ypointer=0;
String total = ""; String total = "";
boolean startPointer=ypointers[iteration]>=0;
if (startPointer) {
ypointer=ypointers[iteration];
}
trialloop: trialloop:
while (ypointer<20) { while (ypointer<20) {
xpointer=FUTURETONE_RECT_SEARCH_SCORE.width-1; xpointer=FUTURETONE_RECT_SEARCH_SCORE.width-1;
@ -945,8 +907,13 @@ public class TypeFace2 {
if (total.length()>0) { if (total.length()>0) {
break trialloop; break trialloop;
} }
if (startPointer) {
startPointer=false;
ypointer=0;
} else {
ypointer++; ypointer++;
} }
}
if (total.equals("")) { if (total.equals("")) {
return -1; return -1;
@ -955,13 +922,20 @@ public class TypeFace2 {
} }
} }
public int extractScoreNumbersFromImage(BufferedImage img,boolean debug) throws IOException { public int extractScoreNumbersFromImage(BufferedImage img,boolean debug,int iteration) throws IOException {
this.img=img; this.img=img;
File f = null; File f = null;
BufferedImage test = null; BufferedImage test = null;
xpointer=MEGAMIX_RECT_SEARCH_SCORE.width-1; xpointer=MEGAMIX_RECT_SEARCH_SCORE.width-1;
ypointer=0; ypointer=0;
String total = ""; String total = "";
boolean startPointer=ypointers[iteration]>=0;
if (startPointer) {
ypointer=ypointers[iteration];
}
trialloop: trialloop:
while (ypointer<12) { while (ypointer<12) {
xpointer=MEGAMIX_RECT_SEARCH_SCORE.width-1; xpointer=MEGAMIX_RECT_SEARCH_SCORE.width-1;
@ -1035,8 +1009,13 @@ public class TypeFace2 {
if (total.length()>0) { if (total.length()>0) {
break trialloop; break trialloop;
} }
if (startPointer) {
startPointer=false;
ypointer=0;
} else {
ypointer++; ypointer++;
} }
}
if (total.equals("")) { if (total.equals("")) {
return -1; return -1;

Loading…
Cancel
Save