Initialize new ColorRegion class.

secondmonitor
sigonasr2 4 years ago
parent 6cb33c4380
commit 31b802a47e
  1. BIN
      DivaBot/DivaBot.jar
  2. 8
      DivaBot/calibration_data.txt
  3. BIN
      DivaBot/capture_1.png
  4. BIN
      DivaBot/capture_2.png
  5. BIN
      DivaBot/capture_3.png
  6. BIN
      DivaBot/changemonitor.png
  7. BIN
      DivaBot/rectangle0.png
  8. BIN
      DivaBot/rectangle1.png
  9. BIN
      DivaBot/rectangle2.png
  10. BIN
      DivaBot/rectangle3.png
  11. BIN
      DivaBot/rectangle4.png
  12. 72
      DivaBot/src/sig/ColorRegion.java
  13. 23
      DivaBot/src/sig/MyRobot.java
  14. 4
      DivaBot/src/sig/Overlay.java
  15. BIN
      Release/DivaBot04B.zip

Binary file not shown.

@ -1,4 +1,4 @@
533 643
170 365
1459 1491
693 844

Binary file not shown.

After

Width:  |  Height:  |  Size: 735 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 908 KiB

After

Width:  |  Height:  |  Size: 712 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 938 KiB

After

Width:  |  Height:  |  Size: 732 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.5 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: 5.6 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

@ -0,0 +1,72 @@
package sig;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
public class ColorRegion {
Rectangle region;
BufferedImage img;
ColorRegion(BufferedImage img, Rectangle region) {
this.region=region;
this.img=img;
}
public boolean getRedRange(int min,int max) {
int avgRed = getRed();
return avgRed>=min&&avgRed<=max;
}
public boolean getGreenRange(int min,int max) {
int avgGreen = getGreen();
return avgGreen>=min&&avgGreen<=max;
}
public boolean getBlueRange(int min,int max) {
int avgBlue = getBlue();
return avgBlue>=min&&avgBlue<=max;
}
public boolean getAllRange(int min,int max) {
return getRedRange(min,max)&&getGreenRange(min,max)&&getBlueRange(min,max);
}
public boolean getAllRange(int minRed,int maxRed,int minGreen,int maxGreen,int minBlue,int maxBlue) {
return getRedRange(minRed,maxRed)&&getGreenRange(minGreen,maxGreen)&&getBlueRange(minBlue,maxBlue);
}
public int getRed() {
int total = 0;
for (int x=0;x<region.width;x++) {
for (int y=0;y<region.height;y++) {
total+=new Color(img.getRGB(region.x+x, region.y+y)).getRed();
}
}
return total/(region.width*region.height);
}
public int getGreen() {
int total = 0;
for (int x=0;x<region.width;x++) {
for (int y=0;y<region.height;y++) {
total+=new Color(img.getRGB(region.x+x, region.y+y)).getGreen();
}
}
return total/(region.width*region.height);
}
public int getBlue() {
int total = 0;
for (int x=0;x<region.width;x++) {
for (int y=0;y<region.height;y++) {
total+=new Color(img.getRGB(region.x+x, region.y+y)).getBlue();
}
}
return total/(region.width*region.height);
}
public String toString() {
StringBuilder sb = new StringBuilder("ColorRegion(Region: ");
return sb.append(region).append(",")
.append("R:").append(getRed()).append(",")
.append("G:").append(getGreen()).append(",")
.append("B:").append(getBlue()).append(")")
.toString();
}
}

@ -168,11 +168,21 @@ public class MyRobot{
public static long lastmainlooptime = 0; public static long lastmainlooptime = 0;
public static Result lastData=null; public static Result lastData=null;
public static int screen=0;
public static void main(String[] args) throws JSONException, IOException, FontFormatException { public static void main(String[] args) throws JSONException, IOException, FontFormatException {
if (args.length>0) { if (args.length>0) {
if (args[0].equalsIgnoreCase("calibrate")) { if (args[0].equalsIgnoreCase("calibrate")) {
File f = new File("screenConfig.txt");
if (f.exists()) {
String[] data= FileUtils.readFromFile("screenConfig.txt");
try {
screen=Integer.parseInt(data[0]);
} catch (Exception e) {
System.err.println("Could not read from screenConfig.txt. It's invalid data, consider deleting the file and run the program again.");
}
}
CALIBRATION_MODE=true; CALIBRATION_MODE=true;
} }
if (args[0].equalsIgnoreCase("debug")) { if (args[0].equalsIgnoreCase("debug")) {
@ -535,8 +545,8 @@ public class MyRobot{
Color c2 = new Color(MYROBOT.createScreenCapture(new Rectangle(31,196,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)); Color c3 = new Color(MYROBOT.createScreenCapture(new Rectangle(483,256,40,40)).getRGB(0, 0));
//System.out.println(c1+"/"+c2+"/"+c3); //System.out.println(c1+"/"+c2+"/"+c3);
return c1.getRed()>=250 && c1.getGreen()>=250 && c1.getBlue()>=250 && c2.getRed()>=7 && c2.getRed()<=30 && c2.getGreen()>=200 && c2.getGreen()<=240 && c2.getBlue()>=180 && c2.getBlue()<=220 && 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()>=160 && c3.getRed()<=255 && c3.getGreen()>=160 && c3.getGreen()<=255 && c3.getBlue()>=130 && c3.getBlue()<=220; 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)); Color ft_pixel1 = new Color(img2.getRGB(260, 38));
@ -772,6 +782,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("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);
@ -935,8 +946,8 @@ public class MyRobot{
} }
public static boolean checkSongSelect() throws IOException { public static boolean checkSongSelect() throws IOException {
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(845,638,1,1)).getRGB(0, 0)); ColorRegion cr = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(842,635,5,5));
onSongSelect = (c.getRed()>=15 && c.getRed()<=45 && c.getGreen()>=75 && c.getGreen()<=90 && c.getBlue()>=200 && c.getBlue()<=230); onSongSelect = cr.getAllRange(15,45,75,90,200,230);
if (onSongSelect) { if (onSongSelect) {
stillOnSongSelect++; stillOnSongSelect++;
@ -948,8 +959,8 @@ public class MyRobot{
} }
} else } else
{ {
c = new Color(MYROBOT.createScreenCapture(new Rectangle(743,173,1,1)).getRGB(0, 0)); cr = new ColorRegion(MYROBOT.createScreenCapture(),new Rectangle(741,171,5,5));
if (!onSongSelect&&(c.getRed()>=160&&c.getRed()<=200&&c.getGreen()<=15&&c.getBlue()>=170&&c.getBlue()<=200)) { if (!onSongSelect&&cr.getAllRange(160,200,0,15,170,200)) {
stillOnSongSelect++; stillOnSongSelect++;
FUTURETONE=true; FUTURETONE=true;
onSongSelect=true; onSongSelect=true;

@ -8,6 +8,7 @@ import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -23,11 +24,13 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
public static boolean started=false; public static boolean started=false;
BufferedImage setupWindowButton; BufferedImage setupWindowButton;
BufferedImage finishButton; BufferedImage finishButton;
BufferedImage changeMonitorButton;
Font drawFont = new Font("Verdana",Font.PLAIN,32); Font drawFont = new Font("Verdana",Font.PLAIN,32);
Overlay() throws IOException { Overlay() throws IOException {
setupWindowButton = ImageIO.read(new File("setupwindow.png")); setupWindowButton = ImageIO.read(new File("setupwindow.png"));
finishButton = ImageIO.read(new File("finish.png")); finishButton = ImageIO.read(new File("finish.png"));
changeMonitorButton = ImageIO.read(new File("changemonitor.png"));
Thread t = new Thread() { Thread t = new Thread() {
public void run() { public void run() {
while (true) { while (true) {
@ -95,6 +98,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
} else } else
{ {
g.drawImage(setupWindowButton,MyRobot.screenSize.width-setupWindowButton.getWidth()+1,0,this); g.drawImage(setupWindowButton,MyRobot.screenSize.width-setupWindowButton.getWidth()+1,0,this);
//g.drawImage(changeMonitorButton,MyRobot.screenSize.width-changeMonitorButton.getWidth()+1,setupWindowButton.getHeight(),this);
} }
} }

Binary file not shown.
Loading…
Cancel
Save