DDR number recognition completed (#1)

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent dfb440a723
commit 7004f21e0c
  1. 60
      readers/DDRReader.java
  2. 63
      readers/ITGReader.java
  3. 15
      readers/Reader.java
  4. BIN
      result.png
  5. 6
      sigPlace.java
  6. BIN
      sub.png

@ -20,23 +20,25 @@ public class DDRReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> extraRegions = new ArrayList<>();
static int lastJump=0;
public DDRReader(){
readRegions.add(new Box(305,428,402,69)); //score[0]
readRegions.add(new Box(603,565,133,37)); //max combo[1]
readRegions.add(new Box(603,612,133,37)); //marvelous[2]
readRegions.add(new Box(603,651,133,37)); //perfect[3]
readRegions.add(new Box(603,698,133,37)); //great[4]
readRegions.add(new Box(603,742,133,37)); //good[5]
readRegions.add(new Box(603,787,133,37)); //OK[6]
readRegions.add(new Box(603,830,133,37)); //miss[7]
readRegions.add(new Box(603,876,133,37)); //ex score[8]
readRegions.add(new Box(783,738,133,37)); //fast[9]
readRegions.add(new Box(783,821,133,37)); //slow[10]
readRegions.add(new Box(600,165,133,53)); //diffnumb[11]
readRegions.add(new Box(577,91,174,36)); //playstyle[12]
readRegions.add(new Box(253,207,357,183)); //grade[13]
readRegions.add(new Box(756,432,411,38)); //songname[14]
readRegions.add(new Box(576,126,185,40)); //difficulty text[15]
addRegion(new Box(305,428,402,69),NUMBER); //score[0]+
addRegion(new Box(603,565,133,37),NUMBER); //max combo[1]+
addRegion(new Box(603,612,133,37),NUMBER); //marvelous[2]+
addRegion(new Box(603,651,133,37),NUMBER); //perfect[3]+
addRegion(new Box(603,698,133,37),NUMBER); //great[4]+
addRegion(new Box(603,742,133,37),NUMBER); //good[5]+
addRegion(new Box(603,787,133,37),NUMBER); //OK[6]+
addRegion(new Box(603,830,133,37),NUMBER); //miss[7]+
addRegion(new Box(603,876,133,37),NUMBER); //ex score[8]+
addRegion(new Box(783,738,133,37),NUMBER); //fast[9]+
addRegion(new Box(783,821,133,37),NUMBER); //slow[10]+
addRegion(new Box(600,165,133,53),NUMBER); //diffnumb[11]+
addRegion(new Box(577,91,174,36)); //playstyle[12]
addRegion(new Box(253,207,357,183)); //grade[13]
addRegion(new Box(756,432,411,38)); //songname[14]
addRegion(new Box(576,126,185,40)); //difficulty text[15]
init();
}
void ColorFilter(int[] arr,int region,int width) {
@ -121,6 +123,7 @@ public class DDRReader extends Reader{
int regionHeights = 0;
int maxWidth = 0;
int counter=0;
for (int i=0;i<readRegions.size();i++) {
regionHeights+=readRegions.get(i).h+REGION_PADDING;
if (readRegions.get(i).w>maxWidth) {
@ -145,7 +148,10 @@ public class DDRReader extends Reader{
subRegion.setRGB(0,0,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
ImageIO.write(subRegion,"png",new File("sub.png"));
cutImg.setRGB(0,currentHeight,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
System.out.println(interpretImage(subRegion,i));
String val = interpretImage(subRegion,i);
if (!val.isEmpty()) {
sig_data[counter++]=val;
}
currentHeight+=readRegions.get(i).h+REGION_PADDING;
}
Path output = Paths.get("result.png");
@ -158,7 +164,8 @@ public class DDRReader extends Reader{
trimAllData(en_data);
System.out.println(Arrays.toString(ja_data));
System.out.println(Arrays.toString(en_data));
interpretOutput(ja_data,en_data);
System.out.println(Arrays.toString(sig_data));
//interpretOutput(ja_data,en_data);
g.dispose();
} catch (IOException e) {
e.printStackTrace();
@ -189,6 +196,23 @@ public class DDRReader extends Reader{
List<Glyph> glyphs = Glyph.split(cutImg);
return f.convertGlyphs(glyphs);
}
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 9:
case 10:{
Font f = Font.FONT_DDR_NOTECOUNT;
List<Glyph> glyphs = Glyph.split(cutImg);
return f.convertGlyphs(glyphs);
}
case 11:{
Font f = Font.FONT_DDR_DIFF;
List<Glyph> glyphs = Glyph.split(cutImg);
return f.convertGlyphs(glyphs);
}
}
return "";
}

@ -12,23 +12,26 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import readers.fonts.Font;
import readers.fonts.Glyph;
public class ITGReader extends Reader{
final static int REGION_PADDING = 32;
List<Box> extraRegions = new ArrayList<>();
static int lastJump=0;
public ITGReader(){
readRegions.add(new Box(388,552,227,60)); //score[0]
readRegions.add(new Box(797,438,164,58)); //fantastic+[1]
readRegions.add(new Box(797,493,164,58)); //fantastic[2]
readRegions.add(new Box(797,551,164,58)); //excellent[3]
readRegions.add(new Box(797,618,164,58)); //great[4]
readRegions.add(new Box(797,673,164,58)); //decent[5]
readRegions.add(new Box(797,736,164,58)); //miss[6]
readRegions.add(new Box(279,443,340,104)); //pct[7]
readRegions.add(new Box(277,364,64,60)); //diffnumb[8]
readRegions.add(new Box(344,393,266,36)); //playstyle[9]
readRegions.add(new Box(277,174,324,171)); //grade[10]
readRegions.add(new Box(632,106,656,43)); //songname[11]
addRegion(new Box(388,552,227,60),NUMBER); //score[0]
addRegion(new Box(797,438,164,58),NUMBER); //fantastic+[1]
addRegion(new Box(797,493,164,58),NUMBER); //fantastic[2]
addRegion(new Box(797,551,164,58),NUMBER); //excellent[3]
addRegion(new Box(797,618,164,58),NUMBER); //great[4]
addRegion(new Box(797,673,164,58),NUMBER); //decent[5]
addRegion(new Box(797,736,164,58),NUMBER); //miss[6]
addRegion(new Box(279,443,340,104),NUMBER); //pct[7]
addRegion(new Box(277,364,64,60),NUMBER); //diffnumb[8]
addRegion(new Box(344,393,266,36)); //playstyle[9]
addRegion(new Box(277,174,324,171)); //grade[10]
addRegion(new Box(632,106,656,43)); //songname[11]
}
void ColorFilter(int[] arr,int region,int width) {
@ -96,6 +99,7 @@ public class ITGReader extends Reader{
int regionHeights = 0;
int maxWidth = 0;
int counter = 0;
for (int i=0;i<readRegions.size();i++) {
regionHeights+=readRegions.get(i).h+REGION_PADDING;
if (readRegions.get(i).w>maxWidth) {
@ -108,14 +112,22 @@ public class ITGReader extends Reader{
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);
BufferedImage subRegion = new BufferedImage(readRegions.get(i).w, readRegions.get(i).h,BufferedImage.TYPE_INT_ARGB);
subRegion.setRGB(0,0,readRegions.get(i).w,readRegions.get(i).h,originalImg.getRGB(readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).w, readRegions.get(i).h, null, 0, readRegions.get(i).w),0,readRegions.get(i).w);
int[] arr = subRegion.getRGB(0, 0, readRegions.get(i).w, readRegions.get(i).h, null, 0, readRegions.get(i).w);
//System.out.println(Arrays.toString(arr));
//System.out.println(i);
//ImageIO.write(originalImg.getSubimage(readRegions.get(i).x, readRegions.get(i).y, readRegions.get(i).w, readRegions.get(i).h),"png",new File("cut.png"));
System.out.println(i);
ColorFilter(arr,i,readRegions.get(i).w);
subRegion.setRGB(0,0,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
ImageIO.write(subRegion,"png",new File("sub.png"));
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;
String val = interpretImage(subRegion,i);
if (!val.isEmpty()) {
sig_data[counter++]=val;
}
}
Path output = Paths.get("result.png");
ImageIO.write(cutImg,"png",output.toFile());
@ -127,6 +139,7 @@ public class ITGReader extends Reader{
trimAllData(en_data);
System.out.println(Arrays.toString(ja_data));
System.out.println(Arrays.toString(en_data));
System.out.println(Arrays.toString(sig_data));
interpretOutput(ja_data,en_data);
g.dispose();
} catch (IOException e) {
@ -136,6 +149,26 @@ public class ITGReader extends Reader{
//System.out.println(data[2]);
}
private String interpretImage(BufferedImage cutImg, int i) {
switch (i) {
case 0:{
Font f = Font.FONT_DDR_SCORE;
List<Glyph> glyphs = Glyph.split(cutImg);
if (glyphs.size()==9) {
//This is a 1,000,000 score.
glyphs.remove(5);
glyphs.remove(1);
} else
if (glyphs.size()>4) {
//This is a XXX,XXX score.
glyphs.remove(3);
}
return f.convertGlyphs(glyphs);
}
}
return "";
}
@Override
void interpretResults(String[] finalData) {
// TODO Auto-generated method stub

@ -10,6 +10,7 @@ import java.awt.Color;
public abstract class Reader{
final static int REGION_PADDING = 32;
final static boolean NUMBER = true;
int score;
int rank;
int[] notes = new int[7];
@ -18,8 +19,22 @@ public abstract class Reader{
double pct;
int maxcombo;
String other="";
String[] sig_data;
List<Box> readRegions = new ArrayList<>();
int sig_data_size = 0;
final int TRANSPARENT = new Color(0,0,0,0).getRGB();
protected void addRegion(Box box) {
addRegion(box,false);
}
protected void addRegion(Box box,boolean isNumb) {
readRegions.add(box);
if (isNumb) {
sig_data_size++;
}
}
protected void init() {
sig_data = new String[sig_data_size];
}
String readAllBoxes(Path img) {
try {
Process p = Runtime.getRuntime().exec(new String[]{"python3","runocr.py","ja",img.toAbsolutePath().toString()});

Binary file not shown.

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 174 KiB

@ -81,7 +81,7 @@ public class sigPlace {
final static int TRANSPARENT = new Color(0,0,0,0).getRGB();
public static void main(String[] args) {
String fontName = "sdvx_EXScore";
/*String fontName = "sdvx_EXScore";
String value = "04882";
Path f = Paths.get("sdvx2.png");
BufferedImage img;
@ -114,8 +114,8 @@ public class sigPlace {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//ArcadeReader.retrieveData(Paths.get("ddr5.png"));
}*/
ArcadeReader.retrieveData(Paths.get("ddr5.png"));
/* Path secretFile = Paths.get(".clientsecret");
List<String> data;
try {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save