Song select screen recognition using calibration now fully implemented.

secondmonitor
sigonasr2 4 years ago
parent 62a3e7f776
commit 42cd32c0a3
  1. 6
      DivaBot/.classpath
  2. 1
      DivaBot/.settings/org.eclipse.core.resources.prefs
  3. 7
      DivaBot/.settings/org.eclipse.jdt.core.prefs
  4. BIN
      DivaBot/DivaBot.jar
  5. 4
      DivaBot/calibration_data.txt
  6. 359
      DivaBot/colorData
  7. 195
      DivaBot/colorData.old
  8. 7
      DivaBot/src/sig/Calibrator.java
  9. 44
      DivaBot/src/sig/CustomRobot.java
  10. 76
      DivaBot/src/sig/DrawCanvas.java
  11. 162
      DivaBot/src/sig/MyRobot.java
  12. 4
      DivaBot/src/sig/Overlay.java
  13. 33
      DivaBot/src/sig/SongData.java
  14. BIN
      DivaBot/test.png

@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
@ -16,5 +11,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

@ -1,4 +1,3 @@
eclipse.preferences.version=1
encoding//src/sig/FutureToneBot.java=UTF-8
encoding//src/sig/MyRobot.java=UTF-8
encoding/colorData=UTF-8

@ -1,8 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -12,4 +13,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=1.7

Binary file not shown.

@ -0,0 +1,4 @@
530
260
1573
845

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -9,6 +9,8 @@ import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import sig.utils.FileUtils;
public class Calibrator{
public static BufferedImage img;
@ -62,6 +64,11 @@ public class Calibrator{
//MyRobot.CALIBRATIONSTATUS="First calibration set done: X"+(x-MyRobot.STARTDRAG.x)+" Y"+(y-MyRobot.STARTDRAG.y);
img = MyRobot.MYROBOT.getSizedCapture(new Rectangle(0,0,MyRobot.screenSize.width,MyRobot.screenSize.height));
ImageIO.write(img.getSubimage(MyRobot.STARTDRAG.x,MyRobot.STARTDRAG.y,MyRobot.ENDDRAG.x-MyRobot.STARTDRAG.x,MyRobot.ENDDRAG.y-MyRobot.STARTDRAG.y),"png",new File("capture_5.png"));
FileUtils.deleteFile("calibration_data.txt");
FileUtils.logToFile(Integer.toString(MyRobot.STARTDRAG.x), "calibration_data.txt");
FileUtils.logToFile(Integer.toString(MyRobot.STARTDRAG.y), "calibration_data.txt");
FileUtils.logToFile(Integer.toString(MyRobot.ENDDRAG.x), "calibration_data.txt");
FileUtils.logToFile(Integer.toString(MyRobot.ENDDRAG.y), "calibration_data.txt");
}
private boolean CalibrationStage1() throws IOException, InterruptedException {

@ -10,12 +10,16 @@ import java.io.IOException;
import javax.imageio.ImageIO;
import sig.utils.FileUtils;
import sig.utils.ImageUtils;
public class CustomRobot extends Robot{
File calibration_file = new File("calibration_data.txt");
BufferedImage currentScreen;
BufferedImage scoreCurrentScreen;
int[] calibration_data = new int[]{0,0,1,1};
long lastCalibrationTime = 0;
public CustomRobot() throws AWTException {
super();
@ -30,19 +34,43 @@ public class CustomRobot extends Robot{
}
public void refreshScreen() {
currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83));
//currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83));
if (CalibrationDataChanged()) {
ReloadCalibrationData();
}
if (calibration_data.length>0) {
currentScreen = super.createScreenCapture(new Rectangle(calibration_data[0],calibration_data[1],calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1]));
} else {
currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83));
}
}
private void ReloadCalibrationData() {
lastCalibrationTime=calibration_file.lastModified();
String[] data = FileUtils.readFromFile("calibration_data.txt");
calibration_data[0]=Integer.parseInt(data[0]);
calibration_data[1]=Integer.parseInt(data[1]);
calibration_data[2]=Integer.parseInt(data[2]);
calibration_data[3]=Integer.parseInt(data[3]);
}
private boolean CalibrationDataChanged() {
return calibration_file.exists()&&lastCalibrationTime!=calibration_file.lastModified();
}
public void refreshScoreScreen() {
scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23,204+85,912-18,586-83));
if (CalibrationDataChanged()) {
ReloadCalibrationData();
}
if (calibration_data.length>0) {
scoreCurrentScreen = super.createScreenCapture(new Rectangle(calibration_data[0],calibration_data[1],calibration_data[2]-calibration_data[0],calibration_data[3]-calibration_data[1]));
} else {
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));
return ImageUtils.toBufferedImage(currentScreen.getScaledInstance(1227, 690, BufferedImage.SCALE_AREA_AVERAGING)).getSubimage(r.x, r.y, r.width, r.height);
//return img2.getSubimage(r.x-418, r.y-204, r.width, r.height);
}
public synchronized BufferedImage createScoreScreenCapture() {
return scoreCurrentScreen;

@ -103,7 +103,7 @@ public class DrawCanvas extends JPanel implements KeyListener{
}
}
public void pullData(String songname,String difficulty) {
public void pullData(final String songname,final String difficulty) {
this.songname=(songname.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(songname.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":songname);
this.difficulty=difficulty;
romanizedname="";
@ -124,42 +124,46 @@ public class DrawCanvas extends JPanel implements KeyListener{
romanizedname = obj.getString("romanized_name");
englishname = obj.getString("english_name");
artist = obj.getString("artist");*/
SongInfo currentSong = SongInfo.getByTitle(MyRobot.p.songname);
if (currentSong.rating.has(difficulty)) {
difficultyRating = currentSong.rating.getDouble(difficulty);
}
romanizedname = currentSong.romanized_name;
englishname = currentSong.english_name;
artist = currentSong.artist;
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;
}
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/playcount/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
plays = obj.getInt("playcount");
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/songpasscount/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
passes = obj.getInt("passcount");
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/songfccount/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
fcCount = obj.getInt("fccount");
/*obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
lastRating = overallrating;
overallrating = (int)obj.getDouble("rating");
if (lastRating<overallrating) {ratingTime=System.currentTimeMillis();}
*/
String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate"+((fcCount>0)?" - "+fcCount+" FC"+(fcCount==1?"":"s")+" "+((int)(Math.floor(((float)fcCount)/plays*100)))+"% FC rate":"")+")":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():"")+" Overall Rating: "+overallrating;
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont);
if (bounds.getWidth()>1345) {
scrolling=true;
} else {
scrolling=false;
}
scrollX = 0;
MyRobot.p.repaint(0,0,1400,1000);
if (MyRobot.p.songname!=null) {
SongInfo currentSong = SongInfo.getByTitle(MyRobot.p.songname);
if (currentSong!=null) {
if (currentSong.rating.has(difficulty)) {
difficultyRating = currentSong.rating.getDouble(difficulty);
}
romanizedname = currentSong.romanized_name;
englishname = currentSong.english_name;
artist = currentSong.artist;
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;
}
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/playcount/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
plays = obj.getInt("playcount");
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/songpasscount/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
passes = obj.getInt("passcount");
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/songfccount/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
fcCount = obj.getInt("fccount");
/*obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
lastRating = overallrating;
overallrating = (int)obj.getDouble("rating");
if (lastRating<overallrating) {ratingTime=System.currentTimeMillis();}
*/
String text = songname+" / "+((romanizedname.length()>0)?romanizedname:englishname)+" "+(artist.length()>0?"by "+artist:"")+" "+((plays>0)?("Plays - "+(passes)+"/"+(plays)):"")+" "+((plays!=0)?"("+((int)(Math.floor(((float)passes)/plays*100)))+"% pass rate"+((fcCount>0)?" - "+fcCount+" FC"+(fcCount==1?"":"s")+" "+((int)(Math.floor(((float)fcCount)/plays*100)))+"% FC rate":"")+")":"No plays")+" "+((bestPlay!=null)?"Best Play - "+bestPlay.display():"")+" Overall Rating: "+overallrating;
Rectangle2D bounds = TextUtils.calculateStringBoundsFont(text, programFont);
if (bounds.getWidth()>1345) {
scrolling=true;
} else {
scrolling=false;
}
scrollX = 0;
MyRobot.p.repaint(0,0,1400,1000);
}
}
} catch (JSONException | IOException e) {
e.printStackTrace();
e.printStackTrace();
}
}
};

@ -89,9 +89,10 @@ public class MyRobot{
static CustomRobot MYROBOT;
Color SCREEN[][];
static SongData SONGS[];
//static String SONGNAMES[] = new String[] {"Yellow","The secret garden","Tell Your World","愛言葉","Weekender Girl","歌に形はないけれど","えれくとりっく・えんじぇぅ","神曲","カンタレラ","巨大少女","クローバー♣クラブ","恋スルVOC@LOID","桜ノ雨","39","深海シティアンダーグラウンド","深海少女","積乱雲グラフィティ","千年の独奏歌","ダブルラリアット","ハジメテノオト","初めての恋が終わる時","packaged","Palette","FREELY TOMORROW","from Y to Y","みくみくにしてあげる♪","メルト","モノクロ∞ブルースカイ","ゆめゆめ","16 -out of the gravity-","ACUTE","インタビュア","LOL -lots of laugh-","Glory 3usi9","soundless voice","ジェミニ","白い雪のプリンセスは","スキキライ","タイムマシン","Dear","DECORATOR","トリコロール・エア・ライン","Nostalogic","Hand in Hand","Fire◎Flower","ブラック★ロックシューター","メテオ","ワールドイズマイン","アマツキツネ","erase or zero","エレクトロサチュレイタ","on the rocks","からくりピエロ","カラフル×メロディ","Catch the Wave","キャットフード","サマーアイドル","shake it!","Just Be Friends","スイートマジック","SPiCa -39's Giving Day Edition-","番凩","テレカクシ思春期","天樂","どういうことなの!?","東京テディベア","どりーみんチュチュ","トリノコシティ","ネトゲ廃人シュプレヒコール","No Logic","ハイハハイニ","はじめまして地球人さん","*ハロー、プラネット。 (I.M.PLSE-EDIT)","Hello, Worker","忘却心中","magnet","右肩の蝶","結ンデ開イテ羅刹ト骸","メランコリック","リモコン","ルカルカ★ナイトフィーバー","炉心融解","WORLD'S END UMBRELLA","アカツキアライヴァル","アゲアゲアゲイン","1925","え?あぁ、そう。","エイリアンエイリアン","ODDS&ENDS","君の体温","こっち向いて Baby","壊セ壊セ","39みゅーじっく!","サンドリヨン","SING&SMILE","スノーマン","DYE","なりすましゲンガー","ヒバナ","ヒビカセ","ブラックゴールド","ミラクルペイント","指切り","ありふれたせかいせいふく","アンハッピーリフレイン","大江戸ジュリアナイト","ゴーストルール","こちら、幸福安心委員会です。","孤独の果て -extend edition-","ジターバグ","Sweet Devil","砂の惑星","テオ","初音ミクの消失 -DEAD END-","秘密警察","妄想スケッチ","リンちゃんなう!","ローリンガール","ロキ","ロミオとシンデレラ","エンヴィキャットウォーク","骸骨楽団とリリア","サイハテ","ジグソーパズル","千本桜","ピアノ×フォルテ×スキャンダル","Blackjack","ぽっぴっぽー","裏表ラバーズ","Sadistic.Music∞Factory","デンパラダイム","二次元ドリームフィーバー","ネガポジ*コンティニューズ","初音ミクの激唱","ワールズエンド・ダンスホール","ココロ","システマティック・ラヴ","Knife","二息歩行","PIANOGIRL","夢喰い白黒バク","ブレス・ユア・ブレス","恋は戦争","あなたの歌姫","Starduster","StargazeR","リンリンシグナル","Rosary Pale","多重未来のカルテット~QUARTET THEME~","LIKE THE WIND","AFTER BURNER"};
/*static String SONGNAMES[] = new String[] {"Yellow","The secret garden","Tell Your World","愛言葉","Weekender Girl","歌に形はないけれど","えれくとりっく・えんじぇぅ","神曲","カンタレラ","巨大少女","クローバー♣クラブ","恋スルVOC@LOID","桜ノ雨","39","深海シティアンダーグラウンド","深海少女","積乱雲グラフィティ","千年の独奏歌","ダブルラリアット","ハジメテノオト","初めての恋が終わる時","packaged","Palette","FREELY TOMORROW","from Y to Y","みくみくにしてあげる♪","メルト","モノクロ∞ブルースカイ","ゆめゆめ","16 -out of the gravity-","ACUTE","インタビュア","LOL -lots of laugh-","Glory 3usi9","soundless voice","ジェミニ","白い雪のプリンセスは","スキキライ","タイムマシン","Dear","DECORATOR","トリコロール・エア・ライン","Nostalogic","Hand in Hand","Fire◎Flower","ブラック★ロックシューター","メテオ","ワールドイズマイン","アマツキツネ","erase or zero","エレクトロサチュレイタ","on the rocks","からくりピエロ","カラフル×メロディ","Catch the Wave","キャットフード","サマーアイドル","shake it!","Just Be Friends","スイートマジック","SPiCa -39's Giving Day Edition-","番凩","テレカクシ思春期","天樂","どういうことなの!?","東京テディベア","どりーみんチュチュ","トリノコシティ","ネトゲ廃人シュプレヒコール","No Logic","ハイハハイニ","はじめまして地球人さん","*ハロー、プラネット。 (I.M.PLSE-EDIT)","Hello, Worker","忘却心中","magnet","右肩の蝶","結ンデ開イテ羅刹ト骸","メランコリック","リモコン","ルカルカ★ナイトフィーバー","炉心融解","WORLD'S END UMBRELLA","アカツキアライヴァル","アゲアゲアゲイン","1925","え?あぁ、そう。","エイリアンエイリアン","ODDS&ENDS","君の体温","こっち向いて Baby","壊セ壊セ","39みゅーじっく!","サンドリヨン","SING&SMILE","スノーマン","DYE","なりすましゲンガー","ヒバナ","ヒビカセ","ブラックゴールド","ミラクルペイント","指切り","ありふれたせかいせいふく","アンハッピーリフレイン","大江戸ジュリアナイト","ゴーストルール","こちら、幸福安心委員会です。","孤独の果て -extend edition-","ジターバグ","Sweet Devil","砂の惑星","テオ","初音ミクの消失 -DEAD END-","秘密警察","妄想スケッチ","リンちゃんなう!","ローリンガール","ロキ","ロミオとシンデレラ","エンヴィキャットウォーク","骸骨楽団とリリア","サイハテ","ジグソーパズル","千本桜","ピアノ×フォルテ×スキャンダル","Blackjack","ぽっぴっぽー","裏表ラバーズ","Sadistic.Music∞Factory","デンパラダイム","二次元ドリームフィーバー","ネガポジ*コンティニューズ","初音ミクの激唱","ワールズエンド・ダンスホール","ココロ","システマティック・ラヴ","Knife","二息歩行","PIANOGIRL","夢喰い白黒バク","ブレス・ユア・ブレス","恋は戦争","あなたの歌姫","Starduster","StargazeR","リンリンシグナル","Rosary Pale","多重未来のカルテット~QUARTET THEME~","LIKE THE WIND","AFTER BURNER",
"ストロボナイツ","VOiCE","恋色病棟","ねこみみスイッチ","パラジクロロベンゼン","カラフル×セクシィ","劣等上等","Star Story","パズル","キップル・インダストリー","夢の続き","MEGANE","Change me"};*/
static SongInfo SONGNAMES[] = new SongInfo[] {};
static String NEWSONGS[] = new String[] {"ブラック★ロックシューター","メテオ"};
static String NEWSONGS[] = new String[] {"Catch the Wave"};
int SCREEN_X;
int SCREEN_Y;
int WINDOW_X;
@ -114,8 +115,8 @@ public class MyRobot{
BufferedImage bufImg;
Rectangle rect;
static JTextField title;
final int WIDTH = 200;
final int HEIGHT = 5;
final int WIDTH = 204;
final int HEIGHT = 25;
public static DrawCanvas p;
static int currentSong = 0;
static SongData selectedSong = null;
@ -149,11 +150,17 @@ public class MyRobot{
static Rectangle calibrationline = null;
static boolean repaintCalled = false;
public static Overlay OVERLAY;
public static boolean CALIBRATION_MODE=false;
public static ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
public static void main(String[] args) throws JSONException, IOException, FontFormatException {
if (args.length>0) {
if (args[0].equalsIgnoreCase("calibrate")) {
CALIBRATION_MODE=true;
}
}
JSONObject obj = FileUtils.readJsonFromUrl("http://www.projectdivar.com/songs");
SONGNAMES = new SongInfo[JSONObject.getNames(obj).length];
for (String key : JSONObject.getNames(obj)) {
@ -403,18 +410,71 @@ public class MyRobot{
}
}
private void GetCurrentSong() throws IOException {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)));
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i,j),true);
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(812-10,380-10,WIDTH+20,HEIGHT+20)));
boolean found=false;
LOOP1:
for (int x=0;x<10;x++) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP1;
}
}
}
/*File f = new File("test.png");
ImageIO.write(img,"png",f);*/
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
if (!found) {
LOOP2:
for (int x=0;x>-10;x--) {
for (int y=0;y<10;y++) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
for (int y=-1;y>-10;y--) {
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
selectedSong = ss;
found=true;
break LOOP2;
}
}
}
}
}
@ -459,33 +519,55 @@ public class MyRobot{
actionMap.put("Press", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)));
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i,j),true);
}
}
SongData.saveSongToFile(NEWSONGS[currentSong],col);
SongData.loadSongsFromFile();
System.out.println((++currentSong>=NEWSONGS.length)?"DONE!":NEWSONGS[currentSong]);
//System.out.println(title.getText());
//BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(460,426,WIDTH,HEIGHT)));
//Buffered img ImageUtils.toCompatibleImage(
MYROBOT.refreshScreen();
BufferedImage img = null;
try {
ImageIO.write(img=MYROBOT.createScreenCapture(new Rectangle(812,380,WIDTH,HEIGHT)),"png",new File("test.png"));
} catch (IOException e1) {
e1.printStackTrace();
}
Color[] col = new Color[WIDTH*HEIGHT];
for (int i=0;i<WIDTH;i++) {
for (int j=0;j<HEIGHT;j++) {
col[i*HEIGHT+j]=new Color(img.getRGB(i,j),true);
}
}
SongData.saveSongToFile(NEWSONGS[currentSong],col);
SongData.loadSongsFromFile();
currentSong+=1;
if (currentSong>=NEWSONGS.length) {
System.out.println("DONE!");
} else {
for (SongInfo i : SONGNAMES) {
if (i.name.equalsIgnoreCase(NEWSONGS[currentSong])) {
System.out.println(NEWSONGS[currentSong]+" - "+((i.romanized_name.length()>0)?i.romanized_name:i.english_name));
break;
}
}
}
}
});
JFrame.setDefaultLookAndFeelDecorated(true);
f.setUndecorated(true);
OVERLAY = new Overlay();
OVERLAY.setBounds(f.getGraphicsConfiguration().getBounds());
OVERLAY.setOpaque(false);
f.addMouseListener(OVERLAY);
f.addMouseMotionListener(OVERLAY);
screenSize=new Dimension(f.getGraphicsConfiguration().getBounds().width,f.getGraphicsConfiguration().getBounds().height);
f.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
//f.add(p);
//System.out.println(f.getGraphicsConfiguration().getBounds().width+"/"+f.getGraphicsConfiguration().getBounds().height);
f.setSize(f.getGraphicsConfiguration().getBounds().width,f.getGraphicsConfiguration().getBounds().height);
f.add(OVERLAY);
f.setBackground(new Color(0,0,0,0));
if (CALIBRATION_MODE) {
JFrame.setDefaultLookAndFeelDecorated(true);
f.setUndecorated(true);
OVERLAY = new Overlay();
OVERLAY.setBounds(f.getGraphicsConfiguration().getBounds());
OVERLAY.setOpaque(false);
f.addMouseListener(OVERLAY);
f.addMouseMotionListener(OVERLAY);
screenSize=new Dimension(f.getGraphicsConfiguration().getBounds().width,f.getGraphicsConfiguration().getBounds().height);
f.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
//f.add(p);
//System.out.println(f.getGraphicsConfiguration().getBounds().width+"/"+f.getGraphicsConfiguration().getBounds().height);
f.setSize(f.getGraphicsConfiguration().getBounds().width,f.getGraphicsConfiguration().getBounds().height);
f.add(OVERLAY);
f.setBackground(new Color(0,0,0,0));
} else {
f.setSize(1362, 1036);
f.add(p);
}
f.setVisible(true);
f.setTitle("DivaBot");
title = new JTextField();
@ -598,7 +680,7 @@ public class MyRobot{
}
public static boolean checkSongSelect() throws IOException {
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(1255,824,20,20)).getRGB(10, 10));
Color c = new Color(MYROBOT.createScreenCapture(new Rectangle(845,638,1,1)).getRGB(0, 0));
onSongSelect = c.getRed()==43 && c.getGreen()==88 && c.getBlue()==213;
//System.out.println(onSongSelect+"/"+c);
return onSongSelect;

@ -56,12 +56,12 @@ public class Overlay extends JPanel implements MouseMotionListener,MouseListener
public void mouseReleased(MouseEvent e) {
MyRobot.ENDDRAG=e.getLocationOnScreen();
if (MyRobot.STARTDRAG.x>MyRobot.ENDDRAG.x) {
var xTemp = MyRobot.STARTDRAG.x;
int xTemp = MyRobot.STARTDRAG.x;
MyRobot.STARTDRAG.x=MyRobot.ENDDRAG.x;
MyRobot.ENDDRAG.x=xTemp;
}
if (MyRobot.STARTDRAG.y>MyRobot.ENDDRAG.y) {
var xTemp = MyRobot.STARTDRAG.y;
int xTemp = MyRobot.STARTDRAG.y;
MyRobot.STARTDRAG.y=MyRobot.ENDDRAG.y;
MyRobot.ENDDRAG.y=xTemp;
}

@ -7,6 +7,8 @@ import sig.utils.ImageUtils;
public class SongData {
String title;
Color[] songCode;
int distance=0;
static int MAXTHRESHOLD=200000;
final static float TOLERANCE = 0.95f;
public SongData(String title,Color[] songCode) {
this.title=title;
@ -23,17 +25,31 @@ public class SongData {
}
public static SongData compareData(Color[] data) {
int closestDistance = Integer.MAX_VALUE;
int closestDistance = Integer.MAX_VALUE;
int closestMaxThresholdDistance = Integer.MAX_VALUE;
SongData closestSong = null;
for (SongData s : MyRobot.SONGS) {
int distance = 0;
for (int i=0;i<s.songCode.length;i++) {
distance += ImageUtils.distanceToColor(s.songCode[i],data[i]);
}
if (distance<closestDistance) {
//System.out.println(matched+"/"+s.songCode.length+" pixels matched for song "+s.title);
closestSong=s;
closestDistance=distance;
if (s!=null&&s.songCode!=null) {
for (int i=0;i<s.songCode.length;i++) {
distance += ImageUtils.distanceToColor(s.songCode[i],data[i]);
/*if (distance>MAXTHRESHOLD) {
distance=MAXTHRESHOLD+1;
break;
}*/
}
if (/*distance<=MAXTHRESHOLD && */distance<closestDistance) {
//System.out.println(distance+" pixels matched for song "+s.title);
closestSong=s;
closestSong.distance=distance;
closestDistance=distance;
}
if (distance>=MAXTHRESHOLD && distance<closestMaxThresholdDistance) {
System.out.println(distance+" pixels diff: "+s.title);
closestMaxThresholdDistance=distance;
}
} else {
continue;
}
}
return closestSong;
@ -71,6 +87,7 @@ public class SongData {
for (int i=0;i<data.length;i++) {
colors[i]=new Color(Integer.parseInt(data[i]),true);
}
System.out.println("Store "+title+"/"+colors);
return new SongData(title,colors);
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Loading…
Cancel
Save