Correct basic tests using a Y range system for normal numbers.

secondmonitor
sigonasr2 4 years ago
parent 6a270300b7
commit c8af68b140
  1. BIN
      DivaBot/DivaBot.jar
  2. 8
      DivaBot/calibration_data.txt
  3. BIN
      DivaBot/rectangle0.png
  4. BIN
      DivaBot/rectangle1.png
  5. BIN
      DivaBot/rectangle2.png
  6. BIN
      DivaBot/rectangle3.png
  7. BIN
      DivaBot/rectangle4.png
  8. 4
      DivaBot/src/sig/Calibrator.java
  9. 37
      DivaBot/src/sig/MyRobot.java
  10. 3
      DivaBot/src/sig/Result.java
  11. 8
      DivaBot/src/sig/SongData.java
  12. 65
      DivaBot/src/sig/TypeFace2.java
  13. BIN
      DivaBot/typeface.png
  14. BIN
      DivaBot/typeface2.png

Binary file not shown.

@ -1,4 +1,4 @@
517 521
265 299
1485 1490
808 842

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

@ -207,9 +207,9 @@ public class Calibrator{
//ImageIO.write(miniImg,"png",new File("capture_"+System.nanoTime()+".png")); //ImageIO.write(miniImg,"png",new File("capture_"+System.nanoTime()+".png"));
Color col = new Color(miniImg.getRGB(0, 0)); Color col = new Color(miniImg.getRGB(0, 0));
System.out.println("Checking "+col); System.out.println("Checking "+col);
if ((col.getRed()>=5&&col.getRed()<=40&& if ((col.getRed()>=5&&col.getRed()<=75&&
col.getGreen()>=170&&col.getGreen()<=210&& col.getGreen()>=170&&col.getGreen()<=210&&
col.getBlue()>=205&&col.getBlue()<=250)) { col.getBlue()>=180&&col.getBlue()<=250)) {
//This is the max X. Calibration on this side good. //This is the max X. Calibration on this side good.
MyRobot.STARTDRAG.y=MyRobot.STARTDRAG.y+i; MyRobot.STARTDRAG.y=MyRobot.STARTDRAG.y+i;
//MyRobot.STARTDRAG.x--; //MyRobot.STARTDRAG.x--;

@ -205,12 +205,14 @@ public class MyRobot{
@Override @Override
public void run() { public void run() {
try { try {
if (CALIBRATION_MODE) {
if (MyRobot.calibrating) { if (MyRobot.calibrating) {
MyRobot.calibrating=false; MyRobot.calibrating=false;
Overlay.OVERLAY.setVisible(false); Overlay.OVERLAY.setVisible(false);
Thread.sleep(1000); Thread.sleep(1000);
Calibrator c = new Calibrator(); Calibrator c = new Calibrator();
} }
} else {
if (checkSongSelect()) { if (checkSongSelect()) {
if (!overlayHidden) { if (!overlayHidden) {
overlayHidden=true; overlayHidden=true;
@ -240,7 +242,6 @@ public class MyRobot{
p.repaint(0, 0, 1400, 1000); p.repaint(0, 0, 1400, 1000);
} }
if ((selectedSong!=null && difficulty!=null)) { if ((selectedSong!=null && difficulty!=null)) {
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) { if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
lastSongSelectTime=System.currentTimeMillis(); lastSongSelectTime=System.currentTimeMillis();
MYROBOT.setAutoDelay(0); MYROBOT.setAutoDelay(0);
@ -261,7 +262,8 @@ public class MyRobot{
} }
try { try {
Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture()); Result data = typeface1.getAllData(MYROBOT.createScoreScreenCapture());
//ImageIO.write(MYROBOT.createNormalScreenCapture(new Rectangle(418,204,1227,690)),"png",new File("test.png")); System.out.println(data);
//ImageIO.write(MYROBOT.,"png",new File("test.png"));
if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) { if (data.cool==-1 || data.fine==-1 || data.safe==-1 || data.sad==-1 || data.worst==-1 || data.percent<0f || data.percent>110f || data.combo==-1 || data.score==-1) {
System.out.println("Waiting for results to populate..."); System.out.println("Waiting for results to populate...");
} else } else
@ -383,15 +385,21 @@ public class MyRobot{
} }
} }
MYROBOT.refreshScreen(); MYROBOT.refreshScreen();
}
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
private boolean OnResultsScreen() { private boolean OnResultsScreen() throws IOException {
Color c1 = new Color(MYROBOT.createScreenCapture(new Rectangle(449,434,2,2)).getRGB(0, 0)); //r.x-418, r.y-204
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(449,400,2,2)).getRGB(0, 0)); ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(31,230,40,40)),"png",new File("color1.png"));
Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(901,460,2,2)).getRGB(0, 0)); 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"));
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()>=254 && c1.getGreen()>=254 && c1.getBlue()>=254 && c2.getRed()==16 && c2.getGreen()==222 && c2.getBlue()==202 && return c1.getRed()>=254 && c1.getGreen()>=254 && c1.getBlue()>=254 && c2.getRed()==16 && c2.getGreen()==222 && c2.getBlue()==202 &&
c3.getRed()>=219 && c3.getRed()<=255 && c3.getGreen()>=213 && c3.getGreen()<=255 && c3.getBlue()>=160 && c3.getBlue()<=220; c3.getRed()>=219 && c3.getRed()<=255 && c3.getGreen()>=213 && c3.getGreen()<=255 && c3.getBlue()>=160 && c3.getBlue()<=220;
} }
@ -571,6 +579,7 @@ public class MyRobot{
f.add(OVERLAY); f.add(OVERLAY);
f.setBackground(new Color(0,0,0,0)); f.setBackground(new Color(0,0,0,0));
} else { } else {
RunTests();
f.setSize(1362, 1036); f.setSize(1362, 1036);
f.add(p); f.add(p);
} }
@ -581,12 +590,12 @@ public class MyRobot{
title.setText((currentSong>=SONGNAMES.length)?"DONE!":SONGNAMES[currentSong].name); title.setText((currentSong>=SONGNAMES.length)?"DONE!":SONGNAMES[currentSong].name);
SongData s = SongData.getByTitle(SONGNAMES[currentSong].name); //SongData s = SongData.getByTitle(SONGNAMES[currentSong].name);
BotMain(); BotMain();
} }
void RunTests() throws IOException { static void RunTests() throws IOException {
selectedSong=new SongData("LIKE THE WIND",new Color[] {}); selectedSong=new SongData("LIKE THE WIND",new Color[] {});
difficulty="H"; difficulty="H";
@ -609,6 +618,7 @@ public class MyRobot{
RunTest("test16.png",320,46,2,0,4,93.26f,"EXEX","HS",135,463170,false); RunTest("test16.png",320,46,2,0,4,93.26f,"EXEX","HS",135,463170,false);
RunTest("test17.png",431,30,3,0,3,100.51f,"EXEX","HS",386,581700,false); RunTest("test17.png",431,30,3,0,3,100.51f,"EXEX","HS",386,581700,false);
RunTest("test18.png",427,86,5,1,4,92.45f,"EX","HS",136,526740,false); RunTest("test18.png",427,86,5,1,4,92.45f,"EX","HS",136,526740,false);
RunTest("test19.png",4,2,2,0,95,0.42f,"EXEX","HS",2,4130,true);
RunTest("testimage.png",371,40,3,4,3,97.63f,"EX","HS",233,523750,false); RunTest("testimage.png",371,40,3,4,3,97.63f,"EX","HS",233,523750,false);
RunTest("testimage2.png",942,71,1,0,3,97.02f,"EXEX","",714,951020,false); RunTest("testimage2.png",942,71,1,0,3,97.02f,"EXEX","",714,951020,false);
RunTest("testimage3.png",546,52,0,0,0,101.77f,"EX","",598,567430,false); RunTest("testimage3.png",546,52,0,0,0,101.77f,"EX","",598,567430,false);
@ -649,11 +659,11 @@ public class MyRobot{
RunTest("サマーアイドル.jpg",245,19,4,0,2,87.04f,"E","",103,179360,false); RunTest("サマーアイドル.jpg",245,19,4,0,2,87.04f,"E","",103,179360,false);
} }
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) 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) throws IOException {
RunTest(_img,_cool,_fine,_safe,_sad,_worst,_percent,_difficulty,_mod,_combo,_score,_fail,false); RunTest(_img,_cool,_fine,_safe,_sad,_worst,_percent,_difficulty,_mod,_combo,_score,_fail,false);
} }
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,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,boolean debug) throws IOException {
System.out.println("Running test "+_img); System.out.println("Running test "+_img);
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
String testdir="testsuite"; String testdir="testsuite";
@ -671,6 +681,7 @@ public class MyRobot{
e.printStackTrace(); e.printStackTrace();
} }
Result data = typeface1.getAllData(img,debug); Result data = typeface1.getAllData(img,debug);
try {
assert data.cool == _cool : "Expected cool count to be "+_cool+", got "+data.cool; assert data.cool == _cool : "Expected cool count to be "+_cool+", got "+data.cool;
assert data.fine == _fine : "Expected fine count to be "+_fine+", got "+data.fine; assert data.fine == _fine : "Expected fine count to be "+_fine+", got "+data.fine;
assert data.safe == _safe : "Expected safe count to be "+_safe+", got "+data.safe; assert data.safe == _safe : "Expected safe count to be "+_safe+", got "+data.safe;
@ -682,7 +693,11 @@ public class MyRobot{
assert data.difficulty == _difficulty : "Expected difficulty to be "+_difficulty+", got "+data.difficulty; assert data.difficulty == _difficulty : "Expected difficulty to be "+_difficulty+", got "+data.difficulty;
assert data.combo == _combo : "Expected combo to be "+_combo+", got "+data.combo; assert data.combo == _combo : "Expected combo to be "+_combo+", got "+data.combo;
assert data.score == _score : "Expected score to be "+_score+", got "+data.score; assert data.score == _score : "Expected score to be "+_score+", got "+data.score;
System.out.println(" Passed ("+(System.currentTimeMillis()-startTime)+"ms)!"); } catch(AssertionError e) {
System.err.println("\t"+e.getMessage()+" "+"("+(System.currentTimeMillis()-startTime)+"ms)!");
System.exit(1);
}
System.out.println("\tPassed ("+(System.currentTimeMillis()-startTime)+"ms)!");
} }
public static boolean checkSongSelect() throws IOException { public static boolean checkSongSelect() throws IOException {

@ -44,4 +44,7 @@ public class Result {
.append(",\"").append(difficulty).append("\",\"").append(mod).append("\",").append(Boolean.toString(fail).toLowerCase()) .append(",\"").append(difficulty).append("\",\"").append(mod).append("\",").append(Boolean.toString(fail).toLowerCase())
.append(",").append(combo).append(",").append(score).toString(); .append(",").append(combo).append(",").append(score).toString();
} }
public String toString() {
return displayDebug();
}
} }

@ -8,7 +8,7 @@ public class SongData {
String title; String title;
Color[] songCode; Color[] songCode;
int distance=0; int distance=0;
static int MAXTHRESHOLD=200000; static int MAXTHRESHOLD=400000;
final static float TOLERANCE = 0.95f; final static float TOLERANCE = 0.95f;
public SongData(String title,Color[] songCode) { public SongData(String title,Color[] songCode) {
this.title=title; this.title=title;
@ -38,16 +38,16 @@ public class SongData {
break; break;
}*/ }*/
} }
if (/*distance<=MAXTHRESHOLD && */distance<closestDistance) { if (/*distance<=MAXTHRESHOLD &&*/ distance<closestDistance) {
//System.out.println(distance+" pixels matched for song "+s.title); //System.out.println(distance+" pixels matched for song "+s.title);
closestSong=s; closestSong=s;
closestSong.distance=distance; closestSong.distance=distance;
closestDistance=distance; closestDistance=distance;
} }
if (distance>=MAXTHRESHOLD && distance<closestMaxThresholdDistance) { /*if (distance>=MAXTHRESHOLD && distance<closestMaxThresholdDistance) {
System.out.println(distance+" pixels diff: "+s.title); System.out.println(distance+" pixels diff: "+s.title);
closestMaxThresholdDistance=distance; closestMaxThresholdDistance=distance;
} }*/
} else { } else {
continue; continue;
} }

@ -38,18 +38,30 @@ public class TypeFace2 {
return getAllData(img,false); return getAllData(img,false);
} }
final static int XOFFSET = 8;
final static Rectangle RECT_SEARCH_COOL=new Rectangle(866+XOFFSET,260,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_FINE=new Rectangle(866+XOFFSET,294,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_SAFE=new Rectangle(866+XOFFSET,329,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_SAD=new Rectangle(866+XOFFSET,364,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_WORST=new Rectangle(866+XOFFSET,400,100+XOFFSET,22);
final static Rectangle RECT_SEARCH_PCT=new Rectangle(1182+XOFFSET,165,1132,168);
final static Rectangle RECT_SEARCH_PCT2=new Rectangle(1123+XOFFSET,165,1051,168);
final static Rectangle RECT_SEARCH_SCORE=new Rectangle(859+XOFFSET,578,250+XOFFSET,32);
final static Rectangle RECT_SEARCH_COMBO=new Rectangle(1010+XOFFSET,435,100+XOFFSET,20);
public Result getAllData(BufferedImage img, boolean debug) throws IOException,NumberFormatException,IndexOutOfBoundsException { public Result getAllData(BufferedImage img, boolean debug) throws IOException,NumberFormatException,IndexOutOfBoundsException {
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 = new Rectangle[] { Rectangle[] ranges = new Rectangle[] {
//These coords are in regard to the old screenshot sizes. //These coords are in regard to the old screenshot sizes.
new Rectangle(866,262,100,20), //33 pixels per line. RECT_SEARCH_COOL, //33 pixels per line.
new Rectangle(866,296,100,20), RECT_SEARCH_FINE,
new Rectangle(866,331,100,20), RECT_SEARCH_SAFE,
new Rectangle(866,366,100,20), RECT_SEARCH_SAD,
new Rectangle(866,400,100,20), RECT_SEARCH_WORST,
}; };
for (int i=0;i<ranges.length;i++) { for (int i=0;i<ranges.length;i++) {
@ -86,10 +98,10 @@ public class TypeFace2 {
//1109,435 //1109,435
result.combo = extractNumbersFromImage(img2.getSubimage( result.combo = extractNumbersFromImage(img2.getSubimage(
1010,435,100,20),debug); RECT_SEARCH_COMBO.x,RECT_SEARCH_COMBO.y,RECT_SEARCH_COMBO.width,RECT_SEARCH_COMBO.height),debug);
result.score = extractScoreNumbersFromImage(img2.getSubimage( result.score = extractScoreNumbersFromImage(img2.getSubimage(
859,578,250,32),debug); RECT_SEARCH_SCORE.x,RECT_SEARCH_SCORE.y,RECT_SEARCH_SCORE.width,RECT_SEARCH_SCORE.height),debug);
return result; return result;
} }
@ -131,14 +143,14 @@ public class TypeFace2 {
//second part: 1123 //second part: 1123
String decimal = ""; String decimal = "";
String integer = ""; String integer = "";
xpointer=1182; xpointer=RECT_SEARCH_PCT.x;
ypointer=165; ypointer=RECT_SEARCH_PCT.y;
BufferedImage test = null; BufferedImage test = null;
trialloop: trialloop:
while (ypointer<168) { while (ypointer<RECT_SEARCH_PCT.height) {
xpointer=1182; xpointer=RECT_SEARCH_PCT.x;
while (xpointer>1132) { while (xpointer>RECT_SEARCH_PCT.width) {
int foundIndex = -1; int foundIndex = -1;
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
if (debug) { if (debug) {
@ -243,12 +255,12 @@ public class TypeFace2 {
ypointer++; ypointer++;
} }
xpointer=1123; xpointer=RECT_SEARCH_PCT2.x;
ypointer=165; ypointer=RECT_SEARCH_PCT2.y;
trialloop: trialloop:
while (ypointer<168) { while (ypointer<RECT_SEARCH_PCT2.height) {
xpointer=1123; xpointer=RECT_SEARCH_PCT2.x;
while (xpointer>1051) { while (xpointer>RECT_SEARCH_PCT2.width) {
int foundIndex = -1; int foundIndex = -1;
for (int i=0;i<10;i++) { for (int i=0;i<10;i++) {
if (debug) { if (debug) {
@ -375,8 +387,12 @@ public class TypeFace2 {
this.img=img; this.img=img;
File f = null; File f = null;
BufferedImage test = null; BufferedImage test = null;
xpointer=99; xpointer=RECT_SEARCH_COOL.width-1;
ypointer=0;
String total = ""; String total = "";
trialloop:
while (ypointer<4) {
xpointer=RECT_SEARCH_COOL.width-1;
while (xpointer>22) { while (xpointer>22) {
int distance = 0; int distance = 0;
int foundIndex = -1; int foundIndex = -1;
@ -391,7 +407,7 @@ public class TypeFace2 {
for (int x=0;x<22;x++) { for (int x=0;x<22;x++) {
for (int y=0;y<20;y++) { for (int y=0;y<20;y++) {
Color fontCol = new Color(font.getRGB(x+i*22,y)); Color fontCol = new Color(font.getRGB(x+i*22,y));
Color pixelCol = new Color(img.getRGB(xpointer-22+x+1, y)); Color pixelCol = new Color(img.getRGB(xpointer-22+x+1, y+ypointer));
if (fontCol.equals(Color.RED) && pixelCol.getRed()<150 if (fontCol.equals(Color.RED) && pixelCol.getRed()<150
&& pixelCol.getGreen()<150 && pixelCol.getBlue()<150) { && pixelCol.getGreen()<150 && pixelCol.getBlue()<150) {
//Breaks a rule. //Breaks a rule.
@ -444,6 +460,11 @@ public class TypeFace2 {
xpointer--; xpointer--;
} }
} }
if (total.length()>0) {
break trialloop;
}
ypointer++;
}
if (total.equals("")) { if (total.equals("")) {
return -1; return -1;
@ -456,12 +477,12 @@ public class TypeFace2 {
this.img=img; this.img=img;
File f = null; File f = null;
BufferedImage test = null; BufferedImage test = null;
xpointer=249; xpointer=RECT_SEARCH_SCORE.width-1;
ypointer=0; ypointer=0;
String total = ""; String total = "";
trialloop: trialloop:
while (ypointer<4) { while (ypointer<4) {
xpointer=249; xpointer=RECT_SEARCH_SCORE.width-1;
while (xpointer>31) { while (xpointer>31) {
int distance = 0; int distance = 0;
int foundIndex = -1; int foundIndex = -1;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Loading…
Cancel
Save