Popn Music Number recognition implemented (#1)

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 2 years ago
parent 59ba8c0a80
commit 596f4f1e7d
  1. 2
      ArcadeReader.java
  2. 89
      readers/PopnReader.java
  3. BIN
      result.png
  4. 2
      sigPlace.java
  5. BIN
      sub.png

@ -59,6 +59,6 @@ public class ArcadeReader {
*
*/
public static void retrieveData(Path img) {
new LoveLiveReader().interpretBoxes(img);
new PopnReader().interpretBoxes(img);
}
}

@ -2,6 +2,7 @@ package readers;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -12,20 +13,23 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import readers.fonts.Font;
import readers.fonts.Glyph;
public class PopnReader extends Reader{
List<Box> extraRegions = new ArrayList<>();
static int lastJump=0;
public PopnReader(){
readRegions.add(new Box(941,609,275,54)); //score[0]
readRegions.add(new Box(1060,684,157,40)); //cool[1]
readRegions.add(new Box(1060,724,157,39)); //great[2]
readRegions.add(new Box(1060,761,157,40)); //good[3]
readRegions.add(new Box(1060,800,157,40)); //bad[4]
readRegions.add(new Box(1060,858,157,42)); //combo[5]
readRegions.add(new Box(970,288,271,50)); //diff[6]
readRegions.add(new Box(689,345,547,128)); //song[7]
readRegions.add(new Box(502,23,314,288)); //rating[8]
readRegions.add(new Box(692,525,532,16)); //lifebar[9]
addRegion(new Box(941,609,275,54),NUMBER); //score[0]
addRegion(new Box(1060,684,157,40),NUMBER); //cool[1]
addRegion(new Box(1060,724,157,39),NUMBER); //great[2]
addRegion(new Box(1060,761,157,40),NUMBER); //good[3]
addRegion(new Box(1060,800,157,40),NUMBER); //bad[4]
addRegion(new Box(1060,858,157,42),NUMBER); //combo[5]
addRegion(new Box(970,288,271,50)); //diff[6]
addRegion(new Box(689,345,547,128)); //song[7]
addRegion(new Box(502,23,314,288)); //rating[8]
addRegion(new Box(692,525,532,16)); //lifebar[9]
extraRegions.add(new Box(699,616,179,44)); //score text[0]
extraRegions.add(new Box(712,680,164,40)); //cool text[1]
@ -34,6 +38,7 @@ public class PopnReader extends Reader{
extraRegions.add(new Box(712,800,101,38)); //bad text[4]
extraRegions.add(new Box(708,861,170,39)); //combo text[5]
extraRegions.add(new Box(970,290,194,47)); //diff text[6]
init();
}
void ColorFilter(int[] arr,int region,int width) {
@ -123,6 +128,7 @@ public class PopnReader 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) {
@ -135,37 +141,21 @@ public class PopnReader 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"));
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);
int leftMost=readRegions.get(i).w;
for (int j=0;j<arr.length;j++) {
if (arr[j]==Color.MAGENTA.getRGB()&&j%readRegions.get(i).w<leftMost) {
leftMost=j%readRegions.get(i).w;
}
}
if (i<=6) {
int[] arr2 = originalImg.getRGB(extraRegions.get(i).x, extraRegions.get(i).y, extraRegions.get(i).w, extraRegions.get(i).h, null, 0, extraRegions.get(i).w);
int rightMost=0;
ColorFilter(arr2,400+i,extraRegions.get(i).w);
for (int j=0;j<arr2.length;j++) {
if (arr2[j]==Color.MAGENTA.getRGB()&&j%extraRegions.get(i).w>rightMost) {
rightMost=j%extraRegions.get(i).w;
}
}
//cutImg.setRGB(rightMost-leftMost,currentHeight,readRegions.get(i).w,readRegions.get(i).h,arr,0,readRegions.get(i).w);
cutImg.setRGB(0,currentHeight,extraRegions.get(i).w,extraRegions.get(i).h,arr2,0,extraRegions.get(i).w);
final int PADDING = 4;
for (int x=leftMost;x<readRegions.get(i).w;x++) {
for (int y=0;y<readRegions.get(i).h;y++) {
cutImg.setRGB(x+rightMost-leftMost+PADDING, y+currentHeight, arr[y*readRegions.get(i).w+x]);
}
}
} else {
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);
String val = interpretImage(subRegion,i);
if (!val.isEmpty()) {
sig_data[counter++]=val;
}
currentHeight+=readRegions.get(i).h+REGION_PADDING;
}
@ -179,7 +169,8 @@ public class PopnReader 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();
@ -188,6 +179,30 @@ public class PopnReader extends Reader{
//System.out.println(data[2]);
}
private String interpretImage(BufferedImage cutImg, int i) {
switch (i) {
case 0:{
Font f = Font.FONT_POPN_SCORE;
List<Glyph> glyphs = Glyph.split(cutImg);
return f.convertGlyphs(glyphs);
}
case 1:
case 2:
case 3:
case 4:{
Font f = Font.FONT_POPN_NOTECOUNT;
List<Glyph> glyphs = Glyph.split(cutImg);
return f.convertGlyphs(glyphs);
}
case 5:{
Font f = Font.FONT_POPN_COMBO;
List<Glyph> glyphs = Glyph.split(cutImg);
return f.convertGlyphs(glyphs);
}
}
return "";
}
@Override
void interpretResults(String[] finalData) {
for (int i=0;i<finalData.length;i++) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 187 KiB

@ -115,7 +115,7 @@ public class sigPlace {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
ArcadeReader.retrieveData(Paths.get("lovelive2.png"));
ArcadeReader.retrieveData(Paths.get("popn8.png"));
/* Path secretFile = Paths.get(".clientsecret");
List<String> data;
try {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 683 B

After

Width:  |  Height:  |  Size: 10 KiB

Loading…
Cancel
Save