Completed first score image parsing algorithm for Love Live
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
a7304ba139
commit
be03f8849b
@ -1,10 +1,17 @@
|
|||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
public class ArcadeReader {
|
public class ArcadeReader {
|
||||||
@ -63,6 +70,22 @@ public class ArcadeReader {
|
|||||||
new LoveLiveReader().interpretBoxes(img);
|
new LoveLiveReader().interpretBoxes(img);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class ColorRange{
|
||||||
|
int r_h,r_l;
|
||||||
|
int g_h,g_l;
|
||||||
|
int b_h,b_l;
|
||||||
|
ColorRange(int r_l,int r_h,int g_l,int g_h,int b_l,int b_h) {
|
||||||
|
this.r_l=r_l;
|
||||||
|
this.r_h=r_h;
|
||||||
|
this.g_l=g_l;
|
||||||
|
this.g_h=g_h;
|
||||||
|
this.b_l=b_l;
|
||||||
|
this.b_h=b_h;
|
||||||
|
}
|
||||||
|
boolean colorInRange(Color col) {
|
||||||
|
return col.getRed()>=r_l&&col.getRed()<=r_h&&col.getGreen()>=g_l&&col.getGreen()<=g_h&&col.getBlue()>=b_l&&col.getBlue()<=b_h;
|
||||||
|
}
|
||||||
|
}
|
||||||
class Box{
|
class Box{
|
||||||
int x,y,w,h;
|
int x,y,w,h;
|
||||||
boolean ja_required;
|
boolean ja_required;
|
||||||
@ -78,24 +101,89 @@ class Box{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
class LoveLiveReader extends Reader{
|
class LoveLiveReader extends Reader{
|
||||||
|
final static int REGION_PADDING = 32;
|
||||||
LoveLiveReader(){
|
LoveLiveReader(){
|
||||||
readRegions.add(new Box(10,10,24,24)); //score[0]
|
readRegions.add(new Box(713,401,232,50)); //score[0]
|
||||||
readRegions.add(new Box(10,40,24,24)); //rank[1]
|
readRegions.add(new Box(613,290,65,36)); //rank[1]
|
||||||
readRegions.add(new Box(10,70,24,24)); //notes[2]
|
readRegions.add(new Box(509,604,190,54)); //notes[2]
|
||||||
readRegions.add(new Box(10,70,24,24)); //notes[3]
|
readRegions.add(new Box(509,680,190,54)); //notes[3]
|
||||||
readRegions.add(new Box(10,70,24,24)); //notes[4]
|
readRegions.add(new Box(509,760,190,54)); //notes[4]
|
||||||
readRegions.add(new Box(10,70,24,24)); //notes[5]
|
readRegions.add(new Box(509,840,190,54)); //notes[5]
|
||||||
readRegions.add(new Box(10,70,24,24)); //notes[6]
|
readRegions.add(new Box(509,920,190,54)); //notes[6]
|
||||||
readRegions.add(new Box(10,70,24,24)); //notes[7]
|
readRegions.add(new Box(26,374,265,36)); //difficulty[7]
|
||||||
readRegions.add(new Box(10,70,24,24)); //notes[8]
|
readRegions.add(new Box(277,165,572,40)); //title[8]
|
||||||
readRegions.add(new Box(10,70,24,24)); //difficulty[9]
|
readRegions.add(new Box(716,502,226,45)); //pct[9]
|
||||||
readRegions.add(new Box(10,70,24,24)); //title[10]
|
readRegions.add(new Box(782,452,158,50)); //maxcombo[10]
|
||||||
readRegions.add(new Box(10,70,24,24)); //pct[11]
|
|
||||||
readRegions.add(new Box(10,70,24,24)); //maxcombo[12]
|
|
||||||
readRegions.add(new Box(10,70,24,24)); //other...[13]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void seek(int[]arr,int i,ColorRange SEEKCOLOR,Color FINALCOLOR,int width) {
|
||||||
|
arr[i]=FINALCOLOR.getRGB();
|
||||||
|
for (int x=-1;x<=1;x++) {
|
||||||
|
for (int y=-1;y<=1;y++) {
|
||||||
|
if (SEEKCOLOR.colorInRange(new Color(arr[i+x+y*width]))) {
|
||||||
|
seek(arr,i+x+y*width,SEEKCOLOR,FINALCOLOR,width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorFilter(int[] arr,int region,int width) {
|
||||||
|
final int TRANSPARENT = new Color(0,0,0,0).getRGB();
|
||||||
|
switch (region) {
|
||||||
|
case 0:{
|
||||||
|
final ColorRange TARGETCOLOR = new ColorRange(240,255,130,150,0,10);
|
||||||
|
final ColorRange SEEKINGCOLOR = new ColorRange(140,255,110,255,0,200);
|
||||||
|
final Color FINALCOLOR = Color.MAGENTA;
|
||||||
|
for (int i=0;i<arr.length;i++) {
|
||||||
|
Color col = new Color(arr[i],true);
|
||||||
|
if (TARGETCOLOR.colorInRange(col)) {
|
||||||
|
seek(arr,i,SEEKINGCOLOR,FINALCOLOR,width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i=0;i<arr.length;i++) {
|
||||||
|
Color col = new Color(arr[i],true);
|
||||||
|
if (!col.equals(Color.MAGENTA)) {
|
||||||
|
arr[i]=TRANSPARENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void interpretBoxes(Path img){
|
void interpretBoxes(Path img){
|
||||||
String dataString = readAllBoxes(img);
|
/*String dataString = readAllBoxes(img);
|
||||||
|
String[] data = dataString.split(Pattern.quote("\n"));
|
||||||
|
String[] ja_data = data[0].split(Pattern.quote(")"));
|
||||||
|
String[] en_data = data[2].split(Pattern.quote(")"));
|
||||||
|
trimAllData(ja_data);
|
||||||
|
trimAllData(en_data);
|
||||||
|
System.out.println(Arrays.toString(ja_data));
|
||||||
|
System.out.println(Arrays.toString(en_data));*/
|
||||||
|
|
||||||
|
int regionHeights = 0;
|
||||||
|
int maxWidth = 0;
|
||||||
|
for (int i=0;i<readRegions.size();i++) {
|
||||||
|
regionHeights+=readRegions.get(i).h+REGION_PADDING;
|
||||||
|
if (readRegions.get(i).w>maxWidth) {
|
||||||
|
maxWidth=readRegions.get(i).w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
BufferedImage originalImg = ImageIO.read(img.toFile());
|
||||||
|
BufferedImage cutImg = new BufferedImage(maxWidth,regionHeights,BufferedImage.TYPE_INT_ARGB);
|
||||||
|
Graphics2D g = cutImg.createGraphics();
|
||||||
|
int currentHeight=0;
|
||||||
|
for (int i=0;i<readRegions.size();i++) {
|
||||||
|
int[] arr = originalImg.getRGB(readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).w, readRegions.get(i).h, null, 0, readRegions.get(i).w);
|
||||||
|
//System.out.println(Arrays.toString(arr));
|
||||||
|
ColorFilter(arr,i,readRegions.get(i).w);
|
||||||
|
//g.drawImage(originalImg, 0,currentHeight,readRegions.get(i).w,readRegions.get(i).h+currentHeight,readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).x+readRegions.get(i).w, readRegions.get(i).y+readRegions.get(i).h, null);
|
||||||
|
cutImg.setRGB(0,currentHeight,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
|
||||||
|
currentHeight+=readRegions.get(i).h+REGION_PADDING;
|
||||||
|
}
|
||||||
|
Path output = Paths.get("result.png");
|
||||||
|
ImageIO.write(cutImg,"png",output.toFile());
|
||||||
|
String dataString = readAllBoxes(output);
|
||||||
String[] data = dataString.split(Pattern.quote("\n"));
|
String[] data = dataString.split(Pattern.quote("\n"));
|
||||||
String[] ja_data = data[0].split(Pattern.quote(")"));
|
String[] ja_data = data[0].split(Pattern.quote(")"));
|
||||||
String[] en_data = data[2].split(Pattern.quote(")"));
|
String[] en_data = data[2].split(Pattern.quote(")"));
|
||||||
@ -103,8 +191,9 @@ class LoveLiveReader extends Reader{
|
|||||||
trimAllData(en_data);
|
trimAllData(en_data);
|
||||||
System.out.println(Arrays.toString(ja_data));
|
System.out.println(Arrays.toString(ja_data));
|
||||||
System.out.println(Arrays.toString(en_data));
|
System.out.println(Arrays.toString(en_data));
|
||||||
for (int i=0;i<readRegions.size();i++) {
|
g.dispose();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
//System.out.println(data[0]);
|
//System.out.println(data[0]);
|
||||||
//System.out.println(data[2]);
|
//System.out.println(data[2]);
|
||||||
|
BIN
lovelive1.png
Normal file
BIN
lovelive1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 MiB |
BIN
result.png
BIN
result.png
Binary file not shown.
Before Width: | Height: | Size: 858 B After Width: | Height: | Size: 104 KiB |
@ -48,7 +48,7 @@ public class sigPlace {
|
|||||||
"%FOOTER", Paths.get(REFDIR,"FOOTER.html"))
|
"%FOOTER", Paths.get(REFDIR,"FOOTER.html"))
|
||||||
));
|
));
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
ArcadeReader.retrieveData(Paths.get("sdvx.jpg"));
|
ArcadeReader.retrieveData(Paths.get("lovelive1.png"));
|
||||||
/* Path secretFile = Paths.get(".clientsecret");
|
/* Path secretFile = Paths.get(".clientsecret");
|
||||||
List<String> data;
|
List<String> data;
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user