diff --git a/image.png b/image.png index df79c33..cf91532 100644 Binary files a/image.png and b/image.png differ diff --git a/rectangle0.png b/rectangle0.png index 180836c..cdbdfcf 100644 Binary files a/rectangle0.png and b/rectangle0.png differ diff --git a/rectangle1.png b/rectangle1.png index 3f40967..aac2fe4 100644 Binary files a/rectangle1.png and b/rectangle1.png differ diff --git a/rectangle2.png b/rectangle2.png index ea13f05..fe77f79 100644 Binary files a/rectangle2.png and b/rectangle2.png differ diff --git a/rectangle3.png b/rectangle3.png index 5eb2b2b..c3e51fd 100644 Binary files a/rectangle3.png and b/rectangle3.png differ diff --git a/rectangle4.png b/rectangle4.png index f63c243..1ffc9ae 100644 Binary files a/rectangle4.png and b/rectangle4.png differ diff --git a/src/main/java/com/example/demo/ColorRegion.java b/src/main/java/com/example/demo/ColorRegion.java new file mode 100644 index 0000000..8bcd2db --- /dev/null +++ b/src/main/java/com/example/demo/ColorRegion.java @@ -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.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.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.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(); + } +} diff --git a/src/main/java/com/example/demo/Controller.java b/src/main/java/com/example/demo/Controller.java index f6eb57e..0d74828 100644 --- a/src/main/java/com/example/demo/Controller.java +++ b/src/main/java/com/example/demo/Controller.java @@ -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