Second OCR parsing engine in progress. Next is to add rank cleaning algorithm with reference images

master
Joshua Sigona 3 years ago
parent 13e8547092
commit 8aa6eb7d4a
  1. 1
      apikey
  2. BIN
      d4dj_rankTracker.jar
  3. BIN
      output.png
  4. 27
      pom.xml
  5. BIN
      ranks/1.png
  6. BIN
      ranks/10.png
  7. BIN
      ranks/100.png
  8. BIN
      ranks/1000.png
  9. BIN
      ranks/10000.png
  10. BIN
      ranks/10000_2.png
  11. BIN
      ranks/1000_2.png
  12. BIN
      ranks/100_2.png
  13. BIN
      ranks/10_2.png
  14. BIN
      ranks/11.png
  15. BIN
      ranks/11_2.png
  16. BIN
      ranks/12.png
  17. BIN
      ranks/12_2.png
  18. BIN
      ranks/13.png
  19. BIN
      ranks/13_2.png
  20. BIN
      ranks/14.png
  21. BIN
      ranks/14_2.png
  22. BIN
      ranks/15.png
  23. BIN
      ranks/15_2.png
  24. BIN
      ranks/16.png
  25. BIN
      ranks/16_2.png
  26. BIN
      ranks/17.png
  27. BIN
      ranks/17_2.png
  28. BIN
      ranks/18.png
  29. BIN
      ranks/18_2.png
  30. BIN
      ranks/19.png
  31. BIN
      ranks/19_2.png
  32. BIN
      ranks/1_2.png
  33. BIN
      ranks/2.png
  34. BIN
      ranks/20.png
  35. BIN
      ranks/2000.png
  36. BIN
      ranks/2000_2.png
  37. BIN
      ranks/20_2.png
  38. BIN
      ranks/2_2.png
  39. BIN
      ranks/3.png
  40. BIN
      ranks/3_2.png
  41. BIN
      ranks/4.png
  42. BIN
      ranks/4_2.png
  43. BIN
      ranks/5.png
  44. BIN
      ranks/50.png
  45. BIN
      ranks/500.png
  46. BIN
      ranks/5000.png
  47. BIN
      ranks/5000_2.png
  48. BIN
      ranks/500_2.png
  49. BIN
      ranks/50_2.png
  50. BIN
      ranks/5_2.png
  51. BIN
      ranks/6.png
  52. BIN
      ranks/6_2.png
  53. BIN
      ranks/7.png
  54. BIN
      ranks/7_2.png
  55. BIN
      ranks/8.png
  56. BIN
      ranks/8_2.png
  57. BIN
      ranks/9.png
  58. BIN
      ranks/9_2.png
  59. 580
      src/main/java/d4dj/d4dj/App.java
  60. 542
      src/main/java/d4dj/d4dj/App_old.java
  61. 42
      src/main/java/sig/utils/ImageUtils.java
  62. 58
      src/main/java/sig/utils/WebUtils.java
  63. BIN
      target/classes/com/recognition/software/jdeskew/ImageDeskew$HoughLine.class
  64. BIN
      target/classes/com/recognition/software/jdeskew/ImageDeskew.class
  65. BIN
      target/classes/com/recognition/software/jdeskew/ImageUtil.class
  66. BIN
      target/classes/d4dj/d4dj/Annotation.class
  67. BIN
      target/classes/d4dj/d4dj/App.class
  68. BIN
      target/classes/d4dj/d4dj/App_old.class
  69. BIN
      target/classes/d4dj/d4dj/SubmitThread.class
  70. BIN
      target/classes/org/json/CDL.class
  71. BIN
      target/classes/org/json/Cookie.class
  72. BIN
      target/classes/org/json/CookieList.class
  73. BIN
      target/classes/org/json/HTTP.class
  74. BIN
      target/classes/org/json/HTTPTokener.class
  75. BIN
      target/classes/org/json/JSONArray.class
  76. BIN
      target/classes/org/json/JSONException.class
  77. BIN
      target/classes/org/json/JSONML.class
  78. BIN
      target/classes/org/json/JSONObject$Null.class
  79. BIN
      target/classes/org/json/JSONObject.class
  80. BIN
      target/classes/org/json/JSONPointer$Builder.class
  81. BIN
      target/classes/org/json/JSONPointer.class
  82. BIN
      target/classes/org/json/JSONPointerException.class
  83. BIN
      target/classes/org/json/JSONString.class
  84. BIN
      target/classes/org/json/JSONStringer.class
  85. BIN
      target/classes/org/json/JSONTokener.class
  86. BIN
      target/classes/org/json/JSONWriter.class
  87. BIN
      target/classes/org/json/Property.class
  88. BIN
      target/classes/org/json/XML$1$1.class
  89. BIN
      target/classes/org/json/XML$1.class
  90. BIN
      target/classes/org/json/XML.class
  91. BIN
      target/classes/org/json/XMLTokener.class
  92. BIN
      target/classes/sig/utils/Audio.class
  93. BIN
      target/classes/sig/utils/DebugUtils.class
  94. BIN
      target/classes/sig/utils/DrawUtils.class
  95. BIN
      target/classes/sig/utils/FileUtils.class
  96. BIN
      target/classes/sig/utils/GithubUtils.class
  97. BIN
      target/classes/sig/utils/ImageUtils.class
  98. BIN
      target/classes/sig/utils/JavaUtils.class
  99. BIN
      target/classes/sig/utils/ReflectUtils.class
  100. BIN
      target/classes/sig/utils/SoundUtils.class
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1 @@
PR8LRMV1V0FX

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

@ -9,19 +9,6 @@
<version>0.0.1-SNAPSHOT</version>
<name>d4dj</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>18.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -30,26 +17,22 @@
</properties>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.12</version>
</dependency>
</dependencies>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 965 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 904 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 923 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1000 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 825 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 939 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 775 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 995 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 700 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1021 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 877 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 803 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 902 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 947 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 950 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 946 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 895 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 960 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 819 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 958 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 818 B

@ -1,542 +1,102 @@
package d4dj.d4dj;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.EntityAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Feature.Type;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.protobuf.ByteString;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import sig.utils.FileUtils;
import sig.utils.ImageUtils;
class SubmitThread implements Runnable{
String name,description;
int event,rank,points;
boolean FINAL;
SubmitThread(String name,String description,int points,int event,int rank,boolean FINAL) {
this.name=name;
this.description=description;
this.points=points;
this.event=event;
this.rank=rank;
this.FINAL=FINAL;
}
@Override
public void run() {
System.out.println(rank+": "+name+" ("+description+") - "+points);
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://projectdivar.com/eventsubmit");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("eventid", Integer.toString(event)));
params.add(new BasicNameValuePair("rank", Integer.toString(rank)));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("description", description));
params.add(new BasicNameValuePair("points", Integer.toString(points)));
if (FINAL) {
params.add(new BasicNameValuePair("fin", Boolean.toString(FINAL)));
}
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println("Rank "+rank+": ("+points+")");
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
import sig.utils.WebUtils;
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println("Rank "+rank+": "+result+"("+points+")");
//System.out.println(rank+": "+name+" ("+description+") - "+points);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
}
}
public class App
{
public static Image paragraph/*,paragraph2,paragraph3*/;
final static int EVENT = 20;
public static int[] lastScores = new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public static int[] lastLowerTierScores = new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public static Font myFont = new Font("Serif", Font.BOLD, 26);
public static int[] ranks = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
50,100,500,1000,2000,5000,10000,20000,30000,50000};
public static int[] drawRanks = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
50,100,500,1000,2000,5000,10000,1000,2000,5000,10000,20000,30000,50000};
public static boolean FINAL = false;
public static void main( String[] args ) throws IOException
{
if (args.length>0) {
if (args[0].equalsIgnoreCase("final")) {
FINAL=true;
}
}
Rectangle[] cropPoints1 = {
new Rectangle(305,163,200,23),
new Rectangle(305,262,200,23),
new Rectangle(305,358,200,23),
new Rectangle(305,453,200,23),
new Rectangle(305,550,200,23),
new Rectangle(305,645,200,23),
new Rectangle(305,740,200,23)
};
Rectangle[] cropPoints2 = {
new Rectangle(305,-191,200,23),
new Rectangle(305,-96,200,23),
new Rectangle(305,1,200,23),
new Rectangle(305,95,200,23),
new Rectangle(305,191,200,23),
new Rectangle(305,287,200,23)
};
Rectangle[] cropPoints3 = {
new Rectangle(305,206,200,23),
new Rectangle(305,302,200,23),
new Rectangle(305,398,200,23),
new Rectangle(305,494,200,23),
new Rectangle(305,589,200,23),
new Rectangle(305,686,200,23),
new Rectangle(305,781,200,23)
};
int lastCount=0;
File folder = new File("Screenshots");
File[] list2 = folder.listFiles();
do {
public class App {
public static String APIKEY = "";
public static void main(String[] args) {
if (new File("apikey").exists()) {
APIKEY = FileUtils.readFromFile("apikey")[0];
} else {
System.err.println("API Key file does not exist! It has been created at:");
File f = new File("apikey");
try {
lastCount=list2.length;
Thread.sleep(5000);
} catch (InterruptedException e) {
f.createNewFile();
FileUtils.writetoFile(new String[] {"API key goes here."},"apikey");
} catch (IOException e) {
e.printStackTrace();
}
list2 = folder.listFiles();
} while (list2.length!=lastCount);
for (File fff : list2) {
fff.delete();
System.err.println(" "+f.getAbsolutePath());
System.err.println("Please fill it in then run this program again.");
System.exit(1);
}
paragraph = ImageIO.read(new File("paragraph.png"));
/*paragraph2 = ImageIO.read(new File("paragraph2.png"));
paragraph3 = ImageIO.read(new File("paragraph3.png"));*/
while (true) {
while (true) {
File f = new File("Screenshots");
if (f.listFiles().length==5) {
//New files found!
//Grab the first 5 files and try to parse them.
File[] list = f.listFiles();
try {
Image leaderboard = ImageIO.read(list[0]);
BufferedImage leaderboard2 = ImageIO.read(list[1]);
Image leaderboard3 = ImageIO.read(list[2]);
Image leaderboard4 = ImageIO.read(list[3]);
Image leaderboard5 = ImageIO.read(list[4]);
BufferedImage cropped1 = new BufferedImage(910,42*48,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = cropped1.createGraphics();
//For comments: down by 40, width is 340.
for (int i=0;i<cropPoints1.length;i++) { //1-7
drawData(g,1,leaderboard, 100, (i)*42, 100+200, (i)*42+23, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,2,leaderboard, 320, (i)*42, 320+340, (i)*42+22, cropPoints1[i].x, cropPoints1[i].y+61, cropPoints1[i].x+340, cropPoints1[i].y+84, null);
drawData(g,0,leaderboard, 740, (i)*42, 740+130, (i)*42+24, cropPoints1[i].x+373, cropPoints1[i].y+48, cropPoints1[i].x+488, cropPoints1[i].y+72, null);
}
//start at X 146
//Find R73,G40,B180
//Scroll down until you find R>220,G>220,B>220
//Scroll back up until you find 36,17,77
//That is the Y position you start at.
int MAXTRIES=1000;
int count=0;
int YMarker=145;
while (count++<MAXTRIES) {
Color c = new Color(leaderboard2.getRGB(140, YMarker++));
if (c.getRed()==255&&c.getGreen()==255&&c.getBlue()==255) {
System.out.println("Step 1 - Found! Y:"+(YMarker-1));
break;
}
}count=0;
/*System.out.println("Test");
while (count++<MAXTRIES) {
Color c = new Color(leaderboard2.getRGB(146, YMarker++));
if (c.getRed()>=220&&c.getGreen()>=220&&c.getBlue()>=220) {
System.out.println("Step 2 - Found! Y:"+(YMarker-1));
break;
}
}count=0;
System.out.println("Test");*/
while (count++<MAXTRIES) {
Color c = new Color(leaderboard2.getRGB(140, YMarker--));
if (YMarker<=1) {
break;
}
if (c.getRed()==0&&c.getGreen()==0&&c.getBlue()==0) {
System.out.println("Step 3 - Found! Y:"+(YMarker+1));
break;
}
}count=0;
System.out.println("Test");
int YOFFSET = YMarker+1;
for (int i=0;i<cropPoints2.length;i++) {//8-13
drawData(g,1,leaderboard2,100, (i+7)*42, 100+200, (i+7)*42+23, cropPoints2[i].x, YOFFSET+cropPoints2[i].y, cropPoints2[i].x+cropPoints2[i].width, YOFFSET+cropPoints2[i].y+cropPoints2[i].height, null);
drawData(g,2,leaderboard2, 320, (i+7)*42, 320+340, (i+7)*42+22, cropPoints2[i].x, YOFFSET+cropPoints2[i].y+61, cropPoints2[i].x+340, YOFFSET+cropPoints2[i].y+84, null);
drawData(g,0,leaderboard2, 740, (i+7)*42, 740+130, (i+7)*42+24, cropPoints2[i].x+373, YOFFSET+cropPoints2[i].y+48, cropPoints2[i].x+488, YOFFSET+cropPoints2[i].y+72, null);
}
for (int i=0;i<cropPoints3.length;i++) {//12-20
drawData(g,1,leaderboard3, 100, (i+13)*42, 100+200, (i+13)*42+23, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,2,leaderboard3, 320, (i+13)*42, 320+340, (i+13)*42+22, cropPoints3[i].x, cropPoints3[i].y+61, cropPoints3[i].x+340, cropPoints3[i].y+84, null);
drawData(g,0,leaderboard3, 740, (i+13)*42, 740+130, (i+13)*42+24, cropPoints3[i].x+373, cropPoints3[i].y+48, cropPoints3[i].x+488, cropPoints3[i].y+72, null);
}
for (int i=0;i<cropPoints1.length;i++) {//50-10000
drawData(g,1,leaderboard4, 100, (i+20)*42, 100+200, (i+20)*42+23, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,2,leaderboard4, 320, (i+20)*42, 320+340, (i+20)*42+26, cropPoints1[i].x, cropPoints1[i].y+61, cropPoints1[i].x+340, cropPoints1[i].y+84, null);
drawData(g,0,leaderboard4, 740, (i+20)*42, 740+130, (i+20)*42+24, cropPoints1[i].x+373, cropPoints1[i].y+48, cropPoints1[i].x+488, cropPoints1[i].y+72, null);
}
for (int i=0;i<cropPoints3.length;i++) {//10000-50000
drawData(g,1,leaderboard5, 100, (i+27)*42, 100+200, (i+27)*42+23, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,2,leaderboard5, 320, (i+27)*42, 320+340, (i+27)*42+22, cropPoints3[i].x, cropPoints3[i].y+61, cropPoints3[i].x+340, cropPoints3[i].y+84, null);
drawData(g,0,leaderboard5, 740, (i+27)*42, 740+130, (i+27)*42+24, cropPoints3[i].x+373, cropPoints3[i].y+48, cropPoints3[i].x+488, cropPoints3[i].y+72, null);
}
for (int i=0;i<drawRanks.length;i++) {
drawRank(g,drawRanks[i],i*42);
}
ImageIO.write(cropped1,"png",new File("testing_leaderboardnames.png"));
g.dispose();
cropped1.flush();
leaderboard.flush();
leaderboard2.flush();
leaderboard3.flush();
leaderboard4.flush();
leaderboard5.flush();
} catch (Exception e) {
System.out.println(e.getMessage());
}
File[] list3 = f.listFiles();
for (File ff : list3) {
ff.delete();
}
String filePath = "testing_leaderboardnames.png";
try {
detectText(filePath);
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else {
if (f.listFiles().length>5) {
File[] list = f.listFiles();
for (File ff : list) {
ff.delete();
}
}
File[] fileList = f.listFiles();
for (File ff : fileList) {
ParseImage(ff);
ff.delete();
}
try {
Thread.sleep(10000);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private static void drawData(Graphics2D g, int type,Image leaderboard, int i, int j, int k, int l, int x, int y, int m,
int n, ImageObserver object) {
switch (type) {
case 0:{
//g.drawImage(paragraph, 0, j, 18, l, 0, 0, 18, 23, object);
}break;
case 1:{
//g.drawImage(paragraph, 2, j, 20, l, 0, 0, 18, 23, object);
}break;
case 2:{
///g.drawImage(paragraph, i-18, j, i, l, 0, 0, 18, 23, object);
}break;
}
g.drawImage(leaderboard, i, j, k, l, x, y, m, n, object);
}
}
private static void drawRank(Graphics2D g,int number,int y) {
g.setFont(myFont);
g.setColor(Color.BLACK);
String numb=Integer.toString(number);
for (int i=0;i<5-Integer.toString(number).length();i++) {
numb="0"+numb;
}
g.drawString(numb,0,y+24);
}
// Detects text in the specified image.
public static void detectText(String filePath) throws IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
com.google.cloud.vision.v1.Image img = com.google.cloud.vision.v1.Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Feature.Type.TEXT_DETECTION).build();
AnnotateImageRequest request =
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
StringBuilder reader = new StringBuilder();
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.format("Error: %s%n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
reader.append(annotation.getDescription());
//System.out.format("Position : %s%n", annotation.getBoundingPoly());
break;
//System.out.println(annotation.getDescription());
//System.out.format("Text: %s%n", annotation.getDescription());
}
}
client.close();
}
System.out.println(reader);
String[] s = reader.toString().split("\n");
int count=0;
int rankIndex=0;
String[] orderedRanks= new String[] {
"00001","00002","00003","00004","00005","00006","00007","00008","00009","00010",
"00011","00012","00013","00014","00015","00016","00017","00018","00019","00020",
"00050","00100","00500","01000","02000","05000","10000","20000","30000","50000"
};
int[] dupData = new int[] {
-1,-1,-1,-1,-1
}; //Contains specifically 5k,10k,20k,30k,and 50k data.
System.out.println(count+"/"+s.length);
while (count<s.length) {
if (s[count].equalsIgnoreCase(orderedRanks[rankIndex])) {
List<String> mydata = new ArrayList<String>();
count++;
mydata.add(orderedRanks[rankIndex]);
int rank = Integer.parseInt(orderedRanks[rankIndex]);
while (count<s.length) {
String nextRank=(rankIndex+1<orderedRanks.length)?orderedRanks[rankIndex+1]:"FDAJIVOAJVIAJJQ";
if (s[count].equalsIgnoreCase(nextRank)) {
break;
}
if (rank==30000&&s[count].equalsIgnoreCase("00100")) {
break;
}
mydata.add(s[count++]);
}
System.out.println("Data: "+mydata);
if (mydata.size()==4&&StringUtils.isNumeric(mydata.get(3))) {
new Thread(
new SubmitThread(mydata.get(1),mydata.get(2),Integer.parseInt(mydata.get(3)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==4&&StringUtils.isNumeric(mydata.get(2))) {
new Thread(
new SubmitThread(mydata.get(3),mydata.get(1),Integer.parseInt(mydata.get(2)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==3&&StringUtils.isNumeric(mydata.get(2))) {
new Thread(
new SubmitThread(mydata.get(1),"MuniMuni",Integer.parseInt(mydata.get(2)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==3&&StringUtils.isNumeric(mydata.get(1))) {
new Thread(
new SubmitThread(mydata.get(2),"MuniMuni",Integer.parseInt(mydata.get(1)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==2&&StringUtils.isNumeric(mydata.get(1))) {
new Thread(
new SubmitThread("Muni","MuniMuni",Integer.parseInt(mydata.get(1)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()>4) {
int marker=1;
boolean foundName=false;
boolean foundDesc=false;
boolean foundPoints=false;
String name = "";
String desc = "";
int points = 0;
boolean submitted=false;
while (marker<mydata.size()) {
if (!foundName&&mydata.get(marker).length()>0) {
foundName=true;
name = mydata.get(marker);
} else
if (!foundDesc&&mydata.get(marker).length()>0) {
foundDesc=true;
desc = mydata.get(marker);
} else
if (!foundPoints&&StringUtils.isNumeric(mydata.get(marker))&&mydata.get(marker).length()>0) {
foundPoints=true;
points = Integer.parseInt(mydata.get(marker));
}
marker++;
}
if (foundName&&foundDesc&&foundPoints) {
new Thread(
new SubmitThread(name,desc,points,EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
submitted=true;
} else
{
System.out.println("Could not make a template from this: "+mydata);
System.out.println("Name:"+foundName+"-"+name+", Description:"+foundDesc+"-"+desc+", Points:"+foundPoints+"-"+points);
}
} else {
System.out.println("Could not find a suitable format for:"+mydata);
}
rankIndex++;
} else {
count++;
}
}
/*System.out.println(scores);
System.out.println(names);
System.out.println(descriptions);*/
/*
for (int i=0;i<data.length;i++) {
//System.out.print(data[i].length()+",");
if (data[i].length()>0) {
if (scores.size()<)
}
}*/
//System.out.println(Arrays.toString(t20scores));
//System.out.println(Arrays.toString(tempLowerTierScores));
//Lower tier order is: 50,100,500,1000,2000,5000,10000,20000,30000,50000
/*
if (!error1) {
for (int i=0;i<20;i++) {
new Thread(
new SubmitThread(t20names[i],t20desc[i],t20scores[i],EVENT,i+1))
.start();
}
} else {
System.out.println("Cannot submit t20 scores. Invalid array params.");
}
int[] ranks = new int[] {50,100,500,1000,2000,5000,10000,20000,30000,50000};
if (!error2) {
for (int j=0;j<10;j++) {
try {
//if (j>=1&&j<9&&Integer.parseInt(lowerTierScores[j])>Integer.parseInt(lowerTierScores[j+1])&&Integer.parseInt(lowerTierScores[j])<Integer.parseInt(lowerTierScores[j+1])) {
new Thread(
new SubmitThread(lowerTierNames[j],lowerTierDesc[j],lowerTierScores[j],EVENT,ranks[j]))
.start();
//}
} catch (Exception e) {
System.out.println("Cannot parse score for rank "+ranks[j]+".");
}
}
} else {
System.out.println("Cannot submit lower tier scores. Invalid array params.");
}
*/
}
private static void AddScore(List<Integer> scores, int[] ranks, String ss) {
if (scores.size()>20) {
//See if this score is already in list.
if (StringUtils.isNumeric(ss)) {
int thisScore = Integer.parseInt(ss);
boolean found=false;
for (int i=0;i<scores.size();i++) {
if (thisScore==scores.get(i)) {
found=true;
break;
}
private static void ParseImage(File ff) {
int pointerX=108;
int pointerY=160;
int counter=0;
try {
BufferedImage leaderboard = ImageIO.read(ff);
BufferedImage template = new BufferedImage(2400,60*7,BufferedImage.TYPE_INT_RGB);
template.getGraphics().setColor(Color.WHITE);
template.getGraphics().fillRect(0, 0, 2400, 60*7);
boolean foundPurple = false;
for (pointerY=230;pointerY<900;pointerY++) {
Color c = new Color(leaderboard.getRGB(pointerX, pointerY));
if (c.getRed()>130&&c.getGreen()>=50&&c.getGreen()<=140&&c.getBlue()>=190&&c.getBlue()>130) {
foundPurple=true;
}
if (StringUtils.isNumeric(ss)) {
if (!found&&scores.size()<ranks.length) {
scores.add(thisScore);
if (foundPurple&&c.getRed()<=10&&c.getGreen()<=10&&c.getBlue()<=10) {
for (int i=0;i<7;i++) {
BufferedImage rank = ImageUtils.removeBrightPixels(ImageUtils.invertImage(ImageUtils.deepCopy(leaderboard).getSubimage(pointerX,pointerY-60,105,40)),400);
Image name = ImageUtils.removeBrightPixels(ImageUtils.invertImage(ImageUtils.deepCopy(leaderboard).getSubimage(306,pointerY-85,200,20)),400).getScaledInstance(-1, 40, Image.SCALE_SMOOTH);
Image desc = ImageUtils.removeBrightPixels(ImageUtils.invertImage(ImageUtils.deepCopy(leaderboard).getSubimage(306,pointerY-25,356,20)),200).getScaledInstance(-1, 40, Image.SCALE_SMOOTH);
Image score = ImageUtils.removeBrightPixels(ImageUtils.invertImage(ImageUtils.deepCopy(leaderboard).getSubimage(677,pointerY-37,118,22)),200).getScaledInstance(-1, 40, Image.SCALE_SMOOTH);
template.getGraphics().drawImage(rank,0,60*counter+5,null);
template.getGraphics().drawImage(name,120,60*counter+5,null);
template.getGraphics().drawImage(desc,540,60*counter+5,null);
template.getGraphics().drawImage(score,1272,60*counter+5,null);
foundPurple=false;
pointerY+=96;
counter++;
}
} else {
scores.add(0);
break;
}
} else {
scores.add(0);
}
} else {
if (StringUtils.isNumeric(ss)) {
scores.add(Integer.parseInt(ss));
} else {
scores.add(0);
if (counter>0) {
template.getGraphics().setColor(Color.BLACK);
for (int i=0;i<7;i++) {
template.getGraphics().clearRect(0,60*i-2,2400,4);
}
template.getGraphics().clearRect(110,0,4,60*7);
template.getGraphics().clearRect(530,0,4,60*7);
template.getGraphics().clearRect(1262,0,4,60*7);
ImageIO.write(template,"png",new File("output.png"));
Map<String,String> values = new HashMap<String,String>();
values.put("language","jpn");
values.put("filetype","PNG");
values.put("isTable","true");
values.put("apikey",APIKEY);
System.out.println(WebUtils.POSTimage("https://apipro1.ocr.space/parse/image", new File("output.png"), values));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,542 @@
package d4dj.d4dj;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import javax.imageio.ImageIO;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.EntityAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Feature.Type;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.protobuf.ByteString;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import sig.utils.ImageUtils;
class SubmitThread implements Runnable{
String name,description;
int event,rank,points;
boolean FINAL;
SubmitThread(String name,String description,int points,int event,int rank,boolean FINAL) {
this.name=name;
this.description=description;
this.points=points;
this.event=event;
this.rank=rank;
this.FINAL=FINAL;
}
@Override
public void run() {
System.out.println(rank+": "+name+" ("+description+") - "+points);
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost("http://projectdivar.com/eventsubmit");
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("eventid", Integer.toString(event)));
params.add(new BasicNameValuePair("rank", Integer.toString(rank)));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("description", description));
params.add(new BasicNameValuePair("points", Integer.toString(points)));
if (FINAL) {
params.add(new BasicNameValuePair("fin", Boolean.toString(FINAL)));
}
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println("Rank "+rank+": ("+points+")");
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream instream = entity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
String result = s.hasNext() ? s.next() : "";
System.out.println("Rank "+rank+": "+result+"("+points+")");
//System.out.println(rank+": "+name+" ("+description+") - "+points);
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
}
}
public class App_old
{
public static Image paragraph/*,paragraph2,paragraph3*/;
final static int EVENT = 20;
public static int[] lastScores = new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public static int[] lastLowerTierScores = new int[]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public static Font myFont = new Font("Serif", Font.BOLD, 26);
public static int[] ranks = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
50,100,500,1000,2000,5000,10000,20000,30000,50000};
public static int[] drawRanks = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
50,100,500,1000,2000,5000,10000,1000,2000,5000,10000,20000,30000,50000};
public static boolean FINAL = false;
public static void main( String[] args ) throws IOException
{
if (args.length>0) {
if (args[0].equalsIgnoreCase("final")) {
FINAL=true;
}
}
Rectangle[] cropPoints1 = {
new Rectangle(305,163,200,23),
new Rectangle(305,262,200,23),
new Rectangle(305,358,200,23),
new Rectangle(305,453,200,23),
new Rectangle(305,550,200,23),
new Rectangle(305,645,200,23),
new Rectangle(305,740,200,23)
};
Rectangle[] cropPoints2 = {
new Rectangle(305,-191,200,23),
new Rectangle(305,-96,200,23),
new Rectangle(305,1,200,23),
new Rectangle(305,95,200,23),
new Rectangle(305,191,200,23),
new Rectangle(305,287,200,23)
};
Rectangle[] cropPoints3 = {
new Rectangle(305,206,200,23),
new Rectangle(305,302,200,23),
new Rectangle(305,398,200,23),
new Rectangle(305,494,200,23),
new Rectangle(305,589,200,23),
new Rectangle(305,686,200,23),
new Rectangle(305,781,200,23)
};
int lastCount=0;
File folder = new File("Screenshots");
File[] list2 = folder.listFiles();
do {
try {
lastCount=list2.length;
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
list2 = folder.listFiles();
} while (list2.length!=lastCount);
for (File fff : list2) {
fff.delete();
}
paragraph = ImageIO.read(new File("paragraph.png"));
/*paragraph2 = ImageIO.read(new File("paragraph2.png"));
paragraph3 = ImageIO.read(new File("paragraph3.png"));*/
while (true) {
File f = new File("Screenshots");
if (f.listFiles().length==5) {
//New files found!
//Grab the first 5 files and try to parse them.
File[] list = f.listFiles();
try {
Image leaderboard = ImageIO.read(list[0]);
BufferedImage leaderboard2 = ImageIO.read(list[1]);
Image leaderboard3 = ImageIO.read(list[2]);
Image leaderboard4 = ImageIO.read(list[3]);
Image leaderboard5 = ImageIO.read(list[4]);
BufferedImage cropped1 = new BufferedImage(910,42*48,BufferedImage.TYPE_INT_ARGB);
Graphics2D g = cropped1.createGraphics();
//For comments: down by 40, width is 340.
for (int i=0;i<cropPoints1.length;i++) { //1-7
drawData(g,1,leaderboard, 100, (i)*42, 100+200, (i)*42+23, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,2,leaderboard, 320, (i)*42, 320+340, (i)*42+22, cropPoints1[i].x, cropPoints1[i].y+61, cropPoints1[i].x+340, cropPoints1[i].y+84, null);
drawData(g,0,leaderboard, 740, (i)*42, 740+130, (i)*42+24, cropPoints1[i].x+373, cropPoints1[i].y+48, cropPoints1[i].x+488, cropPoints1[i].y+72, null);
}
//start at X 146
//Find R73,G40,B180
//Scroll down until you find R>220,G>220,B>220
//Scroll back up until you find 36,17,77
//That is the Y position you start at.
int MAXTRIES=1000;
int count=0;
int YMarker=145;
while (count++<MAXTRIES) {
Color c = new Color(leaderboard2.getRGB(140, YMarker++));
if (c.getRed()==255&&c.getGreen()==255&&c.getBlue()==255) {
System.out.println("Step 1 - Found! Y:"+(YMarker-1));
break;
}
}count=0;
/*System.out.println("Test");
while (count++<MAXTRIES) {
Color c = new Color(leaderboard2.getRGB(146, YMarker++));
if (c.getRed()>=220&&c.getGreen()>=220&&c.getBlue()>=220) {
System.out.println("Step 2 - Found! Y:"+(YMarker-1));
break;
}
}count=0;
System.out.println("Test");*/
while (count++<MAXTRIES) {
Color c = new Color(leaderboard2.getRGB(140, YMarker--));
if (YMarker<=1) {
break;
}
if (c.getRed()==0&&c.getGreen()==0&&c.getBlue()==0) {
System.out.println("Step 3 - Found! Y:"+(YMarker+1));
break;
}
}count=0;
System.out.println("Test");
int YOFFSET = YMarker+1;
for (int i=0;i<cropPoints2.length;i++) {//8-13
drawData(g,1,leaderboard2,100, (i+7)*42, 100+200, (i+7)*42+23, cropPoints2[i].x, YOFFSET+cropPoints2[i].y, cropPoints2[i].x+cropPoints2[i].width, YOFFSET+cropPoints2[i].y+cropPoints2[i].height, null);
drawData(g,2,leaderboard2, 320, (i+7)*42, 320+340, (i+7)*42+22, cropPoints2[i].x, YOFFSET+cropPoints2[i].y+61, cropPoints2[i].x+340, YOFFSET+cropPoints2[i].y+84, null);
drawData(g,0,leaderboard2, 740, (i+7)*42, 740+130, (i+7)*42+24, cropPoints2[i].x+373, YOFFSET+cropPoints2[i].y+48, cropPoints2[i].x+488, YOFFSET+cropPoints2[i].y+72, null);
}
for (int i=0;i<cropPoints3.length;i++) {//12-20
drawData(g,1,leaderboard3, 100, (i+13)*42, 100+200, (i+13)*42+23, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,2,leaderboard3, 320, (i+13)*42, 320+340, (i+13)*42+22, cropPoints3[i].x, cropPoints3[i].y+61, cropPoints3[i].x+340, cropPoints3[i].y+84, null);
drawData(g,0,leaderboard3, 740, (i+13)*42, 740+130, (i+13)*42+24, cropPoints3[i].x+373, cropPoints3[i].y+48, cropPoints3[i].x+488, cropPoints3[i].y+72, null);
}
for (int i=0;i<cropPoints1.length;i++) {//50-10000
drawData(g,1,leaderboard4, 100, (i+20)*42, 100+200, (i+20)*42+23, cropPoints1[i].x, cropPoints1[i].y, cropPoints1[i].x+cropPoints1[i].width, cropPoints1[i].y+cropPoints1[i].height, null);
drawData(g,2,leaderboard4, 320, (i+20)*42, 320+340, (i+20)*42+26, cropPoints1[i].x, cropPoints1[i].y+61, cropPoints1[i].x+340, cropPoints1[i].y+84, null);
drawData(g,0,leaderboard4, 740, (i+20)*42, 740+130, (i+20)*42+24, cropPoints1[i].x+373, cropPoints1[i].y+48, cropPoints1[i].x+488, cropPoints1[i].y+72, null);
}
for (int i=0;i<cropPoints3.length;i++) {//10000-50000
drawData(g,1,leaderboard5, 100, (i+27)*42, 100+200, (i+27)*42+23, cropPoints3[i].x, cropPoints3[i].y, cropPoints3[i].x+cropPoints3[i].width, cropPoints3[i].y+cropPoints3[i].height, null);
drawData(g,2,leaderboard5, 320, (i+27)*42, 320+340, (i+27)*42+22, cropPoints3[i].x, cropPoints3[i].y+61, cropPoints3[i].x+340, cropPoints3[i].y+84, null);
drawData(g,0,leaderboard5, 740, (i+27)*42, 740+130, (i+27)*42+24, cropPoints3[i].x+373, cropPoints3[i].y+48, cropPoints3[i].x+488, cropPoints3[i].y+72, null);
}
for (int i=0;i<drawRanks.length;i++) {
drawRank(g,drawRanks[i],i*42);
}
ImageIO.write(cropped1,"png",new File("testing_leaderboardnames.png"));
g.dispose();
cropped1.flush();
leaderboard.flush();
leaderboard2.flush();
leaderboard3.flush();
leaderboard4.flush();
leaderboard5.flush();
} catch (Exception e) {
System.out.println(e.getMessage());
}
File[] list3 = f.listFiles();
for (File ff : list3) {
ff.delete();
}
String filePath = "testing_leaderboardnames.png";
try {
detectText(filePath);
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else {
if (f.listFiles().length>5) {
File[] list = f.listFiles();
for (File ff : list) {
ff.delete();
}
}
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private static void drawData(Graphics2D g, int type,Image leaderboard, int i, int j, int k, int l, int x, int y, int m,
int n, ImageObserver object) {
switch (type) {
case 0:{
//g.drawImage(paragraph, 0, j, 18, l, 0, 0, 18, 23, object);
}break;
case 1:{
//g.drawImage(paragraph, 2, j, 20, l, 0, 0, 18, 23, object);
}break;
case 2:{
///g.drawImage(paragraph, i-18, j, i, l, 0, 0, 18, 23, object);
}break;
}
g.drawImage(leaderboard, i, j, k, l, x, y, m, n, object);
}
private static void drawRank(Graphics2D g,int number,int y) {
g.setFont(myFont);
g.setColor(Color.BLACK);
String numb=Integer.toString(number);
for (int i=0;i<5-Integer.toString(number).length();i++) {
numb="0"+numb;
}
g.drawString(numb,0,y+24);
}
// Detects text in the specified image.
public static void detectText(String filePath) throws IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ByteString imgBytes = ByteString.readFrom(new FileInputStream(filePath));
com.google.cloud.vision.v1.Image img = com.google.cloud.vision.v1.Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Feature.Type.TEXT_DETECTION).build();
AnnotateImageRequest request =
AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
StringBuilder reader = new StringBuilder();
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.format("Error: %s%n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
for (EntityAnnotation annotation : res.getTextAnnotationsList()) {
reader.append(annotation.getDescription());
//System.out.format("Position : %s%n", annotation.getBoundingPoly());
break;
//System.out.println(annotation.getDescription());
//System.out.format("Text: %s%n", annotation.getDescription());
}
}
client.close();
}
System.out.println(reader);
String[] s = reader.toString().split("\n");
int count=0;
int rankIndex=0;
String[] orderedRanks= new String[] {
"00001","00002","00003","00004","00005","00006","00007","00008","00009","00010",
"00011","00012","00013","00014","00015","00016","00017","00018","00019","00020",
"00050","00100","00500","01000","02000","05000","10000","20000","30000","50000"
};
int[] dupData = new int[] {
-1,-1,-1,-1,-1
}; //Contains specifically 5k,10k,20k,30k,and 50k data.
System.out.println(count+"/"+s.length);
while (count<s.length) {
if (s[count].equalsIgnoreCase(orderedRanks[rankIndex])) {
List<String> mydata = new ArrayList<String>();
count++;
mydata.add(orderedRanks[rankIndex]);
int rank = Integer.parseInt(orderedRanks[rankIndex]);
while (count<s.length) {
String nextRank=(rankIndex+1<orderedRanks.length)?orderedRanks[rankIndex+1]:"FDAJIVOAJVIAJJQ";
if (s[count].equalsIgnoreCase(nextRank)) {
break;
}
if (rank==30000&&s[count].equalsIgnoreCase("00100")) {
break;
}
mydata.add(s[count++]);
}
System.out.println("Data: "+mydata);
if (mydata.size()==4&&StringUtils.isNumeric(mydata.get(3))) {
new Thread(
new SubmitThread(mydata.get(1),mydata.get(2),Integer.parseInt(mydata.get(3)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==4&&StringUtils.isNumeric(mydata.get(2))) {
new Thread(
new SubmitThread(mydata.get(3),mydata.get(1),Integer.parseInt(mydata.get(2)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==3&&StringUtils.isNumeric(mydata.get(2))) {
new Thread(
new SubmitThread(mydata.get(1),"MuniMuni",Integer.parseInt(mydata.get(2)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==3&&StringUtils.isNumeric(mydata.get(1))) {
new Thread(
new SubmitThread(mydata.get(2),"MuniMuni",Integer.parseInt(mydata.get(1)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()==2&&StringUtils.isNumeric(mydata.get(1))) {
new Thread(
new SubmitThread("Muni","MuniMuni",Integer.parseInt(mydata.get(1)),EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
} else
if (mydata.size()>4) {
int marker=1;
boolean foundName=false;
boolean foundDesc=false;
boolean foundPoints=false;
String name = "";
String desc = "";
int points = 0;
boolean submitted=false;
while (marker<mydata.size()) {
if (!foundName&&mydata.get(marker).length()>0) {
foundName=true;
name = mydata.get(marker);
} else
if (!foundDesc&&mydata.get(marker).length()>0) {
foundDesc=true;
desc = mydata.get(marker);
} else
if (!foundPoints&&StringUtils.isNumeric(mydata.get(marker))&&mydata.get(marker).length()>0) {
foundPoints=true;
points = Integer.parseInt(mydata.get(marker));
}
marker++;
}
if (foundName&&foundDesc&&foundPoints) {
new Thread(
new SubmitThread(name,desc,points,EVENT,Integer.parseInt(mydata.get(0)),FINAL))
.start();
submitted=true;
} else
{
System.out.println("Could not make a template from this: "+mydata);
System.out.println("Name:"+foundName+"-"+name+", Description:"+foundDesc+"-"+desc+", Points:"+foundPoints+"-"+points);
}
} else {
System.out.println("Could not find a suitable format for:"+mydata);
}
rankIndex++;
} else {
count++;
}
}
/*System.out.println(scores);
System.out.println(names);
System.out.println(descriptions);*/
/*
for (int i=0;i<data.length;i++) {
//System.out.print(data[i].length()+",");
if (data[i].length()>0) {
if (scores.size()<)
}
}*/
//System.out.println(Arrays.toString(t20scores));
//System.out.println(Arrays.toString(tempLowerTierScores));
//Lower tier order is: 50,100,500,1000,2000,5000,10000,20000,30000,50000
/*
if (!error1) {
for (int i=0;i<20;i++) {
new Thread(
new SubmitThread(t20names[i],t20desc[i],t20scores[i],EVENT,i+1))
.start();
}
} else {
System.out.println("Cannot submit t20 scores. Invalid array params.");
}
int[] ranks = new int[] {50,100,500,1000,2000,5000,10000,20000,30000,50000};
if (!error2) {
for (int j=0;j<10;j++) {
try {
//if (j>=1&&j<9&&Integer.parseInt(lowerTierScores[j])>Integer.parseInt(lowerTierScores[j+1])&&Integer.parseInt(lowerTierScores[j])<Integer.parseInt(lowerTierScores[j+1])) {
new Thread(
new SubmitThread(lowerTierNames[j],lowerTierDesc[j],lowerTierScores[j],EVENT,ranks[j]))
.start();
//}
} catch (Exception e) {
System.out.println("Cannot parse score for rank "+ranks[j]+".");
}
}
} else {
System.out.println("Cannot submit lower tier scores. Invalid array params.");
}
*/
}
private static void AddScore(List<Integer> scores, int[] ranks, String ss) {
if (scores.size()>20) {
//See if this score is already in list.
if (StringUtils.isNumeric(ss)) {
int thisScore = Integer.parseInt(ss);
boolean found=false;
for (int i=0;i<scores.size();i++) {
if (thisScore==scores.get(i)) {
found=true;
break;
}
}
if (StringUtils.isNumeric(ss)) {
if (!found&&scores.size()<ranks.length) {
scores.add(thisScore);
}
} else {
scores.add(0);
}
} else {
scores.add(0);
}
} else {
if (StringUtils.isNumeric(ss)) {
scores.add(Integer.parseInt(ss));
} else {
scores.add(0);
}
}
}
}

@ -1,12 +1,17 @@
package sig.utils;
import java.awt.Color;
import javax.imageio.ImageIO;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
public class ImageUtils {
/**
@ -91,4 +96,41 @@ public class ImageUtils {
public static double distanceToColor(Color p2, Color p1) {
return Math.sqrt(Math.pow(p2.getRed()-p1.getRed(), 2)+Math.pow(p2.getGreen()-p1.getGreen(), 2)+Math.pow(p2.getBlue()-p1.getBlue(), 2));
}
public static BufferedImage invertImage(BufferedImage inputFile) {
for (int x = 0; x < inputFile.getWidth(); x++) {
for (int y = 0; y < inputFile.getHeight(); y++) {
int rgba = inputFile.getRGB(x, y);
Color col = new Color(rgba, true);
col = new Color(255 - col.getRed(),
255 - col.getGreen(),
255 - col.getBlue());
inputFile.setRGB(x, y, col.getRGB());
}
}
return inputFile;
}
public static BufferedImage
removeBrightPixels(BufferedImage inputFile,int threshold) {
for (int x = 0; x < inputFile.getWidth(); x++) {
for (int y = 0; y < inputFile.getHeight(); y++) {
int rgba = inputFile.getRGB(x, y);
Color col = new Color(rgba, true);
if (col.getRed()+col.getGreen()+col.getBlue()>threshold) {
col = new Color(255,
255,
255,0);
inputFile.setRGB(x, y, col.getRGB());
} else {
inputFile.setRGB(x, y, Color.BLACK.getRGB());
}
}
}
return inputFile;
}
public static BufferedImage deepCopy(BufferedImage bi) {
ColorModel cm = bi.getColorModel();
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
WritableRaster raster = bi.copyData(null);
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
}

@ -0,0 +1,58 @@
package sig.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Scanner;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public class WebUtils {
public static String POSTimage(String url,File file,Map<String,String> params) {
String res = "No response.";
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
for (String s : params.keySet()) {
builder.addTextBody(s, params.get(s), ContentType.TEXT_PLAIN);
}
try {
// This attaches the file to the POST:
builder.addBinaryBody(
"file",
new FileInputStream(file),
ContentType.APPLICATION_OCTET_STREAM,
file.getName()
);
HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);
CloseableHttpResponse response;
response = httpClient.execute(uploadFile);
HttpEntity responseEntity = response.getEntity();
Thread.sleep(2000);
String result = "";
if (responseEntity != null) {
try (InputStream instream = responseEntity.getContent()) {
Scanner s = new Scanner(instream).useDelimiter("\\A");
result = s.hasNext() ? s.next() : "";
res=result;
instream.close();
} catch (UnsupportedOperationException | IOException e) {
e.printStackTrace();
}
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
return res;
}
}

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save