New Song detection algorithm implemented.

secondmonitor
sigonasr2 4 years ago
parent c555f2f594
commit a019af5a37
  1. 104
      DivaBot/src/sig/MyRobot.java
  2. 52
      DivaBot/src/sig/SongData.java
  3. 2
      DivaBot/src/sig/utils/ImageUtils.java

@ -95,7 +95,8 @@ public class MyRobot{
/*static String FUTURETONESONGNAMES[] = 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 FUTURETONESONGNAMES[] = 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"};*/ "ストロボナイツ","VOiCE","恋色病棟","ねこみみスイッチ","パラジクロロベンゼン","カラフル×セクシィ","劣等上等","Star Story","パズル","キップル・インダストリー","夢の続き","MEGANE","Change me"};*/
static SongInfo SONGNAMES[] = new SongInfo[] {}; static SongInfo SONGNAMES[] = new SongInfo[] {};
static String NEWSONGS[] = new String[] {}; static String NEWSONGS[] = 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"};
int SCREEN_X; int SCREEN_X;
int SCREEN_Y; int SCREEN_Y;
int WINDOW_X; int WINDOW_X;
@ -128,6 +129,8 @@ public class MyRobot{
static boolean CALIBRATION = true; static boolean CALIBRATION = true;
static Point STARTDRAG = null; static Point STARTDRAG = null;
static Point ENDDRAG = null; static Point ENDDRAG = null;
public static long smallestSongColor = Long.MAX_VALUE;
public static int[] firstTwentyPixels = new int[20];
int lastcool=-1,lastfine=-1,lastsafe=-1,lastsad=-1,lastworst=-1,lastcombo=-1,lastscore=-1; int lastcool=-1,lastfine=-1,lastsafe=-1,lastsad=-1,lastworst=-1,lastcombo=-1,lastscore=-1;
float lastpercent; float lastpercent;
@ -529,75 +532,26 @@ public class MyRobot{
} }
} }
private void GetCurrentSong() throws IOException { private void GetCurrentSong() throws IOException {
BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(812-10,380-10,WIDTH+20,HEIGHT+20))); BufferedImage img = ImageUtils.toCompatibleImage(MYROBOT.createScreenCapture(new Rectangle(630,80,580,380)));
boolean found=false; long r=0,g=0,b=0;
SongData newPick = null; int count=0;
LOOP1: for (int i=0;i<20;i++) {
for (int x=0;x<10;x++) { if (img.getRGB(i, i)!=firstTwentyPixels[i]) {
for (int y=0;y<10;y++) { firstTwentyPixels[i]=img.getRGB(i,i);
Color[] col = new Color[WIDTH*HEIGHT]; } else {
for (int i=0;i<WIDTH;i++) { //System.out.println("Same image as last frame. Ignoring.");
for (int j=0;j<HEIGHT;j++) { return;
col[i*HEIGHT+j]=new Color(img.getRGB(i+10+x,j+10+y),true);
}
}
SongData ss = SongData.compareData(col);
if (ss!=null) {
newPick = 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) {
newPick = ss;
found=true;
break LOOP1;
}
} }
} }
if (!found) { for (int i=0;i<580;i++) {
LOOP2: for (int j=0;j<380;j++) {
for (int x=0;x>-10;x--) { r+=Math.pow(new Color(img.getRGB(i,j),true).getRed(),2);
for (int y=0;y<10;y++) { g+=Math.pow(new Color(img.getRGB(i,j),true).getGreen(),2);
Color[] col = new Color[WIDTH*HEIGHT]; b+=Math.pow(new Color(img.getRGB(i,j),true).getBlue(),2);
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) {
newPick = 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) {
newPick = ss;
found=true;
break LOOP2;
}
}
} }
} }
if (found) { if (r+g+b>=MyRobot.smallestSongColor) {
selectedSong = newPick; selectedSong = SongData.compareData(r,g,b);
} }
} }
@ -648,17 +602,21 @@ public class MyRobot{
} }
BufferedImage img = null; BufferedImage img = null;
try { try {
ImageIO.write(img=MYROBOT.createScreenCapture(new Rectangle(812,380,WIDTH,HEIGHT)),"png",new File("test.png")); ImageIO.write(img=MYROBOT.createScreenCapture(new Rectangle(630,80,580,380)),"png",new File("test.png"));
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
Color[] col = new Color[WIDTH*HEIGHT]; long totalr=0;
for (int i=0;i<WIDTH;i++) { long totalg=0;
for (int j=0;j<HEIGHT;j++) { long totalb=0;
col[i*HEIGHT+j]=new Color(img.getRGB(i,j),true); for (int i=0;i<580;i++) {
for (int j=0;j<380;j++) {
totalr+=Math.pow(new Color(img.getRGB(i,j),true).getRed(),2);
totalg+=Math.pow(new Color(img.getRGB(i,j),true).getGreen(),2);
totalb+=Math.pow(new Color(img.getRGB(i,j),true).getBlue(),2);
} }
} }
SongData.saveSongToFile(NEWSONGS[currentSong],col); SongData.saveSongToFile(NEWSONGS[currentSong],totalr,totalg,totalb);
try { try {
SongData.loadSongsFromFile(); SongData.loadSongsFromFile();
} catch (IOException e1) { } catch (IOException e1) {
@ -734,7 +692,7 @@ public class MyRobot{
static void RunTests() throws IOException { static void RunTests() throws IOException {
selectedSong=new SongData("LIKE THE WIND",new Color[] {}); selectedSong=new SongData("LIKE THE WIND",0,0,0);
difficulty="H"; difficulty="H";
RunTest("test1.jpg",393,127,28,10,48,72.28f,"EXEX","",85,577160,false); RunTest("test1.jpg",393,127,28,10,48,72.28f,"EXEX","",85,577160,false);

@ -7,13 +7,17 @@ import sig.utils.ImageUtils;
public class SongData { public class SongData {
String title; String title;
Color[] songCode; long r;
int distance=0; long g;
static int MAXTHRESHOLD=400000; long b;
long distance=0;
static int MAXTHRESHOLD=200000;
final static float TOLERANCE = 0.95f; final static float TOLERANCE = 0.95f;
public SongData(String title,Color[] songCode) { public SongData(String title,long r,long g,long b) {
this.title=title; this.title=title;
this.songCode=songCode; this.r=r;
this.g=g;
this.b=b;
} }
public static SongData getByTitle(String title) { public static SongData getByTitle(String title) {
@ -25,22 +29,15 @@ public class SongData {
return null; return null;
} }
public static SongData compareData(Color[] data) { public static SongData compareData(long r,long g,long b) {
int closestDistance = Integer.MAX_VALUE; long closestDistance = Long.MAX_VALUE;
int closestMaxThresholdDistance = Integer.MAX_VALUE;
SongData closestSong = null; SongData closestSong = null;
for (SongData s : MyRobot.SONGS) { for (SongData s : MyRobot.SONGS) {
int distance = 0; long distance = 0;
if (s!=null&&s.songCode!=null) { if (s!=null) {
for (int i=0;i<s.songCode.length;i++) { distance = (long)(Math.pow(r-s.r,2)+Math.pow(g-s.g,2)+Math.pow(b-s.b, 2));
distance += ImageUtils.distanceToColor(s.songCode[i],data[i]);
/*if (distance>MAXTHRESHOLD) {
distance=MAXTHRESHOLD+1;
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;
@ -49,18 +46,16 @@ public class SongData {
System.out.println(distance+" pixels diff: "+s.title); System.out.println(distance+" pixels diff: "+s.title);
closestMaxThresholdDistance=distance; closestMaxThresholdDistance=distance;
}*/ }*/
} else {
continue;
} }
} }
return closestSong; return closestSong;
} }
public static void saveSongToFile(String title, Color[] data) { public static void saveSongToFile(String title, long r, long g, long b) {
StringBuilder sb = new StringBuilder(title); StringBuilder sb = new StringBuilder(title);
sb.append(":"); sb.append(":");
boolean first = true; boolean first = true;
for (Color pixel : data) { /*for (Color pixel : data) {
if (first) { if (first) {
first=false; first=false;
} else { } else {
@ -68,7 +63,10 @@ public class SongData {
} }
sb.append(pixel.getRGB()); sb.append(pixel.getRGB());
//Color c = new Color(9,true); //Color c = new Color(9,true);
} }*/
sb.append(r).append(",")
.append(g).append(",")
.append(b);
FileUtils.logToFile(sb.toString(),"colorData"); FileUtils.logToFile(sb.toString(),"colorData");
} }
public static void loadSongsFromFile() throws IOException { public static void loadSongsFromFile() throws IOException {
@ -84,11 +82,9 @@ public class SongData {
String[] split = s.split(":"); String[] split = s.split(":");
String title = split[0]; String title = split[0];
String[] data = split[1].split(","); String[] data = split[1].split(",");
Color[] colors = new Color[data.length]; if (Math.pow(Long.parseLong(data[0]),2)+Math.pow(Long.parseLong(data[1]),2)+Math.pow(Long.parseLong(data[2]),2)<MyRobot.smallestSongColor) {
for (int i=0;i<data.length;i++) { MyRobot.smallestSongColor=(long)Long.parseLong(data[0])+Long.parseLong(data[1])+Long.parseLong(data[2]);
colors[i]=new Color(Integer.parseInt(data[i]),true);
} }
System.out.println("Store "+title+"/"+colors); return new SongData(title,Long.parseLong(data[0]),Long.parseLong(data[1]),Long.parseLong(data[2]));
return new SongData(title,colors);
} }
} }

@ -113,6 +113,6 @@ public class ImageUtils {
return bimage; return bimage;
} }
public static double distanceToColor(Color p2, Color p1) { public static double distanceToColor(Color p2, Color p1) {
return Math.sqrt(Math.pow(p2.getRed()-p1.getRed(), 2)+Math.pow(p2.getGreen()-p1.getGreen(), 2)+Math.pow(p2.getBlue()-p1.getBlue(), 2)); return Math.pow(p2.getRed()-p1.getRed(), 2)+Math.pow(p2.getGreen()-p1.getGreen(), 2)+Math.pow(p2.getBlue()-p1.getBlue(), 2);
} }
} }

Loading…
Cancel
Save