Compare commits
No commits in common. "master" and "old" have entirely different histories.
BIN
cache/-1976272648
vendored
Before Width: | Height: | Size: 4.5 KiB |
BIN
cache/-952931915
vendored
Before Width: | Height: | Size: 38 KiB |
27
d4dj/.classpath
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
23
d4dj/.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>d4dj</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
4
d4dj/.settings/org.eclipse.core.resources.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding/<project>=UTF-8
|
8
d4dj/.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,8 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
4
d4dj/.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 5.0 KiB |
@ -9,6 +9,8 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<name>d4dj</name>
|
||||
<!-- FIXME change it to the project's website -->
|
||||
<url>http://www.example.com</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@ -23,16 +25,16 @@
|
||||
<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>
|
||||
|
||||
|
177
d4dj/src/main/java/d4dj/d4dj/App.java
Normal file
@ -0,0 +1,177 @@
|
||||
package d4dj.d4dj;
|
||||
|
||||
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.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
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 net.sourceforge.tess4j.Tesseract;
|
||||
import net.sourceforge.tess4j.TesseractException;
|
||||
import sig.utils.ImageUtils;
|
||||
class SubmitThread implements Runnable{
|
||||
String name,description,points;
|
||||
int event,rank;
|
||||
|
||||
SubmitThread(String name,String description,String points,int event,int rank) {
|
||||
this.name=name;
|
||||
this.description=description;
|
||||
this.points=points;
|
||||
this.event=event;
|
||||
this.rank=rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
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(7)));
|
||||
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", points));
|
||||
try {
|
||||
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//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(result);
|
||||
instream.close();
|
||||
} catch (UnsupportedOperationException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
/*
|
||||
Tesseract tesseract = new Tesseract();
|
||||
tesseract.setDatapath("C:\\Users\\sigon\\eclipse-workspace\\d4djRankReaderBot\\d4dj\\tessdata");
|
||||
try {
|
||||
tesseract.setLanguage("jpn");
|
||||
//tesseract.setLanguage("eng");
|
||||
String finaldata = tesseract.doOCR(new File("imgtest5.png"));
|
||||
Thread.sleep(500);
|
||||
System.out.println(finaldata);
|
||||
} catch (TesseractException | InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
|
||||
Tesseract tesseract = new Tesseract();
|
||||
tesseract.setTessVariable("tessedit_write_images", "true");
|
||||
tesseract.setDatapath("C:\\Users\\sigon\\eclipse-workspace\\d4djRankReaderBot\\d4dj\\tessdata");
|
||||
|
||||
|
||||
Rectangle[] namepositions = new Rectangle[] {new Rectangle(475,263,316,36),new Rectangle(475,384,316,36),new Rectangle(475,510,316,36),new Rectangle(475,636,316,36)};
|
||||
Rectangle[] descriptions = new Rectangle[] {new Rectangle(475,328,544,36),new Rectangle(475,452,544,36),new Rectangle(475,576,544,36),new Rectangle(475,700,544,36)};
|
||||
Rectangle[] pointpositions = new Rectangle[] {new Rectangle(1042,317,200,34),new Rectangle(1042,442,200,34),new Rectangle(1042,566,200,34),new Rectangle(1042,688,200,34)};
|
||||
Point[] offsets = new Point[] {new Point(0,0),new Point(0,-2),new Point(0,-1),new Point(0,5),new Point(0,20)};
|
||||
|
||||
String[][] namedata = new String[5][4];
|
||||
String[][] descriptiondata = new String[5][4];
|
||||
String[][] pointdata = new String[5][4];
|
||||
|
||||
while (true) {
|
||||
File f = new File("C:\\Users\\sigon\\Pictures\\MEmu Photo\\Screenshots");
|
||||
//System.out.println(Arrays.deepToString(f.listFiles()));
|
||||
|
||||
if (f.listFiles().length==5) {
|
||||
//New files found!
|
||||
|
||||
|
||||
//Grab the first 5 files and try to parse them.
|
||||
File[] list = f.listFiles();
|
||||
for (int i=0;i<5;i++) {
|
||||
try {
|
||||
BufferedImage img = ImageUtils.toBufferedImage(ImageIO.read(list[i]));
|
||||
//ImageIO.write(img,"png",new File("debug/img"+))
|
||||
for (int j=0;j<4;j++) {
|
||||
tesseract.setLanguage("jpn");
|
||||
//ImageIO.write(img.getSubimage(namepositions[j].x+offsets[j].x,namepositions[j].y+offsets[j].y,namepositions[j].width,namepositions[j].height),"png",new File("debug/img"+i+"_"+j+"_0.png"));
|
||||
//ImageIO.write(img.getSubimage(descriptions[j].x+offsets[j].x,descriptions[j].y+offsets[j].y,descriptions[j].width,descriptions[j].height),"png",new File("debug/img"+i+"_"+j+"_1.png"));
|
||||
//ImageIO.write(img.getSubimage(pointpositions[j].x+offsets[j].x,pointpositions[j].y+offsets[j].y,pointpositions[j].width,pointpositions[j].height),"png",new File("debug/img"+i+"_"+j+"_2.png"));
|
||||
String name = tesseract.doOCR(img,new Rectangle(namepositions[j].x+offsets[i].x,namepositions[j].y+offsets[i].y,namepositions[j].width,namepositions[j].height));
|
||||
String description = tesseract.doOCR(img,new Rectangle(descriptions[j].x+offsets[i].x,descriptions[j].y+offsets[i].y,descriptions[j].width,descriptions[j].height));
|
||||
tesseract.setLanguage("eng");
|
||||
String points = tesseract.doOCR(img,new Rectangle(pointpositions[j].x+offsets[i].x,pointpositions[j].y+offsets[i].y,pointpositions[j].width,pointpositions[j].height));
|
||||
|
||||
namedata[i][j]=name;
|
||||
descriptiondata[i][j]=description;
|
||||
pointdata[i][j]=points;
|
||||
}
|
||||
} catch (IOException | TesseractException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (File ff : list) {
|
||||
ff.delete();
|
||||
}
|
||||
|
||||
// Request parameters and other properties.
|
||||
for (int i=0;i<20;i++) {
|
||||
new Thread(
|
||||
new SubmitThread(namedata[i/4][i%4],descriptiondata[i/4][i%4],pointdata[i/4][i%4].replaceAll(" ","").replaceAll("\\.",""),7,i+1))
|
||||
.start();
|
||||
}
|
||||
} else {
|
||||
if (f.listFiles().length>5) {
|
||||
File[] list = f.listFiles();
|
||||
for (File ff : list) {
|
||||
ff.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*System.out.println(Arrays.deepToString(namedata));
|
||||
System.out.println(Arrays.deepToString(descriptiondata));
|
||||
System.out.println(Arrays.deepToString(pointdata));*/
|
||||
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,12 @@
|
||||
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 {
|
||||
/**
|
||||
@ -96,41 +91,4 @@ 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);
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 100 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 200 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |