Cleaning up code

This commit is contained in:
davpapp 2018-04-14 08:41:07 -04:00
parent 864b2a089a
commit feb3fc7389
14 changed files with 61 additions and 7421 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -62,6 +62,20 @@ public class ImageCollector {
return counter; return counter;
} }
/*public void blurTextFromImages() throws IOException, AWTException, InterruptedException {
File folder = new File("/home/dpapp/Videos/BlurredRandom/NonBlurred/");
File[] listOfImages = folder.listFiles();
//RandomDetector randomDetector = new RandomDetector();
int count = 0;
for (File file : listOfImages) {
System.out.println(count);
BufferedImage image = ImageIO.read(file);
BufferedImage blurredImage = RandomDetector.blurDialogueFromImage(image);
ImageIO.write(blurredImage, "png", new File("/home/dpapp/Videos/BlurredRandom/Blurred/blurredRandom" + count + ".png"));
count++;
}
}*/
private File[] getFilesFromFolderThatStartWith(String itemName) { private File[] getFilesFromFolderThatStartWith(String itemName) {
File folder = new File(screenshotOutputDirectory); File folder = new File(screenshotOutputDirectory);
File[] listOfFiles = folder.listFiles(new FilenameFilter() { File[] listOfFiles = folder.listFiles(new FilenameFilter() {
@ -99,12 +113,13 @@ public class ImageCollector {
inventory.updateAndWriteAllInventoryImages(); inventory.updateAndWriteAllInventoryImages();
} }
/*public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
ImageCollector imageCollector = new ImageCollector("/home/dpapp/Desktop/RunescapeAI/Images/"); ImageCollector imageCollector = new ImageCollector("/home/dpapp/Desktop/RunescapeAI/Images/");
imageCollector.collectImages("chatDialogue"); //imageCollector.blurTextFromImages();
//imageCollector.collectImages("chatDialogue");
//imageCollector.generateInventoryImages(); //imageCollector.generateInventoryImages();
//imageCollector.captureAndSaveFullWindow(); //imageCollector.captureAndSaveFullWindow();
}*/ }
} }

View File

@ -24,7 +24,7 @@ import org.opencv.tracking.TrackerMOSSE;
public class IronMiner { public class IronMiner {
public static final int IRON_ORE_MINING_TIME_MILLISECONDS = 1320; public static final int IRON_ORE_MINING_TIME_MILLISECONDS = 1320;
public static final int MAXIMUM_DISTANCE_TO_WALK_TO_IRON_ORE = 150; public static final int MAXIMUM_DISTANCE_TO_WALK_TO_IRON_ORE = 400;
Cursor cursor; Cursor cursor;
CursorTask cursorTask; CursorTask cursorTask;
@ -56,8 +56,9 @@ public class IronMiner {
int count = 0; int count = 0;
int worldHops = 0; int worldHops = 0;
int lastIronOreInInventory = -1; int lastIronOreInInventory = -1;
int noIronOresCount = 0;
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 195) { while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 163) {
BufferedImage screenCapture = ImageCapturer.captureScreenshotGameWindow(); BufferedImage screenCapture = ImageCapturer.captureScreenshotGameWindow();
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30); ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects); ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
@ -67,17 +68,19 @@ public class IronMiner {
humanBehavior.randomlyRotateCamera(cameraCalibrator); humanBehavior.randomlyRotateCamera(cameraCalibrator);
RandomDetector.dealWithRandoms(screenCapture, cursor); RandomDetector.dealWithRandoms(screenCapture, cursor);
dropInventoryIfCloseToFull(); dropInventoryIfCloseToFull();
/*if (noIronOresCount > 10000) {
return;
}*/
DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres); DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres);
if (closestIronOre != null) { if (closestIronOre != null) {
//Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40)); noIronOresCount = 0;
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10); cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
//System.out.println("Last iron ore: " + lastIronOreInInventory);
int ironOreInInventory = inventory.getFirstIronOreInInventoryDifferentFromLast(lastIronOreInInventory); int ironOreInInventory = inventory.getFirstIronOreInInventoryDifferentFromLast(lastIronOreInInventory);
lastIronOreInInventory = ironOreInInventory; lastIronOreInInventory = ironOreInInventory;
//System.out.println("New iron ore: " + ironOreInInventory + "\n");
int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre"); int numberOfOresInInventoryBefore = inventory.getNumberOfItemsOfTypeInInventory("ironOre");
boolean miningSuccess = false; boolean miningSuccess = false;
@ -120,12 +123,12 @@ public class IronMiner {
boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess); boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
if (worldHopped) { if (worldHopped) {
worldHops++; worldHops++;
/*if (worldHops > 30) {
break;
}*/
} }
System.out.println("worldHops: " + worldHops); System.out.println("worldHops: " + worldHops);
} }
else {
noIronOresCount++;
}
} }
} }

View File

@ -64,7 +64,7 @@ class ObjectTrackerTest {
continue; continue;
} }
BufferedImage screencapture = Mat2BufferedImage(frame); BufferedImage screencapture = Mat2BufferedImage(frame);
Graphics g = screencapture.getGraphics(); Graphics g = screencapture.getGraphics();
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(Mat2BufferedImage(frame), 0.30); ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(Mat2BufferedImage(frame), 0.30);
for (DetectedObject detectedObject : detectedObjects) { for (DetectedObject detectedObject : detectedObjects) {
@ -127,7 +127,7 @@ class ObjectTrackerTest {
} }
g.drawRect((int) boundingBoxes.get(i).x, (int) boundingBoxes.get(i).y, (int) boundingBoxes.get(i).width, (int) boundingBoxes.get(i).height); g.drawRect((int) boundingBoxes.get(i).x, (int) boundingBoxes.get(i).y, (int) boundingBoxes.get(i).width, (int) boundingBoxes.get(i).height);
} }
ImageIO.write(screencapture, "jpg", new File(videoDirectory + "/mining_guild_inv/frame_" + videoFileName + counter + ".jpg")); ImageIO.write(screencapture, "png", new File("/home/dpapp/Videos/BlurredRandom/NonBlurred/" + videoFileName + counter + ".png"));
counter++; counter++;
} }
} }

View File

@ -1,5 +1,6 @@
import java.awt.AWTException; import java.awt.AWTException;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Robot; import java.awt.Robot;
@ -88,6 +89,35 @@ public class RandomDetector {
return null; return null;
} }
/*public static BufferedImage blurDialogueFromImage(BufferedImage screenCapture) throws AWTException, InterruptedException {
Point chatDialogueStart = findChatDialogueCornerPoint(screenCapture);
if (chatDialogueStart == null) {
return screenCapture;
}
int rightMostChatColorPixel = chatDialogueStart.x;
int countSinceLastChatColorPixel = 0;
for (int x = chatDialogueStart.x; x < Constants.GAME_WINDOW_WIDTH && countSinceLastChatColorPixel < 30; x++) {
for (int y = chatDialogueStart.y; y < chatDialogueStart.y + 20; y++) {
int pixelColor = screenCapture.getRGB(x, y);
if (isPixelChatColor(pixelColor)) {
rightMostChatColorPixel = x;
countSinceLastChatColorPixel = 0;
}
}
countSinceLastChatColorPixel++;
}
int chatDialogueBoxWidth = rightMostChatColorPixel - chatDialogueStart.x;
if (chatDialogueBoxWidth > 60 && chatDialogueBoxWidth < 400) {
//BufferedImage result = screenCapture;
Graphics g = screenCapture.getGraphics();
g.clearRect(chatDialogueStart.x, chatDialogueStart.y, chatDialogueBoxWidth, 25);
System.out.println("Found dialogue! Blurring image");
}
return screenCapture;
}*/
private static boolean isSpeakerPointCloseToCharacter(Point speakerPoint) { private static boolean isSpeakerPointCloseToCharacter(Point speakerPoint) {
return (Math.abs(speakerPoint.x + Constants.GAME_WINDOW_OFFSET_X - Constants.CHARACTER_CENTER_X) < 90 && Math.abs(speakerPoint.y + Constants.GAME_WINDOW_OFFSET_Y - Constants.CHARACTER_CENTER_Y) < 80); return (Math.abs(speakerPoint.x + Constants.GAME_WINDOW_OFFSET_X - Constants.CHARACTER_CENTER_X) < 90 && Math.abs(speakerPoint.y + Constants.GAME_WINDOW_OFFSET_Y - Constants.CHARACTER_CENTER_Y) < 80);
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.