Began code for random detection

This commit is contained in:
davpapp 2018-03-05 06:24:11 -05:00
parent af687dedb1
commit d08c9ed936
6 changed files with 54 additions and 30 deletions

View File

@ -25,7 +25,7 @@ public class CameraCalibrator {
randomlyRotateKeyboard();
screenCapture = objectDetector.captureScreenshotGameWindow();
detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor);
detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor);
}
}

View File

@ -46,7 +46,7 @@ public class IronMiner {
public void run() throws Exception {
long startTime = System.currentTimeMillis();
long garbageCollectionTime = System.currentTimeMillis();
long garbageCollectionTime = System.currentTimeMillis() + 60 * 5 * 1000;
int framesWithoutObjects = 0;
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 85) {
@ -103,10 +103,10 @@ public class IronMiner {
// Garbage Collection
if (((System.currentTimeMillis() - garbageCollectionTime) / 1000.0 / 60) > 10) {
if (((System.currentTimeMillis() - garbageCollectionTime) / 1000.0 / 60) > 0) {
System.out.println("Running garbage collection.");
System.gc();
garbageCollectionTime = System.currentTimeMillis() + randomizer.nextGaussianWithinRange(8500, 19340);
garbageCollectionTime = System.currentTimeMillis() + randomizer.nextGaussianWithinRange(8500, 19340) * 60;
}
dropInventoryIfFull();
}
@ -140,32 +140,6 @@ public class IronMiner {
return null;
}
/*private Mat getMatFromBufferedImage(BufferedImage image) {
BufferedImage formattedImage = convertBufferedImage(image, BufferedImage.TYPE_3BYTE_BGR);
byte[] data = ((DataBufferByte) formattedImage.getData().getDataBuffer()).getData();
bgr2rgb(data);
Mat matImage = new Mat(formattedImage.getWidth(), formattedImage.getHeight(), CvType.CV_8UC3);
byte[] pixels = ((DataBufferByte) formattedImage.getRaster().getDataBuffer()).getData();
matImage.put(0, 0, pixels);
return matImage;
}
private static BufferedImage convertBufferedImage(BufferedImage sourceImage, int bufferedImageType) {
BufferedImage image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), bufferedImageType);
Graphics2D g2d = image.createGraphics();
g2d.drawImage(sourceImage, 0, 0, null);
g2d.dispose();
return image;
}
private static void bgr2rgb(byte[] data) {
for (int i = 0; i < data.length; i += 3) {
byte tmp = data[i];
data[i] = data[i + 2];
data[i + 2] = tmp;
}
}*/
public int getDistanceBetweenPoints(Point startingPoint, Point goalPoint) {
return (int) (Math.hypot(goalPoint.x - startingPoint.x, goalPoint.y - startingPoint.y));
}

50
src/RandomDetector.java Normal file
View File

@ -0,0 +1,50 @@
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
public class RandomDetector {
Robot robot;
public RandomDetector() throws AWTException {
robot = new Robot();
}
public void dealWithRandoms(BufferedImage screenCapture) throws AWTException, InterruptedException {
if (isRandomEventPresent(screenCapture)) {
System.out.println("Deal with random here");
}
}
public boolean isRandomEventPresent(BufferedImage screenCapture) throws AWTException, InterruptedException
{
// only do this if it's close to center
boolean foundDialogue = false;
for (int x = 0; x < Constants.GAME_WINDOW_WIDTH; x += 5) {
for (int y = 0; y < Constants.GAME_WINDOW_HEIGHT; y += 1) {
int color = screenCapture.getRGB(x, y);
if (pixelsAreWithinRGBTolerance(color, 10)) {
return true;
}
}
}
return false;
}
private boolean pixelsAreWithinRGBTolerance(int rgb1, int rgb2) {
int[] colors1 = getRGBValuesFromPixel(rgb1);
int[] colors2 = getRGBValuesFromPixel(rgb2);
for (int i = 0; i < 3; i++) {
if (Math.abs(colors1[i] - colors2[i]) > 3) {
return false;
}
}
return true;
}
private int[] getRGBValuesFromPixel(int pixel) {
int[] colors = {(pixel)&0xFF, (pixel>>8)&0xFF, (pixel>>16)&0xFF, (pixel>>24)&0xFF};
return colors;
}
}

Binary file not shown.

Binary file not shown.