Partial implementation of reworked screen recognition algorithm, further
testing required.
2
DivaBot/.gitignore
vendored
@ -11,3 +11,5 @@
|
||||
/39/
|
||||
/1925/
|
||||
/39みゅーじっく!/
|
||||
*.png
|
||||
!/*.png
|
BIN
DivaBot/rectangle0.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
DivaBot/rectangle1.png
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
DivaBot/rectangle2.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
DivaBot/rectangle3.png
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
DivaBot/rectangle4.png
Normal file
After Width: | Height: | Size: 4.4 KiB |
43
DivaBot/src/sig/CustomRobot.java
Normal file
@ -0,0 +1,43 @@
|
||||
package sig;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import sig.utils.ImageUtils;
|
||||
|
||||
public class CustomRobot extends Robot{
|
||||
|
||||
BufferedImage currentScreen;
|
||||
BufferedImage scoreCurrentScreen;
|
||||
|
||||
public CustomRobot() throws AWTException {
|
||||
super();
|
||||
}
|
||||
|
||||
public CustomRobot(GraphicsDevice screen) throws AWTException {
|
||||
super(screen);
|
||||
}
|
||||
|
||||
public void refreshScreen() {
|
||||
currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83));
|
||||
}
|
||||
public void refreshScoreScreen() {
|
||||
scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23,204+85,912-18,586-83));
|
||||
}
|
||||
|
||||
public synchronized BufferedImage createScreenCapture(Rectangle r) {
|
||||
BufferedImage img2 = ImageUtils.toBufferedImage(currentScreen.getScaledInstance(1227, 690, BufferedImage.SCALE_AREA_AVERAGING));
|
||||
return img2.getSubimage(r.x-418, r.y-204, r.width, r.height);
|
||||
}
|
||||
public synchronized BufferedImage createNormalScreenCapture(Rectangle r) {
|
||||
return currentScreen.getSubimage((int)((r.x-418)*(894d/1227)), (int)((r.y-204)*(503d/690)), (int)Math.ceil(r.width*(894d/1227)), (int)Math.ceil(r.height*(503d/690)));
|
||||
//return super.createScreenCapture(new Rectangle(r.x-418,r.y-204,912-18,586-83));
|
||||
}
|
||||
}
|
@ -57,7 +57,9 @@ public class DrawCanvas extends JPanel implements KeyListener{
|
||||
BufferedImage overallbar;
|
||||
BufferedImage panel,paneloverlay,songpanel,songpaneloverlay;
|
||||
long ratingTime = System.currentTimeMillis()-10000;
|
||||
long bestPlayTime = System.currentTimeMillis()-10000;
|
||||
int lastRating = -1;
|
||||
double lastScore = 0d;
|
||||
Thread t = null;
|
||||
boolean scrolling = false;
|
||||
int scrollX = 0;
|
||||
@ -111,7 +113,7 @@ public class DrawCanvas extends JPanel implements KeyListener{
|
||||
passes=0;
|
||||
fcCount=0;
|
||||
artist="";
|
||||
this.repaint(0,0,1400,100);
|
||||
this.repaint(0,0,1400,1000);
|
||||
if (t!=null && t.isAlive()) {
|
||||
t.stop();
|
||||
}
|
||||
@ -132,6 +134,7 @@ public class DrawCanvas extends JPanel implements KeyListener{
|
||||
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
|
||||
if (obj.has("cool")) {
|
||||
bestPlay = new Result(MyRobot.p.songname,difficulty,obj.getInt("cool"),obj.getInt("fine"),obj.getInt("safe"),obj.getInt("sad"),obj.getInt("worst"),(float)obj.getDouble("percent"));
|
||||
lastScore = obj.getDouble("score");
|
||||
} else {
|
||||
bestPlay = null;
|
||||
}
|
||||
@ -182,11 +185,21 @@ public class DrawCanvas extends JPanel implements KeyListener{
|
||||
g2.drawImage(panel, 484,935,null);
|
||||
g2.drawImage(panel, 968,935,null);
|
||||
|
||||
DrawUtils.drawOutlineText(g2, programFont, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), ((romanizedname.length()>0)?romanizedname:englishname));
|
||||
|
||||
DrawUtils.drawOutlineText(g2, programFontSmall, 8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),((bestPlay!=null)?bestPlay.display():""));
|
||||
String songDisplay = ((romanizedname.length()>0)?romanizedname:englishname) + " - " + artist;
|
||||
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(songDisplay, programFont);
|
||||
if (bounds.getWidth()>675) {
|
||||
DrawUtils.drawOutlineText(g2, programFontSmall, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay);
|
||||
} else {
|
||||
DrawUtils.drawOutlineText(g2, programFont, 8, 42, 1, Color.WHITE, new Color(0,0,0,64), songDisplay);
|
||||
}
|
||||
|
||||
if ((bestPlayTime>System.currentTimeMillis()-10000)) {
|
||||
DrawUtils.drawOutlineText(g2, programFont, 8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-bestPlayTime))/5,255)), new Color(0,0,0,64),"New Record!");
|
||||
} else {
|
||||
DrawUtils.drawOutlineText(g2, programFontSmall, 8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),((bestPlay!=null)?bestPlay.display():""));
|
||||
}
|
||||
if ((ratingTime>System.currentTimeMillis()-10000)) {
|
||||
DrawUtils.drawOutlineText(g2, programFont, 484+8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64),"Rating up! "+lastRating+" -> "+overallrating);
|
||||
DrawUtils.drawOutlineText(g2, programFontSmall, 484+8, 935+42, 1, new Color(220,220,255,(int)Math.min(((System.currentTimeMillis()-ratingTime))/5,255)), new Color(0,0,0,64),"Rating up! "+lastRating+" -> "+overallrating);
|
||||
} else {
|
||||
DrawUtils.drawOutlineText(g2, programFont, 484+8, 935+42, 1, Color.WHITE, new Color(0,0,0,64),Integer.toString(overallrating));
|
||||
}
|
||||
|
22
DivaBot/src/sig/Filter.java
Normal file
@ -0,0 +1,22 @@
|
||||
package sig;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
|
||||
public class Filter {
|
||||
Point red_threshold;
|
||||
Point green_threshold;
|
||||
Point blue_threshold;
|
||||
|
||||
public Filter(Point red_threshold, Point green_threshold, Point blue_threshold) {
|
||||
this.red_threshold = red_threshold;
|
||||
this.green_threshold = green_threshold;
|
||||
this.blue_threshold = blue_threshold;
|
||||
}
|
||||
|
||||
public boolean isWithinThreshold(Color c) {
|
||||
return c.getRed()>=red_threshold.x && c.getRed()<=red_threshold.y &&
|
||||
c.getGreen()>=green_threshold.x && c.getGreen()<=green_threshold.y &&
|
||||
c.getBlue()>=blue_threshold.x && c.getBlue()<=blue_threshold.y;
|
||||
}
|
||||
}
|
@ -30,6 +30,8 @@ import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.AttributedString;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -115,7 +117,7 @@ public class MyRobot{
|
||||
boolean lastfail;
|
||||
long lastSongSelectTime = System.currentTimeMillis();
|
||||
|
||||
static TypeFace typeface1,typeface2;
|
||||
static TypeFace2 typeface1,typeface2;
|
||||
static Thread t = null;
|
||||
|
||||
String prevSongTitle = "";
|
||||
@ -208,7 +210,7 @@ public class MyRobot{
|
||||
//602,260 16,222,202
|
||||
//901,460 220-255,220-255,160-220
|
||||
|
||||
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0) {
|
||||
if (OnResultsScreen() && !recordedResults && !recordingResults && results.size()==0 && false) {
|
||||
lastSongSelectTime=System.currentTimeMillis();
|
||||
//gotoxy(800,64);
|
||||
//click();
|
||||
@ -226,25 +228,27 @@ public class MyRobot{
|
||||
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,553,115,26))));
|
||||
//System.out.println(typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26))));
|
||||
//System.out.println(typeface2.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1428,361,128,30))));
|
||||
ImageIO.write(MYROBOT.createNormalScreenCapture(new Rectangle(418,204,1227,690)),"png",new File("scoreimage.png"));
|
||||
File tmp = new File("tmp");
|
||||
if (tmp.exists()) {
|
||||
FileUtils.deleteFile(tmp);
|
||||
} else {
|
||||
tmp.mkdir();
|
||||
}
|
||||
int cool = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,451,115,26)),new File(tmp,"cool"));
|
||||
int fine = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,484,115,26)),new File(tmp,"fine"));
|
||||
int safe = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,518,115,26)),new File(tmp,"safe"));
|
||||
int sad = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,553,115,26)),new File(tmp,"sad"));
|
||||
int worst = typeface1.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),new File(tmp,"worst"));
|
||||
int cool = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,451,115,26)),new File(tmp,"cool"));
|
||||
int fine = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,484,115,26)),new File(tmp,"fine"));
|
||||
int safe = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,518,115,26)),new File(tmp,"safe"));
|
||||
int sad = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,553,115,26)),new File(tmp,"sad"));
|
||||
int worst = typeface1.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1235,583,115,26)),new File(tmp,"worst"));
|
||||
|
||||
boolean fail = textFailPixel(MYROBOT.createScreenCapture(new Rectangle(952,385,1,1)));
|
||||
boolean fail = textFailPixel(MYROBOT.createNormalScreenCapture(new Rectangle(952,385,1,1)));
|
||||
/*try {
|
||||
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(1235,583,115,26)),"png",new File("worst.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
float percent = (float)typeface2.extractNumbersFromImage(MYROBOT.createScreenCapture(new Rectangle(1428,361,128,30)),new File(tmp,"percent"))/100f;
|
||||
float percent = (float)typeface2.extractNumbersFromImage(MYROBOT.createNormalScreenCapture(new Rectangle(1428,361,128,30)),new File(tmp,"percent"))/100f;
|
||||
ImageIO.write(MYROBOT.createNormalScreenCapture(new Rectangle(418,204,1227,690)),"png",new File("test.png"));
|
||||
if (cool==-1 || fine==-1 || safe==-1 || sad==-1 || worst==-1 || percent==-0.01f) {
|
||||
System.out.println("Waiting for results to populate...");
|
||||
} else
|
||||
@ -260,18 +264,6 @@ public class MyRobot{
|
||||
int playId = songFolderFiles.length;
|
||||
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
|
||||
playFolder.mkdir();
|
||||
try {
|
||||
/*FileUtils.copyFileDir(new File(tmp,"cool"), new File(playFolder,"cool"));
|
||||
FileUtils.copyFileDir(new File(tmp,"fine"), new File(playFolder,"fine"));
|
||||
FileUtils.copyFileDir(new File(tmp,"safe"), new File(playFolder,"safe"));
|
||||
FileUtils.copyFileDir(new File(tmp,"sad"), new File(playFolder,"sad"));
|
||||
FileUtils.copyFileDir(new File(tmp,"worst"), new File(playFolder,"worst"));
|
||||
FileUtils.copyFileDir(new File(tmp,"percent"), new File(playFolder,"percent"));*/
|
||||
//FileUtils.deleteFile(tmp);
|
||||
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(418,204,1227,690)),"png",new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+cool+"_"+fine+"_"+safe+"_"+sad+"_"+worst+"_"+percent+".png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
recordedResults=true;
|
||||
lastcool=cool;
|
||||
lastfine=fine;
|
||||
@ -280,7 +272,7 @@ public class MyRobot{
|
||||
lastworst=worst;
|
||||
lastpercent=percent;
|
||||
lastfail=fail;
|
||||
|
||||
new File("scoreimage.png").renameTo(new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+cool+"_"+fine+"_"+safe+"_"+sad+"_"+worst+"_"+percent+".png"));
|
||||
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail));
|
||||
SoundUtils.playSound("collect_item.wav");
|
||||
//gotoxy(800,64);
|
||||
@ -345,7 +337,15 @@ public class MyRobot{
|
||||
|
||||
try {
|
||||
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
|
||||
JSONObject obj2 = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
|
||||
p.lastRating = p.overallrating;
|
||||
if (obj2.has("score")) {
|
||||
double newScore = obj2.getDouble("score");
|
||||
if (newScore>p.lastScore) {
|
||||
p.bestPlayTime=System.currentTimeMillis();
|
||||
}
|
||||
p.lastScore = newScore;
|
||||
}
|
||||
p.overallrating = (int)obj.getDouble("rating");
|
||||
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
|
||||
p.pullData(selectedSong.title, difficulty);
|
||||
@ -418,6 +418,7 @@ public class MyRobot{
|
||||
}
|
||||
}
|
||||
}
|
||||
MYROBOT.refreshScreen();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
@ -503,8 +504,8 @@ public class MyRobot{
|
||||
try {
|
||||
img1 = ImageUtils.toCompatibleImage(ImageIO.read(new File("typeface1.png")));
|
||||
img2 = ImageUtils.toCompatibleImage(ImageIO.read(new File("typeface2.png")));
|
||||
typeface1 = new TypeFace(img1);
|
||||
typeface2 = new TypeFace(img2);
|
||||
typeface1 = new TypeFace2(img1);
|
||||
typeface2 = new TypeFace2(img2);
|
||||
typeface2.green_minthreshold=typeface2.blue_minthreshold=100;
|
||||
typeface2.green_maxthreshold=typeface2.blue_maxthreshold=200;
|
||||
typeface2.darkFillCheck=false;
|
||||
@ -705,6 +706,7 @@ public class MyRobot{
|
||||
setKeyMap();
|
||||
try {
|
||||
MYROBOT = new CustomRobot();
|
||||
MYROBOT.refreshScreen();
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showOptionDialog(null, "Can't build the robot!", "Error", -1, 1, null, null, this);
|
||||
System.exit(1);
|
||||
|
38
DivaBot/src/sig/SongInfo.java
Normal file
@ -0,0 +1,38 @@
|
||||
package sig;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class SongInfo {
|
||||
public int id;
|
||||
public String name;
|
||||
public String romanized_name;
|
||||
public String english_name;
|
||||
public String artist;
|
||||
public String vocaloid;
|
||||
public int bpm;
|
||||
public String album_art;
|
||||
public JSONObject rating;
|
||||
public JSONObject notecount;
|
||||
|
||||
SongInfo(JSONObject jsonData) {
|
||||
id = jsonData.getInt("id");
|
||||
name = jsonData.getString("name");
|
||||
romanized_name = jsonData.getString("romanized_name");
|
||||
english_name = jsonData.getString("english_name");
|
||||
artist = jsonData.getString("artist");
|
||||
vocaloid = jsonData.getString("vocaloid");
|
||||
bpm = jsonData.getInt("bpm");
|
||||
album_art = jsonData.getString("album_art");
|
||||
rating = jsonData.getJSONObject("rating");
|
||||
notecount = jsonData.getJSONObject("notecount");
|
||||
}
|
||||
|
||||
public static SongInfo getByTitle(String title) {
|
||||
for (SongInfo s : MyRobot.SONGNAMES) {
|
||||
if (s.name.equalsIgnoreCase(title)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
28
DivaBot/src/sig/TestMain.java
Normal file
@ -0,0 +1,28 @@
|
||||
package sig;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class TestMain {
|
||||
public static void main(String[] args) throws IOException, AWTException, InterruptedException {
|
||||
|
||||
TypeFace2 font = new TypeFace2(
|
||||
ImageIO.read(new File("typeface.png"))
|
||||
);
|
||||
CustomRobot r = new CustomRobot();
|
||||
/*Thread.sleep(3000);
|
||||
r.refreshScoreScreen();
|
||||
ImageIO.write(r.scoreCurrentScreen,"png",new File("testimage.png"));*/
|
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage.png")))));
|
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage2.png")))));
|
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage3.png")))));
|
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage4.png")))));
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
|
||||
import sig.utils.FileUtils;
|
||||
import sig.utils.ImageUtils;
|
||||
|
||||
@ -20,19 +21,19 @@ public class TypeFace {
|
||||
final static int WIDTH = 32;
|
||||
final static int HEIGHT = 32;
|
||||
final static int NUMBER_COUNT = 10;
|
||||
int blue_minthreshold = 75;
|
||||
int green_minthreshold = 0;
|
||||
int red_minthreshold = 0;
|
||||
int blue_maxthreshold = 255;
|
||||
int green_maxthreshold = 150;
|
||||
int red_maxthreshold = 126;
|
||||
int blue_fillminthreshold = 75;
|
||||
int green_fillminthreshold = 0;
|
||||
int red_fillminthreshold = 0;
|
||||
int blue_fillmaxthreshold = 255;
|
||||
int green_fillmaxthreshold = 150;
|
||||
int red_fillmaxthreshold = 107;
|
||||
boolean darkFillCheck = true;
|
||||
public int blue_minthreshold = 75;
|
||||
public int green_minthreshold = 0;
|
||||
public int red_minthreshold = 0;
|
||||
public int blue_maxthreshold = 255;
|
||||
public int green_maxthreshold = 150;
|
||||
public int red_maxthreshold = 126;
|
||||
public int blue_fillminthreshold = 75;
|
||||
public int green_fillminthreshold = 0;
|
||||
public int red_fillminthreshold = 0;
|
||||
public int blue_fillmaxthreshold = 255;
|
||||
public int green_fillmaxthreshold = 150;
|
||||
public int red_fillmaxthreshold = 107;
|
||||
public boolean darkFillCheck = true;
|
||||
Color[][] numbers = new Color[WIDTH*HEIGHT][NUMBER_COUNT];
|
||||
BufferedImage baseImg;
|
||||
public TypeFace(BufferedImage img) {
|
||||
@ -47,9 +48,49 @@ public class TypeFace {
|
||||
}
|
||||
|
||||
public int extractNumbersFromImage(BufferedImage img,File saveLoc) {
|
||||
return extractNumbersFromImage(img,saveLoc,false);
|
||||
}
|
||||
|
||||
public int extractNumbersFromImage(BufferedImage img,File saveLoc,boolean debug) {
|
||||
|
||||
final boolean DEBUG_IMG = debug;
|
||||
|
||||
for (int x=0;x<img.getWidth();x++) {
|
||||
for (int y=0;y<img.getHeight();y++) {
|
||||
Color currentCol = new Color(img.getRGB(x, y));
|
||||
if (this.equals(DemoApplication.typeface3)) {
|
||||
if ((currentCol.getRed()>=0 && currentCol.getRed()<=70
|
||||
&& currentCol.getGreen()>=0 && currentCol.getGreen()<=100
|
||||
&& currentCol.getBlue()>=0 && currentCol.getBlue()<=120)) {
|
||||
img.setRGB(x, y, new Color(8,114,140).getRGB());
|
||||
} else {
|
||||
img.setRGB(x, y, Color.WHITE.getRGB());
|
||||
}
|
||||
} else
|
||||
if ((currentCol.getRed()>=0 && currentCol.getRed()<=105
|
||||
&& currentCol.getGreen()>=0 && currentCol.getGreen()<=150
|
||||
&& currentCol.getBlue()>=0 && currentCol.getBlue()<=150) ||
|
||||
(this.equals(DemoApplication.typeface2) &&
|
||||
currentCol.getRed()>=0 && currentCol.getRed()<=120
|
||||
&& currentCol.getGreen()>=100 && currentCol.getGreen()<=210
|
||||
&& currentCol.getBlue()>=120 && currentCol.getBlue()<=230
|
||||
&& currentCol.getGreen()+5<currentCol.getBlue())) {
|
||||
img.setRGB(x, y, new Color(8,114,140).getRGB());
|
||||
} else {
|
||||
img.setRGB(x, y, Color.WHITE.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!saveLoc.exists()) {
|
||||
saveLoc.mkdirs();
|
||||
}
|
||||
try {
|
||||
ImageIO.write(img,"png",new File(saveLoc,"img.png"));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
int midY = img.getHeight()/2;
|
||||
int X = 0;
|
||||
@ -60,8 +101,6 @@ public class TypeFace {
|
||||
|
||||
BufferedImage numberImg = null;
|
||||
|
||||
final boolean DEBUG_IMG = false;
|
||||
|
||||
|
||||
int iterations=0;
|
||||
while (X<img.getWidth()) {
|
||||
@ -85,7 +124,7 @@ public class TypeFace {
|
||||
}
|
||||
}
|
||||
if (darkFillCheck) {
|
||||
success = fillDark(img,X,midY,0,0);
|
||||
success = fillDark(img,X,midY,0,0,0);
|
||||
if (!success) {
|
||||
//We're done.
|
||||
X=img.getWidth();
|
||||
@ -96,6 +135,7 @@ public class TypeFace {
|
||||
}break;
|
||||
case 1:{
|
||||
//Move right until light pixel.
|
||||
//Check if next pixel is also a light pixel.
|
||||
if (p.getBlue()>200 && p.getGreen()>200 && p.getRed()>200) {
|
||||
state=2;
|
||||
if (DEBUG_IMG) {
|
||||
@ -107,6 +147,7 @@ public class TypeFace {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//System.out.println("Found light pixel");
|
||||
}
|
||||
}break;
|
||||
case 2:{
|
||||
@ -118,8 +159,17 @@ public class TypeFace {
|
||||
X=img.getWidth();
|
||||
break;
|
||||
} else {
|
||||
X+=i.maxX-1;
|
||||
numberImg = i.createImage();
|
||||
if (numberImg.getWidth()>=32) {
|
||||
state=0;
|
||||
break;
|
||||
}
|
||||
X+=i.maxX;
|
||||
if (numberImg.getHeight()<10 || numberImg.getWidth()<4) {
|
||||
//A number should be at least 10 pixels high...This is not satisfactory.
|
||||
state=4;
|
||||
break;
|
||||
}
|
||||
//X+=numberImg.getWidth();
|
||||
state=3;
|
||||
if (DEBUG_IMG) {
|
||||
@ -131,6 +181,7 @@ public class TypeFace {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//System.out.println("Moving to next step: ");
|
||||
}
|
||||
}break;
|
||||
case 3:{
|
||||
@ -140,6 +191,8 @@ public class TypeFace {
|
||||
int[] hits = new int[NUMBER_COUNT];
|
||||
double highestRatio = 0;
|
||||
int highest = 0;
|
||||
boolean goNext=false;
|
||||
boolean foundOne=false;
|
||||
for (int k=0;k<NUMBER_COUNT;k++) {
|
||||
BufferedImage img2 = ImageUtils.toCompatibleImage(ImageUtils.copyBufferedImage(numberImg));
|
||||
for (int i=0;i<WIDTH;i++) {
|
||||
@ -147,8 +200,26 @@ public class TypeFace {
|
||||
if (i<numberImg.getWidth() &&
|
||||
j<numberImg.getHeight()) {
|
||||
Color pixel = new Color(numberImg.getRGB(i, j));
|
||||
if (numbers[i*HEIGHT+j][k].getRed()==pixel.getRed() && numbers[i*HEIGHT+j][k].getGreen()==pixel.getGreen() && numbers[i*HEIGHT+j][k].getBlue()==pixel.getBlue()) {
|
||||
hits[k]++;
|
||||
if (numbers[i*HEIGHT+j][k].getRed()==0 && numbers[i*HEIGHT+j][k].getGreen()==255 && numbers[i*HEIGHT+j][k].getBlue()==0
|
||||
&& pixel.getRed()==255 && pixel.getGreen()==255 && pixel.getBlue()==255) {
|
||||
goNext=true;
|
||||
img2.setRGB(i, j, Color.MAGENTA.getRGB());
|
||||
break;
|
||||
}
|
||||
if (numbers[i*HEIGHT+j][k].getRed()==255 && numbers[i*HEIGHT+j][k].getGreen()==0 && numbers[i*HEIGHT+j][k].getBlue()==0
|
||||
&& pixel.getRed()==0 && pixel.getGreen()==0 && pixel.getBlue()==0) {
|
||||
goNext=true;
|
||||
img2.setRGB(i, j, Color.YELLOW.getRGB());
|
||||
break;
|
||||
}
|
||||
if (!goNext) {
|
||||
foundOne=true;
|
||||
}
|
||||
if (numbers[i*HEIGHT+j][k].equals(Color.RED) || numbers[i*HEIGHT+j][k].equals(Color.GREEN) ||
|
||||
(numbers[i*HEIGHT+j][k].getRed()==pixel.getRed() && numbers[i*HEIGHT+j][k].getGreen()==pixel.getGreen() && numbers[i*HEIGHT+j][k].getBlue()==pixel.getBlue())) {
|
||||
if (!(numbers[i*HEIGHT+j][k].equals(Color.GREEN) && numbers[i*HEIGHT+j][k].equals(Color.RED))) {
|
||||
hits[k]++;
|
||||
}
|
||||
//System.out.println("Hit for "+((k+1)%NUMBER_COUNT)+"! "+hits[k] + "/"+numbers[i*HEIGHT+j][k]+"/"+pixel);
|
||||
if ((double)hits[k]/(WIDTH*HEIGHT)>highestRatio) {
|
||||
highestRatio= (double)(hits[k])/(WIDTH*HEIGHT);
|
||||
@ -164,6 +235,7 @@ public class TypeFace {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (goNext) {break;}
|
||||
}
|
||||
FileUtils.logToFile(((k+1)%NUMBER_COUNT)+":"+((double)(hits[k])/(WIDTH*HEIGHT)), new File(saveLoc,(iterations)+".txt").getPath());
|
||||
try {
|
||||
@ -171,6 +243,12 @@ public class TypeFace {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
goNext=false;
|
||||
}
|
||||
if (!foundOne) {
|
||||
state=0;
|
||||
iterations++;
|
||||
break;
|
||||
}
|
||||
//System.out.println("Matches closest to "+((highest+1)%NUMBER_COUNT)+" with "+highestRatio);
|
||||
iterations++;
|
||||
@ -178,11 +256,9 @@ public class TypeFace {
|
||||
state=4;
|
||||
}break;
|
||||
case 4:{
|
||||
//Find dark pixels again.
|
||||
if (p.getBlue()>blue_minthreshold && p.getBlue()<blue_maxthreshold &&
|
||||
p.getGreen()>green_minthreshold && p.getGreen()<green_maxthreshold &&
|
||||
p.getRed()>red_minthreshold && p.getRed()<red_maxthreshold) {
|
||||
//We found a dark pixel. Back to the start.
|
||||
//Find light pixels again.
|
||||
if (p.getBlue()>200 && p.getGreen()>200 && p.getRed()>200) {
|
||||
X-=2;
|
||||
state=0;
|
||||
if (DEBUG_IMG) {
|
||||
try {
|
||||
@ -193,6 +269,7 @@ public class TypeFace {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//System.out.println("Found next dark pixel");
|
||||
}
|
||||
}break;
|
||||
}
|
||||
@ -206,8 +283,11 @@ public class TypeFace {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean fillDark(BufferedImage img,int startX,int startY,int x,int y) {
|
||||
public boolean fillDark(BufferedImage img,int startX,int startY,int x,int y, int iterations) {
|
||||
//rect.AddPixel(new Point(x,y), Color.BLACK);
|
||||
if (iterations>Math.max(img.getWidth(),img.getHeight())) {
|
||||
return false;
|
||||
}
|
||||
img.setRGB(startX+x, startY+y, Color.BLACK.getRGB());
|
||||
Color p = null;
|
||||
if (startX+x+1<img.getWidth()) {
|
||||
@ -215,7 +295,7 @@ public class TypeFace {
|
||||
if (p.getBlue()>blue_fillminthreshold && p.getBlue()<blue_fillmaxthreshold &&
|
||||
p.getGreen()>green_fillminthreshold && p.getGreen()<green_fillmaxthreshold &&
|
||||
p.getRed()>red_fillminthreshold && p.getRed()<red_fillmaxthreshold) {
|
||||
fillDark(img,startX,startY,x+1,y);
|
||||
fillDark(img,startX,startY,x+1,y,iterations+1);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
@ -225,7 +305,7 @@ public class TypeFace {
|
||||
if (p.getBlue()>blue_fillminthreshold && p.getBlue()<blue_fillmaxthreshold &&
|
||||
p.getGreen()>green_fillminthreshold && p.getGreen()<green_fillmaxthreshold &&
|
||||
p.getRed()>red_fillminthreshold && p.getRed()<red_fillmaxthreshold) {
|
||||
fillDark(img,startX,startY,x-1,y);
|
||||
fillDark(img,startX,startY,x-1,y,iterations+1);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
@ -235,7 +315,7 @@ public class TypeFace {
|
||||
if (p.getBlue()>blue_fillminthreshold && p.getBlue()<blue_fillmaxthreshold &&
|
||||
p.getGreen()>green_fillminthreshold && p.getGreen()<green_fillmaxthreshold &&
|
||||
p.getRed()>red_fillminthreshold && p.getRed()<red_fillmaxthreshold) {
|
||||
fillDark(img,startX,startY,x,y+1);
|
||||
fillDark(img,startX,startY,x,y+1,iterations+1);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
@ -245,7 +325,7 @@ public class TypeFace {
|
||||
if (p.getBlue()>blue_fillminthreshold && p.getBlue()<blue_fillmaxthreshold &&
|
||||
p.getGreen()>green_fillminthreshold && p.getGreen()<green_fillmaxthreshold &&
|
||||
p.getRed()>red_fillminthreshold && p.getRed()<red_fillmaxthreshold) {
|
||||
fillDark(img,startX,startY,x,y-1);
|
||||
fillDark(img,startX,startY,x,y-1,iterations+1);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
|
138
DivaBot/src/sig/TypeFace2.java
Normal file
@ -0,0 +1,138 @@
|
||||
package sig;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import sig.utils.ImageUtils;
|
||||
|
||||
public class TypeFace2 {
|
||||
BufferedImage img;
|
||||
BufferedImage font;
|
||||
int xpointer = 99;
|
||||
public static final int THRESHOLD = 30000;
|
||||
|
||||
public TypeFace2(BufferedImage font) {
|
||||
this.font=font;
|
||||
}
|
||||
|
||||
public int[] getAllData(BufferedImage img) throws IOException {
|
||||
BufferedImage img2 = ImageUtils.toBufferedImage(img.getScaledInstance(1280, 720, Image.SCALE_AREA_AVERAGING));
|
||||
int[] finalNumbers = new int[5];
|
||||
|
||||
Rectangle[] ranges = new Rectangle[] {
|
||||
//These coords are in regard to the old screenshot sizes.
|
||||
new Rectangle(866,262,100,20), //33 pixels per line.
|
||||
new Rectangle(866,296,100,20),
|
||||
new Rectangle(866,331,100,20),
|
||||
new Rectangle(866,366,100,20),
|
||||
new Rectangle(866,400,100,20),
|
||||
};
|
||||
|
||||
for (int i=0;i<ranges.length;i++) {
|
||||
Rectangle r = ranges[i];
|
||||
|
||||
System.out.println("Image "+i+":");
|
||||
File temp = new File("rectangle"+i+".png");
|
||||
ImageIO.write(img2.getSubimage(r.x,r.y,r.width,r.height),"png",temp);
|
||||
|
||||
finalNumbers[i]=extractNumbersFromImage(img2.getSubimage(
|
||||
r.x,r.y,r.width,r.height),false);
|
||||
|
||||
}
|
||||
return finalNumbers;
|
||||
}
|
||||
|
||||
public int extractNumbersFromImage(BufferedImage img) throws IOException {
|
||||
return extractNumbersFromImage(img,false);
|
||||
}
|
||||
|
||||
public int extractNumbersFromImage(BufferedImage img,boolean debug) throws IOException {
|
||||
this.img=img;
|
||||
File f = null;
|
||||
BufferedImage test = null;
|
||||
xpointer=99;
|
||||
String total = "";
|
||||
while (xpointer>22) {
|
||||
int distance = 0;
|
||||
int foundIndex = -1;
|
||||
//Compare the 22x21 range.
|
||||
for (int i=0;i<10;i++) {
|
||||
if (debug) {
|
||||
test = new BufferedImage(22,20,BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
boolean ruleBreak=false;
|
||||
|
||||
colorloop:
|
||||
for (int x=0;x<22;x++) {
|
||||
for (int y=0;y<20;y++) {
|
||||
Color fontCol = new Color(font.getRGB(x+i*22,y));
|
||||
Color pixelCol = new Color(img.getRGB(xpointer-22+x+1, y));
|
||||
if (fontCol.equals(Color.RED) && pixelCol.getRed()<150
|
||||
&& 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()>150
|
||||
|| pixelCol.getGreen()>150 || 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 (!ruleBreak) {
|
||||
foundIndex=i;
|
||||
if (debug) {
|
||||
System.out.println("Passes as "+((foundIndex+1)%10));
|
||||
}
|
||||
} else
|
||||
if (debug) {
|
||||
ImageIO.write(test,"png",new File(System.nanoTime()+"_"+((i+1)%10)+".png"));
|
||||
}
|
||||
}
|
||||
if (foundIndex!=-1) {
|
||||
//System.out.println(" Closest Match: Index "+((shortestIndex+1)%10)+" ("+shortestDistance+")");
|
||||
if (total.equals("")) {
|
||||
total = Integer.toString((foundIndex+1)%10);
|
||||
} else {
|
||||
total = Integer.toString((foundIndex+1)%10)+total;
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println("Input as "+((foundIndex+1)%10));
|
||||
System.out.println("-------------");
|
||||
}
|
||||
xpointer-=22;
|
||||
} else {
|
||||
//Try shifting the xpointer slowly to the right and try again.
|
||||
xpointer--;
|
||||
}
|
||||
}
|
||||
|
||||
if (total.equals("")) {
|
||||
return -1;
|
||||
} else {
|
||||
return Integer.parseInt(total);
|
||||
}
|
||||
}
|
||||
}
|
BIN
DivaBot/test.png
Normal file
After Width: | Height: | Size: 544 KiB |
BIN
DivaBot/testimage.png
Normal file
After Width: | Height: | Size: 954 KiB |
BIN
DivaBot/testimage2.png
Normal file
After Width: | Height: | Size: 353 KiB |
BIN
DivaBot/testimage3.png
Normal file
After Width: | Height: | Size: 324 KiB |
BIN
DivaBot/testimage4.png
Normal file
After Width: | Height: | Size: 397 KiB |
BIN
DivaBot/testing.png
Normal file
After Width: | Height: | Size: 905 KiB |
BIN
DivaBot/testscreen.png
Normal file
After Width: | Height: | Size: 775 KiB |
BIN
DivaBot/typeface.png
Normal file
After Width: | Height: | Size: 12 KiB |