2020-07-18 08:47:04 +09:00
|
|
|
|
package com.example.demo;
|
|
|
|
|
|
2020-07-20 05:40:04 +09:00
|
|
|
|
import java.awt.Image;
|
|
|
|
|
import java.awt.Point;
|
|
|
|
|
import java.awt.Rectangle;
|
2020-07-19 05:25:56 +09:00
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.ArrayList;
|
2020-07-20 05:40:04 +09:00
|
|
|
|
import java.util.Arrays;
|
2020-07-19 05:25:56 +09:00
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
2020-07-20 20:13:58 +09:00
|
|
|
|
import org.json.JSONException;
|
2020-07-18 08:47:04 +09:00
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
2020-07-20 05:40:04 +09:00
|
|
|
|
import org.springframework.util.Assert;
|
2020-07-18 08:47:04 +09:00
|
|
|
|
|
2020-09-08 22:56:43 +09:00
|
|
|
|
import sig.Result;
|
|
|
|
|
import sig.TypeFace2;
|
2020-07-19 05:25:56 +09:00
|
|
|
|
import sig.utils.FileUtils;
|
2020-07-20 05:40:04 +09:00
|
|
|
|
import sig.utils.ImageUtils;
|
2020-07-19 05:25:56 +09:00
|
|
|
|
|
2020-07-18 08:47:04 +09:00
|
|
|
|
@SpringBootApplication
|
|
|
|
|
public class DemoApplication {
|
2020-07-19 05:25:56 +09:00
|
|
|
|
|
|
|
|
|
public static List<SongData> songs = new ArrayList<SongData>();
|
2020-09-08 22:56:43 +09:00
|
|
|
|
public static TypeFace2 typeface1;
|
|
|
|
|
public static TypeFace2 typeface2;
|
|
|
|
|
public static TypeFace2 typeface3;
|
2020-07-20 20:13:58 +09:00
|
|
|
|
static String testdir="resources";
|
2020-07-20 05:40:04 +09:00
|
|
|
|
static Integer totalConfidence = 0;
|
|
|
|
|
static TestResult result = null;
|
|
|
|
|
static Integer generation = 30; //Confidence level.
|
2020-09-08 22:56:43 +09:00
|
|
|
|
|
2020-09-17 04:38:42 +09:00
|
|
|
|
final static boolean REDO_COLOR_DATA = true;
|
2020-07-18 08:47:04 +09:00
|
|
|
|
|
2020-09-08 22:56:43 +09:00
|
|
|
|
public static void main(String[] args) throws IOException {
|
2020-07-18 08:47:04 +09:00
|
|
|
|
SpringApplication.run(DemoApplication.class, args);
|
2020-07-19 05:25:56 +09:00
|
|
|
|
|
2020-09-08 22:56:43 +09:00
|
|
|
|
if (REDO_COLOR_DATA) {
|
|
|
|
|
File colordat = new File("colorData");
|
|
|
|
|
colordat.delete();
|
|
|
|
|
File dir = new File("resources");
|
|
|
|
|
for (String s : dir.list()) {
|
|
|
|
|
StringBuilder sb = new StringBuilder(s.replace(".jpg","")).append(":");
|
|
|
|
|
boolean first=true;
|
|
|
|
|
try {
|
|
|
|
|
BufferedImage img = ImageIO.read(new File(dir,s));
|
|
|
|
|
if (img.getWidth()!=1200) {
|
|
|
|
|
img = ImageUtils.toBufferedImage(img.getScaledInstance(1200, 675, Image.SCALE_SMOOTH));
|
|
|
|
|
}
|
|
|
|
|
for (int y=288;y<288+288;y++) {
|
|
|
|
|
for (int x=352;x<352+8;x++) {
|
|
|
|
|
if (!first) {
|
|
|
|
|
sb.append(",");
|
|
|
|
|
} else {
|
|
|
|
|
first=false;
|
|
|
|
|
}
|
|
|
|
|
sb.append(img.getRGB(x, y));
|
2020-07-19 05:25:56 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-08 22:56:43 +09:00
|
|
|
|
FileUtils.logToFile(sb.toString(), "colorData");
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
2020-07-19 05:25:56 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-08 22:56:43 +09:00
|
|
|
|
}
|
2020-07-20 05:40:04 +09:00
|
|
|
|
/*File dir = new File("resources");
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
for (String s : dir.list()) {
|
|
|
|
|
sb.append("and name!='").append(s.replace(".jpg","")).append("' ");
|
|
|
|
|
}
|
|
|
|
|
FileUtils.logToFile(sb.toString(), "command");*/
|
2020-09-08 22:56:43 +09:00
|
|
|
|
typeface1 = new TypeFace2(ImageUtils.toCompatibleImage(ImageIO.read(new File("typeface.png"))),
|
|
|
|
|
ImageUtils.toCompatibleImage(ImageIO.read(new File("typeface2.png"))),
|
|
|
|
|
ImageUtils.toCompatibleImage(ImageIO.read(new File("typeface3.png"))));
|
2020-07-19 05:25:56 +09:00
|
|
|
|
|
|
|
|
|
String[] str = FileUtils.readFromFile("colorData");
|
|
|
|
|
for (String s : str) {
|
|
|
|
|
songs.add(new SongData(s));
|
|
|
|
|
}
|
2020-07-20 18:42:48 +09:00
|
|
|
|
RunTest("16 -out of the gravity-.jpg",554,45,1,0,1,101.36f,false,"EX","HS",339,606780);
|
|
|
|
|
RunTest("*ハロー、プラネット。 (I.M.PLSE-EDIT).jpg",336,128,24,6,93,58.85f,true,"EX","",52,308760);
|
2020-07-20 05:40:04 +09:00
|
|
|
|
|
2020-07-20 18:42:48 +09:00
|
|
|
|
RunTest("39.jpg",531,71,2,0,2,97.82f,false,"EXEX","HS",324,832390);
|
|
|
|
|
RunTest("39みゅーじっく!.jpg",573,175,5,0,18,91.22f,false,"EX","HS",354,754140);
|
|
|
|
|
RunTest("1925.jpg",510,115,14,7,22,77.79f,false,"EX","HS",85,564860);
|
|
|
|
|
RunTest("ACUTE.jpg",478,64,1,1,5,95.76f,false,"EX","HS",197,505210);
|
|
|
|
|
RunTest("AFTER BURNER.jpg",370,113,25,16,30,68.76f,true,"EX","HS",94,386390);
|
|
|
|
|
RunTest("Blackjack.jpg",415,123,15,7,50,71.22f,false,"EX","HS",79,443260);
|
|
|
|
|
RunTest("Catch the Wave.jpg",603,72,0,0,1,100.65f,false,"EX","HS",559,773570);
|
|
|
|
|
RunTest("Dear.jpg",402,64,0,0,1,100.90f,false,"EXEX","HS",394,587740);
|
|
|
|
|
RunTest("DECORATOR.jpg",436,100,1,0,6,93.52f,false,"EX","HS",217,560180);
|
|
|
|
|
RunTest("DYE.jpg",530,106,7,2,13,84.77f,false,"EX","HS",143,486360);
|
|
|
|
|
RunTest("erase or zero.jpg",442,70,0,0,2,100.12f,false,"EX","HS",265,731120);
|
|
|
|
|
RunTest("FREELY TOMORROW.jpg",367,57,0,0,0,102.84f,false,"EX","HS",424,498640);
|
|
|
|
|
RunTest("from Y to Y.jpg",350,49,6,1,8,86.35f,false,"EXEX","HS",139,427650);
|
|
|
|
|
RunTest("Glory 3usi9.jpg",468,43,0,0,2,101.62f,false,"EX","HS",382,549780);
|
|
|
|
|
RunTest("Hand in Hand.jpg",401,54,1,0,3,97.58f,false,"EX","HS",176,610040);
|
|
|
|
|
RunTest("Hello, Worker.jpg",439,118,7,1,14,89.93f,false,"EXEX","HS",147,930290);
|
|
|
|
|
RunTest("Just Be Friends.jpg",510,107,6,0,12,89.38f,false,"EXEX","HS",203,602080);
|
|
|
|
|
RunTest("Knife.jpg",327,85,14,9,27,51.96f,true,"EX","HS",124,395170);
|
|
|
|
|
RunTest("LIKE THE WIND.jpg",330,144,20,9,20,72.06f,false,"EX","HS",65,425970);
|
|
|
|
|
RunTest("LOL -lots of laugh-.jpg",489,59,1,2,2,96.36f,false,"EX","HS",183,641920);
|
|
|
|
|
RunTest("magnet.jpg",435,101,18,4,35,76.98f,false,"EXEX","HS",115,480540);
|
|
|
|
|
RunTest("No Logic.jpg",491,101,11,5,15,86.32f,false,"EX","HS",186,476910);
|
|
|
|
|
RunTest("Nostalogic.jpg",346,70,15,7,16,83.61f,false,"EX","HS",94,486030);
|
|
|
|
|
RunTest("WORLD'S END UMBRELLA.jpg",437,136,6,1,3,90.59f,false,"H","",215,475120);
|
|
|
|
|
RunTest("ぽっぴっぽー.jpg",350,46,7,6,3,80.39f,false,"N","",175,263630);
|
|
|
|
|
RunTest("サマーアイドル.jpg",245,19,4,0,2,87.04f,false,"E","",103,179360);
|
2020-09-08 22:56:43 +09:00
|
|
|
|
//RunTest("ジターバグ_2.jpg","ジターバグ",0,0,0,0,159,0.00f,true,"EX","SD",0,0);
|
|
|
|
|
//RunTest("大江戸ジュリアナイト_2.jpg","大江戸ジュリアナイト",0,0,0,0,79,0.08f,true,"EX","HD",0,580);
|
|
|
|
|
/*RunRemoteTest("http://projectdivar.com/files/DECORATOR_EXplay_436_100_1_0_6_93.52.png","DECORATOR",436,100,1,0,6,93.52f,false,"EX","HS",217,560180);
|
2020-07-20 20:13:58 +09:00
|
|
|
|
RunRemoteTest("http://projectdivar.com/files/img2.png","SING&SMILE",551,168,7,2,15,87.24f,false,"EX","HS",138,733310);
|
|
|
|
|
RunRemoteTest("http://projectdivar.com/files/img3.png","忘却心中",361,89,31,9,28,79.20f,false,"EXEX","HS",55,693650);
|
|
|
|
|
RunRemoteTest("http://projectdivar.com/files/img4.png","ロミオとシンデレラ",612,70,7,0,12,88.05f,false,"EX","HS",339,522350);
|
2020-09-08 22:56:43 +09:00
|
|
|
|
RunRemoteTest("http://projectdivar.com/files/img5.png","巨大少女",441,33,0,1,3,102.11f,false,"EXEX","HS",244,673260);*/
|
|
|
|
|
RunRemoteTest("http://projectdivar.com/files/146.jpg","アンハッピーリフレイン",942,71,1,0,3,97.02f,false,"EXEX","",714,951020);
|
2020-07-20 05:40:04 +09:00
|
|
|
|
System.out.println("All Tests passed!");
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 04:38:42 +09:00
|
|
|
|
public static String getCorrectSongName(String song) {
|
|
|
|
|
switch (song.toLowerCase()) {
|
|
|
|
|
case "pianogirl":{
|
|
|
|
|
return "PIANO*GIRL";
|
|
|
|
|
}
|
|
|
|
|
case "16 -out of the gravity-":{
|
|
|
|
|
return "1/6 -out of the gravity-";
|
|
|
|
|
}
|
|
|
|
|
case "ファインダー (DSLR remix - reedit)":{
|
|
|
|
|
return "ファインダー (DSLR remix - re:edit)";
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return song;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:42:48 +09:00
|
|
|
|
static void RunTest(String _img,String _song,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,boolean _fail,String _difficulty,String _mod
|
2020-09-08 22:56:43 +09:00
|
|
|
|
,int _combo,int _score,boolean debug) throws IOException {
|
2020-07-20 20:13:58 +09:00
|
|
|
|
if (!_img.equalsIgnoreCase("image.png")) {
|
|
|
|
|
System.out.println("Running test "+_img);
|
|
|
|
|
}
|
2020-07-20 05:40:04 +09:00
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
Point offset = new Point(418,204);
|
|
|
|
|
File tmp = new File("tmp");
|
|
|
|
|
if (tmp.exists()) {
|
|
|
|
|
FileUtils.deleteFile(tmp);
|
|
|
|
|
}
|
|
|
|
|
tmp.mkdir();
|
|
|
|
|
BufferedImage img=null;
|
2020-09-08 22:56:43 +09:00
|
|
|
|
File f = new File(testdir,_img);
|
|
|
|
|
Assert.isTrue(f.exists(),"Expected file to exist: "+f.getAbsoluteFile());
|
|
|
|
|
img = ImageIO.read(f);
|
|
|
|
|
Result r = typeface1.getAllData(img,debug);
|
|
|
|
|
if (img.getWidth()!=1200) {
|
|
|
|
|
//Resize.
|
|
|
|
|
img = ImageUtils.toBufferedImage(ImageIO.read(new File(testdir,_img)).getScaledInstance(1200, 675, Image.SCALE_SMOOTH));
|
|
|
|
|
}
|
|
|
|
|
ImageIO.write(img,"png",new File("image.png"));
|
2020-07-20 05:40:04 +09:00
|
|
|
|
String song = Controller.getSongTitle(img);
|
2020-09-08 22:56:43 +09:00
|
|
|
|
|
2020-07-20 05:40:04 +09:00
|
|
|
|
|
2020-09-17 04:38:42 +09:00
|
|
|
|
song = getCorrectSongName(song);
|
|
|
|
|
_song = getCorrectSongName(_song);
|
2020-07-20 05:40:04 +09:00
|
|
|
|
|
2020-07-20 18:42:48 +09:00
|
|
|
|
Assert.isTrue(song.equalsIgnoreCase(_song),"Expected song name to be "+_song+", got "+song);
|
2020-09-08 22:56:43 +09:00
|
|
|
|
Assert.isTrue(r.cool == _cool,"Expected cool count to be "+_cool+", got "+r.cool);
|
|
|
|
|
Assert.isTrue(r.fine == _fine,"Expected fine count to be "+_fine+", got "+r.fine);
|
|
|
|
|
Assert.isTrue(r.safe == _safe,"Expected safe count to be "+_safe+", got "+r.safe);
|
|
|
|
|
Assert.isTrue(r.sad == _sad,"Expected sad count to be "+_sad+", got "+r.sad);
|
|
|
|
|
Assert.isTrue(r.worst == _worst,"Expected worst count to be "+_worst+", got "+r.worst);
|
|
|
|
|
Assert.isTrue(r.percent == _percent,"Expected percent to be "+_percent+", got "+r.percent);
|
|
|
|
|
Assert.isTrue(r.combo == _combo,"Expected combo to be "+_combo+", got "+r.combo);
|
|
|
|
|
Assert.isTrue(r.score == _score,"Expected score to be "+_score+", got "+r.score);
|
|
|
|
|
Assert.isTrue(r.fail == _fail,"Expected fail to be "+_fail+", got "+r.fail);
|
|
|
|
|
Assert.isTrue(r.difficulty.equalsIgnoreCase(_difficulty),"Expected difficulty to be "+_difficulty+", got "+r.difficulty);
|
|
|
|
|
Assert.isTrue(_mod.equalsIgnoreCase(r.mod),"Expected mod to be "+_mod+", got "+r.mod);
|
2020-07-20 05:40:04 +09:00
|
|
|
|
System.out.println(" Passed ("+(System.currentTimeMillis()-startTime)+"ms)!");
|
2020-07-18 08:47:04 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 22:56:43 +09:00
|
|
|
|
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,boolean _fail,String _difficulty,String _mod
|
|
|
|
|
,int _combo, int _score) throws IOException {
|
|
|
|
|
RunTest(_img,_img.replace(".jpg",""),_cool,_fine,_safe,_sad,_worst,_percent,_fail,_difficulty,_mod,_combo,_score,false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void RunRemoteTest(String url,String song,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,boolean _fail,String _difficulty,String _mod
|
|
|
|
|
,int _combo, int _score) throws IOException {
|
|
|
|
|
System.out.println("Running remote test "+url);
|
|
|
|
|
File file = new File(testdir,"image.png");
|
|
|
|
|
file.delete();
|
|
|
|
|
try {
|
|
|
|
|
FileUtils.downloadFileFromUrl(url, file.getAbsolutePath());
|
|
|
|
|
} catch (JSONException | IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
RunTest("image.png",song,_cool,_fine,_safe,_sad,_worst,_percent,_fail,_difficulty,_mod,_combo,_score,false);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 20:13:58 +09:00
|
|
|
|
static void RunRemoteTest(String url,String song,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,boolean _fail,String _difficulty,String _mod
|
2020-09-08 22:56:43 +09:00
|
|
|
|
,int _combo, int _score,boolean debug) throws IOException {
|
2020-07-20 20:13:58 +09:00
|
|
|
|
System.out.println("Running remote test "+url);
|
|
|
|
|
File file = new File(testdir,"image.png");
|
|
|
|
|
file.delete();
|
|
|
|
|
try {
|
|
|
|
|
FileUtils.downloadFileFromUrl(url, file.getAbsolutePath());
|
|
|
|
|
} catch (JSONException | IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
2020-09-08 22:56:43 +09:00
|
|
|
|
RunTest("image.png",song,_cool,_fine,_safe,_sad,_worst,_percent,_fail,_difficulty,_mod,_combo,_score,debug);
|
2020-07-20 20:13:58 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:42:48 +09:00
|
|
|
|
static void RunTest(String _img,int _cool,int _fine, int _safe, int _sad, int _worst, float _percent,boolean _fail,String _difficulty,String _mod
|
2020-09-08 22:56:43 +09:00
|
|
|
|
,int _combo, int _score,boolean debug) throws IOException {
|
|
|
|
|
RunTest(_img,_img.replace(".jpg",""),_cool,_fine,_safe,_sad,_worst,_percent,_fail,_difficulty,_mod,_combo,_score,debug);
|
2020-07-20 18:42:48 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-18 08:47:04 +09:00
|
|
|
|
}
|