testing required.secondmonitor
After Width: | Height: | Size: 4.9 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.4 KiB |
@ -0,0 +1,43 @@ |
||||
package sig; |
||||
|
||||
import java.awt.AWTException; |
||||
import java.awt.GraphicsDevice; |
||||
import java.awt.Rectangle; |
||||
import java.awt.Robot; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
|
||||
import sig.utils.ImageUtils; |
||||
|
||||
public class CustomRobot extends Robot{ |
||||
|
||||
BufferedImage currentScreen; |
||||
BufferedImage scoreCurrentScreen; |
||||
|
||||
public CustomRobot() throws AWTException { |
||||
super(); |
||||
} |
||||
|
||||
public CustomRobot(GraphicsDevice screen) throws AWTException { |
||||
super(screen); |
||||
} |
||||
|
||||
public void refreshScreen() { |
||||
currentScreen = super.createScreenCapture(new Rectangle(418+18,204+83,912-18,586-83)); |
||||
} |
||||
public void refreshScoreScreen() { |
||||
scoreCurrentScreen = super.createScreenCapture(new Rectangle(418+23,204+85,912-18,586-83)); |
||||
} |
||||
|
||||
public synchronized BufferedImage createScreenCapture(Rectangle r) { |
||||
BufferedImage img2 = ImageUtils.toBufferedImage(currentScreen.getScaledInstance(1227, 690, BufferedImage.SCALE_AREA_AVERAGING)); |
||||
return img2.getSubimage(r.x-418, r.y-204, r.width, r.height); |
||||
} |
||||
public synchronized BufferedImage createNormalScreenCapture(Rectangle r) { |
||||
return currentScreen.getSubimage((int)((r.x-418)*(894d/1227)), (int)((r.y-204)*(503d/690)), (int)Math.ceil(r.width*(894d/1227)), (int)Math.ceil(r.height*(503d/690))); |
||||
//return super.createScreenCapture(new Rectangle(r.x-418,r.y-204,912-18,586-83));
|
||||
} |
||||
} |
@ -0,0 +1,22 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Point; |
||||
|
||||
public class Filter { |
||||
Point red_threshold; |
||||
Point green_threshold; |
||||
Point blue_threshold; |
||||
|
||||
public Filter(Point red_threshold, Point green_threshold, Point blue_threshold) { |
||||
this.red_threshold = red_threshold; |
||||
this.green_threshold = green_threshold; |
||||
this.blue_threshold = blue_threshold; |
||||
} |
||||
|
||||
public boolean isWithinThreshold(Color c) { |
||||
return c.getRed()>=red_threshold.x && c.getRed()<=red_threshold.y && |
||||
c.getGreen()>=green_threshold.x && c.getGreen()<=green_threshold.y && |
||||
c.getBlue()>=blue_threshold.x && c.getBlue()<=blue_threshold.y; |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
package sig; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
public class SongInfo { |
||||
public int id; |
||||
public String name; |
||||
public String romanized_name; |
||||
public String english_name; |
||||
public String artist; |
||||
public String vocaloid; |
||||
public int bpm; |
||||
public String album_art; |
||||
public JSONObject rating; |
||||
public JSONObject notecount; |
||||
|
||||
SongInfo(JSONObject jsonData) { |
||||
id = jsonData.getInt("id"); |
||||
name = jsonData.getString("name"); |
||||
romanized_name = jsonData.getString("romanized_name"); |
||||
english_name = jsonData.getString("english_name"); |
||||
artist = jsonData.getString("artist"); |
||||
vocaloid = jsonData.getString("vocaloid"); |
||||
bpm = jsonData.getInt("bpm"); |
||||
album_art = jsonData.getString("album_art"); |
||||
rating = jsonData.getJSONObject("rating"); |
||||
notecount = jsonData.getJSONObject("notecount"); |
||||
} |
||||
|
||||
public static SongInfo getByTitle(String title) { |
||||
for (SongInfo s : MyRobot.SONGNAMES) { |
||||
if (s.name.equalsIgnoreCase(title)) { |
||||
return s; |
||||
} |
||||
} |
||||
return null; |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
package sig; |
||||
|
||||
import java.awt.AWTException; |
||||
import java.awt.Color; |
||||
import java.awt.Point; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.Arrays; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
|
||||
public class TestMain { |
||||
public static void main(String[] args) throws IOException, AWTException, InterruptedException { |
||||
|
||||
TypeFace2 font = new TypeFace2( |
||||
ImageIO.read(new File("typeface.png")) |
||||
); |
||||
CustomRobot r = new CustomRobot(); |
||||
/*Thread.sleep(3000); |
||||
r.refreshScoreScreen(); |
||||
ImageIO.write(r.scoreCurrentScreen,"png",new File("testimage.png"));*/ |
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage.png"))))); |
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage2.png"))))); |
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage3.png"))))); |
||||
System.out.println(Arrays.toString(font.getAllData(ImageIO.read(new File("testimage4.png"))))); |
||||
} |
||||
} |
@ -0,0 +1,138 @@ |
||||
package sig; |
||||
|
||||
import java.awt.Color; |
||||
import java.awt.Image; |
||||
import java.awt.Point; |
||||
import java.awt.Rectangle; |
||||
import java.awt.image.BufferedImage; |
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
import javax.imageio.ImageIO; |
||||
|
||||
import sig.utils.ImageUtils; |
||||
|
||||
public class TypeFace2 { |
||||
BufferedImage img; |
||||
BufferedImage font; |
||||
int xpointer = 99; |
||||
public static final int THRESHOLD = 30000; |
||||
|
||||
public TypeFace2(BufferedImage font) { |
||||
this.font=font; |
||||
} |
||||
|
||||
public int[] getAllData(BufferedImage img) throws IOException { |
||||
BufferedImage img2 = ImageUtils.toBufferedImage(img.getScaledInstance(1280, 720, Image.SCALE_AREA_AVERAGING)); |
||||
int[] finalNumbers = new int[5]; |
||||
|
||||
Rectangle[] ranges = new Rectangle[] { |
||||
//These coords are in regard to the old screenshot sizes.
|
||||
new Rectangle(866,262,100,20), //33 pixels per line.
|
||||
new Rectangle(866,296,100,20), |
||||
new Rectangle(866,331,100,20), |
||||
new Rectangle(866,366,100,20), |
||||
new Rectangle(866,400,100,20), |
||||
}; |
||||
|
||||
for (int i=0;i<ranges.length;i++) { |
||||
Rectangle r = ranges[i]; |
||||
|
||||
System.out.println("Image "+i+":"); |
||||
File temp = new File("rectangle"+i+".png"); |
||||
ImageIO.write(img2.getSubimage(r.x,r.y,r.width,r.height),"png",temp); |
||||
|
||||
finalNumbers[i]=extractNumbersFromImage(img2.getSubimage( |
||||
r.x,r.y,r.width,r.height),false); |
||||
|
||||
} |
||||
return finalNumbers; |
||||
} |
||||
|
||||
public int extractNumbersFromImage(BufferedImage img) throws IOException { |
||||
return extractNumbersFromImage(img,false); |
||||
} |
||||
|
||||
public int extractNumbersFromImage(BufferedImage img,boolean debug) throws IOException { |
||||
this.img=img; |
||||
File f = null; |
||||
BufferedImage test = null; |
||||
xpointer=99; |
||||
String total = ""; |
||||
while (xpointer>22) { |
||||
int distance = 0; |
||||
int foundIndex = -1; |
||||
//Compare the 22x21 range.
|
||||
for (int i=0;i<10;i++) { |
||||
if (debug) { |
||||
test = new BufferedImage(22,20,BufferedImage.TYPE_INT_ARGB); |
||||
} |
||||
boolean ruleBreak=false; |
||||
|
||||
colorloop: |
||||
for (int x=0;x<22;x++) { |
||||
for (int y=0;y<20;y++) { |
||||
Color fontCol = new Color(font.getRGB(x+i*22,y)); |
||||
Color pixelCol = new Color(img.getRGB(xpointer-22+x+1, y)); |
||||
if (fontCol.equals(Color.RED) && pixelCol.getRed()<150 |
||||
&& pixelCol.getGreen()<150 && pixelCol.getBlue()<150) { |
||||
//Breaks a rule.
|
||||
ruleBreak=true; |
||||
if (!debug) { |
||||
break colorloop; |
||||
} else { |
||||
test.setRGB(x, y, Color.RED.getRGB()); |
||||
} |
||||
} else |
||||
if (fontCol.equals(Color.GREEN) && (pixelCol.getRed()>150 |
||||
|| pixelCol.getGreen()>150 || pixelCol.getBlue()>150)) { |
||||
//Breaks a rule.
|
||||
ruleBreak=true; |
||||
if (!debug) { |
||||
break colorloop; |
||||
} else { |
||||
test.setRGB(x, y, Color.GREEN.getRGB()); |
||||
} |
||||
} else |
||||
if (debug) { |
||||
test.setRGB(x, y, pixelCol.getRGB()); |
||||
} |
||||
} |
||||
} |
||||
if (!ruleBreak) { |
||||
foundIndex=i; |
||||
if (debug) { |
||||
System.out.println("Passes as "+((foundIndex+1)%10)); |
||||
} |
||||
} else |
||||
if (debug) { |
||||
ImageIO.write(test,"png",new File(System.nanoTime()+"_"+((i+1)%10)+".png")); |
||||
} |
||||
} |
||||
if (foundIndex!=-1) { |
||||
//System.out.println(" Closest Match: Index "+((shortestIndex+1)%10)+" ("+shortestDistance+")");
|
||||
if (total.equals("")) { |
||||
total = Integer.toString((foundIndex+1)%10); |
||||
} else { |
||||
total = Integer.toString((foundIndex+1)%10)+total; |
||||
} |
||||
if (debug) { |
||||
System.out.println("Input as "+((foundIndex+1)%10)); |
||||
System.out.println("-------------"); |
||||
} |
||||
xpointer-=22; |
||||
} else { |
||||
//Try shifting the xpointer slowly to the right and try again.
|
||||
xpointer--; |
||||
} |
||||
} |
||||
|
||||
if (total.equals("")) { |
||||
return -1; |
||||
} else { |
||||
return Integer.parseInt(total); |
||||
} |
||||
} |
||||
} |
After Width: | Height: | Size: 544 KiB |
After Width: | Height: | Size: 954 KiB |
After Width: | Height: | Size: 353 KiB |
After Width: | Height: | Size: 324 KiB |
After Width: | Height: | Size: 397 KiB |
After Width: | Height: | Size: 905 KiB |
After Width: | Height: | Size: 775 KiB |
After Width: | Height: | Size: 12 KiB |