Update Future Tone detection for live streaming and improve typeface
recognition.
BIN
image.png
Before Width: | Height: | Size: 1.0 MiB After Width: | Height: | Size: 1.8 MiB |
BIN
rectangle0.png
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 7.0 KiB |
BIN
rectangle1.png
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 6.0 KiB |
BIN
rectangle2.png
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 5.5 KiB |
BIN
rectangle3.png
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 5.1 KiB |
BIN
rectangle4.png
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 7.2 KiB |
94
src/main/java/com/example/demo/ColorRegion.java
Normal file
@ -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;
|
Point crop2 = null;
|
||||||
|
|
||||||
Color col = new Color(img.getRGB(0, 0));
|
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;
|
MyRobot.FUTURETONE=true;
|
||||||
boolean done=false;
|
boolean done=false;
|
||||||
for (int x=img.getWidth()-1;x>=img.getWidth()*(7f/8);x--) {
|
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 {
|
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;
|
final int THRESHOLD=1;
|
||||||
float lowestMatching = Integer.MAX_VALUE;
|
float lowestMatching = Integer.MAX_VALUE;
|
||||||
SongData matchingSong = null;
|
SongData matchingSong = null;
|
||||||
@ -255,45 +260,54 @@ public class Controller {
|
|||||||
Color p2 = song.data[(y*8)+x];
|
Color p2 = song.data[(y*8)+x];
|
||||||
Color p1 = new Color(img.getRGB(x+352, y+288));
|
Color p1 = new Color(img.getRGB(x+352, y+288));
|
||||||
matching+=ImageUtils.distanceToColor(p2,p1);
|
matching+=ImageUtils.distanceToColor(p2,p1);
|
||||||
/*debug.setRGB(x,y,p2.getRGB());
|
if (debugging) {
|
||||||
debug.setRGB(x+8,y,p1.getRGB());*/
|
debug.setRGB(x,y,p2.getRGB());
|
||||||
|
debug.setRGB(x+8,y,p1.getRGB());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matching<lowestMatching) {
|
if (matching<lowestMatching) {
|
||||||
lowestMatching=matching;
|
lowestMatching=matching;
|
||||||
matchingSong = song;
|
matchingSong = song;
|
||||||
}
|
}
|
||||||
|
if (debugging) {
|
||||||
/*try {
|
try {
|
||||||
PrintStream out = new PrintStream(System.out, true, "UTF-8");
|
PrintStream out = new PrintStream(System.out, true, "UTF-8");
|
||||||
out.println("Comparing to "+song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")+": "+matching);
|
out.println("Comparing to "+song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")+": "+matching);
|
||||||
//ImageIO.write(debug,"png",new File("debugcol",song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")));
|
//ImageIO.write(debug,"png",new File("debugcol",song.song.replaceAll("/","").replaceAll("\\*","").replaceAll(":","")));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (SongData song : DemoApplication.songs) {
|
for (SongData song : DemoApplication.songs) {
|
||||||
|
BufferedImage debug = new BufferedImage(16,288,BufferedImage.TYPE_INT_ARGB);
|
||||||
float matching = 0;
|
float matching = 0;
|
||||||
for (int y=0;y<288;y++) {
|
for (int y=0;y<288;y++) {
|
||||||
for (int x=0;x<8;x++) {
|
for (int x=0;x<8;x++) {
|
||||||
Color p2 = song.data[(y*8)+x];
|
Color p2 = song.data[(y*8)+x];
|
||||||
Color p1 = new Color(img.getRGB(x+352, y+288));
|
Color p1 = new Color(img.getRGB(x+352, y+288));
|
||||||
matching+=ImageUtils.distanceToColor(p2,p1);
|
matching+=ImageUtils.distanceToColor(p2,p1);
|
||||||
|
if (debugging) {
|
||||||
|
debug.setRGB(x,y,p2.getRGB());
|
||||||
|
debug.setRGB(x+8,y,p1.getRGB());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (matching<lowestMatching) {
|
if (matching<lowestMatching) {
|
||||||
lowestMatching=matching;
|
lowestMatching=matching;
|
||||||
matchingSong = song;
|
matchingSong = song;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*try {
|
if (debugging) {
|
||||||
PrintStream out = new PrintStream(System.out, true, "UTF-8");
|
try {
|
||||||
out.println("Comparing to "+song.song+": "+matching);
|
PrintStream out = new PrintStream(System.out, true, "UTF-8");
|
||||||
} catch (UnsupportedEncodingException e) {
|
out.println("Comparing to "+song.song+": "+matching);
|
||||||
e.printStackTrace();
|
} catch (UnsupportedEncodingException e) {
|
||||||
}*/
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,9 @@ public class DemoApplication {
|
|||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
SpringApplication.run(DemoApplication.class, args);
|
SpringApplication.run(DemoApplication.class, args);
|
||||||
|
|
||||||
|
File debugFolder = new File("debug");
|
||||||
|
FileUtils.deleteFile(debugFolder);
|
||||||
|
|
||||||
if (REDO_COLOR_DATA) {
|
if (REDO_COLOR_DATA) {
|
||||||
File colordat = new File("colorData");
|
File colordat = new File("colorData");
|
||||||
colordat.delete();
|
colordat.delete();
|
||||||
@ -70,6 +73,8 @@ public class DemoApplication {
|
|||||||
for (String s : str) {
|
for (String s : str) {
|
||||||
FTsongs.add(new SongData(s));
|
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("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);
|
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));
|
img = ImageUtils.toBufferedImage(img.getScaledInstance(1200, 675, Image.SCALE_SMOOTH));
|
||||||
}
|
}
|
||||||
ImageIO.write(img,"png",new File("image.png"));
|
ImageIO.write(img,"png",new File("image.png"));
|
||||||
String song = Controller.getSongTitle(img);
|
String song = Controller.getSongTitle(img,debug);
|
||||||
|
|
||||||
|
|
||||||
song = getCorrectSongName(song);
|
song = getCorrectSongName(song);
|
||||||
|
BIN
test.png
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 1.7 MiB |
BIN
typeface.png
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
BIN
typeface5.png
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 12 KiB |