Implement first stage calibration.
This commit is contained in:
parent
cb4174f7e5
commit
62d40b0076
@ -10,7 +10,7 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class Calibrator{
|
||||
Calibrator(JPanel p) throws IOException, InterruptedException {
|
||||
Calibrator() throws IOException, InterruptedException {
|
||||
boolean failed=false;
|
||||
int x = Math.min(MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.x);
|
||||
int y = Math.min(MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.y);
|
||||
@ -33,11 +33,10 @@ public class Calibrator{
|
||||
(int)Math.floor(x+width*0.03984375d),
|
||||
(int)Math.floor(y+height*0.30833333333333333333333333333333d));
|
||||
calibrationline=currentPointer;*/
|
||||
failed=CalibrationStage1(p);
|
||||
failed=CalibrationStage1();
|
||||
if (failed) {return;}
|
||||
failed=CalibrationStage2(p);
|
||||
failed=CalibrationStage2();
|
||||
if (failed) {return;}
|
||||
p.setVisible(true);
|
||||
MyRobot.CALIBRATIONSTATUS="First calibration set done: X"+(x-MyRobot.STARTDRAG.x)+" Y"+(y-MyRobot.STARTDRAG.y);
|
||||
// failed=CalibrationStage3(p);
|
||||
// if (failed) {return;}
|
||||
@ -46,11 +45,10 @@ public class Calibrator{
|
||||
//MyRobot.CALIBRATIONSTATUS="First calibration set done: X"+(x-MyRobot.STARTDRAG.x)+" Y"+(y-MyRobot.STARTDRAG.y);
|
||||
}
|
||||
|
||||
private boolean CalibrationStage1(JPanel p) throws IOException, InterruptedException {
|
||||
private boolean CalibrationStage1() throws IOException, InterruptedException {
|
||||
boolean calibrated=false;
|
||||
int MAXTRIES=10000;
|
||||
MyRobot.CALIBRATIONSTATUS="Calibration Stage 1...";
|
||||
p.repaint();
|
||||
//ImageIO.write(MYROBOT.getSizedCapture(new Rectangle(x,y,width,height)),"png",new File("capture.png"));
|
||||
BufferedImage currentScreen = MyRobot.MYROBOT.getSizedCapture(new Rectangle(0,0,MyRobot.screenSize.width,MyRobot.screenSize.height));
|
||||
ImageIO.write(currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y),"png",new File("capture.png"));
|
||||
@ -58,30 +56,29 @@ public class Calibrator{
|
||||
//Try moving left until the difference is too high or the colors are not right anymore.
|
||||
MyRobot.STARTDRAG.x-=1;
|
||||
//BufferedImage pixel = MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1));
|
||||
currentScreen = currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1);
|
||||
ImageIO.write(currentScreen,"png",new File("capture_"+System.nanoTime()+".png"));
|
||||
Color col = new Color(currentScreen.getRGB(0, 0));
|
||||
System.out.println("Checking "+col);
|
||||
BufferedImage miniImg = currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1);
|
||||
ImageIO.write(miniImg,"png",new File("capture_"+System.nanoTime()+".png"));
|
||||
Color col = new Color(miniImg.getRGB(0, 0));
|
||||
//System.out.println("Checking "+col);
|
||||
if (!(col.getRed()>=5&&col.getRed()<=40&&
|
||||
col.getGreen()>=170&&col.getGreen()<=210&&
|
||||
col.getBlue()>=205&&col.getBlue()<=250)) {
|
||||
//This is the max X. Calibration on this side good.
|
||||
MyRobot.STARTDRAG.x++;
|
||||
System.out.println("End at "+MyRobot.STARTDRAG.x);
|
||||
//System.out.println("End at "+MyRobot.STARTDRAG.x);
|
||||
return false;
|
||||
}
|
||||
MAXTRIES--;
|
||||
}
|
||||
MyRobot.CALIBRATIONSTATUS="Calibration failed! Try making the capture region larger and defining it more accurately.";
|
||||
p.repaint();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean CalibrationStage2(JPanel p) throws IOException {
|
||||
private boolean CalibrationStage2() throws IOException {
|
||||
boolean calibrated=false;
|
||||
int MAXTRIES=10000;
|
||||
MyRobot.CALIBRATIONSTATUS="Calibration Stage 2...";
|
||||
p.repaint();
|
||||
//ImageIO.write(MYROBOT.getSizedCapture(new Rectangle(x,y,width,height)),"png",new File("capture.png"));
|
||||
//BufferedImage currentScreen = MYROBOT.getSizedCapture(new Rectangle(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG,height));
|
||||
BufferedImage currentScreen = MyRobot.MYROBOT.getSizedCapture(new Rectangle(0,0,MyRobot.screenSize.width,MyRobot.screenSize.height));
|
||||
@ -89,24 +86,22 @@ public class Calibrator{
|
||||
while (!calibrated&&MAXTRIES>0) {
|
||||
//Try moving left until the difference is too high or the colors are not right anymore.
|
||||
MyRobot.STARTDRAG.y-=1;
|
||||
p.repaint();
|
||||
//currentScreen.setRGB(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y, new Color(0,0,0).getRGB());
|
||||
currentScreen = currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1);
|
||||
ImageIO.write(currentScreen,"png",new File("capture_2_"+System.nanoTime()+".png"));
|
||||
Color col = new Color(currentScreen.getRGB(0, 0));
|
||||
System.out.println("Checking "+col);
|
||||
BufferedImage miniImg = currentScreen.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,1,1);
|
||||
ImageIO.write(miniImg,"png",new File("capture_"+System.nanoTime()+".png"));
|
||||
Color col = new Color(miniImg.getRGB(0, 0));
|
||||
//System.out.println("Checking "+col);
|
||||
if (!(col.getRed()>=5&&col.getRed()<=40&&
|
||||
col.getGreen()>=170&&col.getGreen()<=210&&
|
||||
col.getBlue()>=205&&col.getBlue()<=250)) {
|
||||
//This is the max Y. Calibration on this side good.
|
||||
MyRobot.STARTDRAG.y++;
|
||||
System.out.println("End at "+MyRobot.STARTDRAG.y);
|
||||
//System.out.println("End at "+MyRobot.STARTDRAG.y);
|
||||
return false;
|
||||
}
|
||||
MAXTRIES--;
|
||||
}
|
||||
MyRobot.CALIBRATIONSTATUS="Calibration failed! Try making the capture region larger and defining it more accurately.";
|
||||
p.repaint();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public class MyRobot{
|
||||
static Dimension screenSize = new Dimension(0,0);
|
||||
static boolean dragging = false;
|
||||
static String CALIBRATIONSTATUS = "";
|
||||
static boolean calibrating=true;
|
||||
static boolean calibrating=false;
|
||||
static Rectangle calibrationline = null;
|
||||
static boolean repaintCalled = false;
|
||||
public static Overlay OVERLAY;
|
||||
@ -198,6 +198,12 @@ public class MyRobot{
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (MyRobot.calibrating) {
|
||||
MyRobot.calibrating=false;
|
||||
Overlay.OVERLAY.setVisible(false);
|
||||
Thread.sleep(1000);
|
||||
Calibrator c = new Calibrator();
|
||||
}
|
||||
if (checkSongSelect()) {
|
||||
if (!overlayHidden) {
|
||||
overlayHidden=true;
|
||||
|
@ -10,6 +10,8 @@ import javax.swing.JPanel;
|
||||
|
||||
public class Overlay extends JPanel implements MouseMotionListener,MouseListener{
|
||||
|
||||
public static Overlay OVERLAY;
|
||||
|
||||
Overlay() {
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
@ -24,6 +26,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
OVERLAY=this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,6 +65,7 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
|
||||
MyRobot.STARTDRAG.y=MyRobot.ENDDRAG.y;
|
||||
MyRobot.ENDDRAG.y=xTemp;
|
||||
}
|
||||
MyRobot.calibrating=true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user