Update Future Tone detection for live streaming and improve typeface

recognition.
master
sigonasr2 4 years ago
parent 457bbb6fa8
commit 239fa86d6b
  1. BIN
      image.png
  2. BIN
      rectangle0.png
  3. BIN
      rectangle1.png
  4. BIN
      rectangle2.png
  5. BIN
      rectangle3.png
  6. BIN
      rectangle4.png
  7. 94
      src/main/java/com/example/demo/ColorRegion.java
  8. 50
      src/main/java/com/example/demo/Controller.java
  9. 7
      src/main/java/com/example/demo/DemoApplication.java
  10. BIN
      test.png
  11. BIN
      typeface.png
  12. BIN
      typeface5.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 7.2 KiB

@ -0,0 +1,94 @@
package com.example.demo;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.Arrays;
public class ColorRegion {
Rectangle region;
BufferedImage img;
ColorRegion(BufferedImage img, Rectangle region){
this.region=region;
this.img=img;
}
public boolean getRedRange(int min,int max) {
int avgRed = getRed();
return avgRed>=min&&avgRed<=max;
}
public boolean getGreenRange(int min,int max) {
int avgGreen = getGreen();
return avgGreen>=min&&avgGreen<=max;
}
public boolean getBlueRange(int min,int max) {
int avgBlue = getBlue();
return avgBlue>=min&&avgBlue<=max;
}
public boolean getAllRange(int min,int max) {
return getRedRange(min,max)&&getGreenRange(min,max)&&getBlueRange(min,max);
}
public boolean getAllRange(int minRed,int maxRed,int minGreen,int maxGreen,int minBlue,int maxBlue) {
return getRedRange(minRed,maxRed)&&getGreenRange(minGreen,maxGreen)&&getBlueRange(minBlue,maxBlue);
}
public int getRed() {
int total = 0;
for (int x=0;x<region.width;x++) {
for (int y=0;y<region.height;y++) {
if (region.x+x<0||region.x+x>=region.x+region.width||region.y+y<0||region.y+y>=region.y+region.height) {
continue;
}
try {
total+=new Color(img.getRGB(region.x+x, region.y+y)).getRed();
} catch (NullPointerException|ArrayIndexOutOfBoundsException e) {
}
}
}
return total/(region.width*region.height);
}
public int getGreen() {
int total = 0;
for (int x=0;x<region.width;x++) {
for (int y=0;y<region.height;y++) {
if (region.x+x<0||region.x+x>=region.x+region.width||region.y+y<0||region.y+y>=region.y+region.height) {
continue;
}
try {
total+=new Color(img.getRGB(region.x+x, region.y+y)).getGreen();
} catch (NullPointerException|ArrayIndexOutOfBoundsException e) {
}
}
}
return total/(region.width*region.height);
}
public int getBlue() {
int total = 0;
for (int x=0;x<region.width;x++) {
for (int y=0;y<region.height;y++) {
if (region.x+x<0||region.x+x>=region.x+region.width||region.y+y<0||region.y+y>=region.y+region.height) {
continue;
}
try {
total+=new Color(img.getRGB(region.x+x, region.y+y)).getBlue();
} catch (NullPointerException|ArrayIndexOutOfBoundsException e) {
}
}
}
return total/(region.width*region.height);
}
public String toString() {
StringBuilder sb = new StringBuilder("ColorRegion(Region: ");
return sb.append(region).append(",")
.append("R:").append(getRed()).append(",")
.append("G:").append(getGreen()).append(",")
.append("B:").append(getBlue()).append(")")
.toString();
}
}

@ -200,7 +200,8 @@ public class Controller {
Point crop2 = null;
Color col = new Color(img.getRGB(0, 0));
if (col.getRed()<=5&&col.getGreen()<=5&&col.getBlue()<=5) {
ColorRegion ft_results = new ColorRegion(img,new Rectangle(81,35,80,37));
if ((col.getRed()<=5&&col.getGreen()<=5&&col.getBlue()<=5)||ft_results.getAllRange(30,150,60,180,60,180)) {
MyRobot.FUTURETONE=true;
boolean done=false;
for (int x=img.getWidth()-1;x>=img.getWidth()*(7f/8);x--) {
@ -239,6 +240,10 @@ public class Controller {
}
public static String getSongTitle(BufferedImage img) throws IOException {
return getSongTitle(img,false);
}
public static String getSongTitle(BufferedImage img,boolean debugging) throws IOException {
final int THRESHOLD=1;
float lowestMatching = Integer.MAX_VALUE;
SongData matchingSong = null;
@ -255,45 +260,54 @@ public class Controller {
Color p2 = song.data[(y*8)+x];
Color p1 = new Color(img.getRGB(x+352, y+288));
matching+=ImageUtils.distanceToColor(p2,p1);
/*debug.setRGB(x,y,p2.getRGB());
debug.setRGB(x+8,y,p1.getRGB());*/
if (debugging) {
debug.setRGB(x,y,p2.getRGB());
debug.setRGB(x+8,y,p1.getRGB());
}
}
}
if (matching<lowestMatching) {
lowestMatching=matching;
matchingSong = song;
}
/*try {
PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.println("Comparing to "+song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")+": "+matching);
//ImageIO.write(debug,"png",new File("debugcol",song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
if (debugging) {
try {
PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.println("Comparing to "+song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")+": "+matching);
//ImageIO.write(debug,"png",new File("debugcol",song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
*/
}
} else {
for (SongData song : DemoApplication.songs) {
BufferedImage debug = new BufferedImage(16,288,BufferedImage.TYPE_INT_ARGB);
float matching = 0;
for (int y=0;y<288;y++) {
for (int x=0;x<8;x++) {
Color p2 = song.data[(y*8)+x];
Color p1 = new Color(img.getRGB(x+352, y+288));
matching+=ImageUtils.distanceToColor(p2,p1);
if (debugging) {
debug.setRGB(x,y,p2.getRGB());
debug.setRGB(x+8,y,p1.getRGB());
}
}
}
if (matching<lowestMatching) {
lowestMatching=matching;
matchingSong = song;
}
/*try {
PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.println("Comparing to "+song.song+": "+matching);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}*/
if (debugging) {
try {
PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.println("Comparing to "+song.song+": "+matching);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}

@ -42,6 +42,9 @@ public class DemoApplication {
public static void main(String[] args) throws IOException {
SpringApplication.run(DemoApplication.class, args);
File debugFolder = new File("debug");
FileUtils.deleteFile(debugFolder);
if (REDO_COLOR_DATA) {
File colordat = new File("colorData");
colordat.delete();
@ -70,6 +73,8 @@ public class DemoApplication {
for (String s : str) {
FTsongs.add(new SongData(s));
}
RunTest("test5.png","ZIGG-ZAGG",88,18,1,2,13,11.87f,true,"EXEX","HS",28,88935,false);
RunTest("test3.png","メルト",39,9,0,0,9,7.44f,true,"EXEX","HS",48,40040,false);
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);
@ -206,7 +211,7 @@ public class DemoApplication {
img = ImageUtils.toBufferedImage(img.getScaledInstance(1200, 675, Image.SCALE_SMOOTH));
}
ImageIO.write(img,"png",new File("image.png"));
String song = Controller.getSongTitle(img);
String song = Controller.getSongTitle(img,debug);
song = getCorrectSongName(song);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save