mirror of
https://github.com/davpapp/PowerMiner
synced 2025-01-08 12:28:06 -05:00
Creating new images for testing inventory
This commit is contained in:
parent
343c984d5e
commit
58c9b94f50
@ -1,3 +1,9 @@
|
||||
/*
|
||||
* I made this class when I was trying to do color and feature matching with Haartraining in OpenCV.
|
||||
* I no longer really use this, except for printCursorColor, which also prints the cursor's coordinates.
|
||||
*/
|
||||
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.MouseInfo;
|
||||
|
@ -1,7 +1,18 @@
|
||||
|
||||
public class Constants {
|
||||
public static final int GAME_WINDOW_WIDTH = 1000;
|
||||
public static final int GAME_WINDOW_HEIGHT = 1000;
|
||||
public static final int INVENTORY_WIDTH = 1000;
|
||||
public static final int INVENTORY_HEIGHT = 1000;
|
||||
public static final int GAME_WINDOW_OFFSET_X = 103;
|
||||
public static final int GAME_WINDOW_OFFSET_Y = 85;
|
||||
public static final int GAME_WINDOW_WIDTH = 510;
|
||||
public static final int GAME_WINDOW_HEIGHT = 330;
|
||||
|
||||
|
||||
public static final int INVENTORY_WINDOW_OFFSET_X = 655; //top left corner of inventory, fromm top left corner of screen
|
||||
public static final int INVENTORY_WINDOW_OFFSET_Y = 290;
|
||||
public static final int INVENTORY_WINDOW_WIDTH = 171;
|
||||
public static final int INVENTORY_WINDOW_HEIGHT = 350;
|
||||
public static final int INVENTORY_SLOT_WIDTH = 171 / 4;
|
||||
public static final int INVENTORY_SLOT_HEIGHT = 254 / 7;
|
||||
|
||||
public static final int INVENTORY_NUM_ROWS = 4;
|
||||
public static final int INVENTORY_NUM_COLUMNS = 7;
|
||||
}
|
||||
|
@ -77,9 +77,15 @@ public class ImageCollector {
|
||||
return screenshotOutputDirectory + itemName + "_" + counter + ".jpg";
|
||||
}
|
||||
|
||||
private void generateInventorySlotImages() throws AWTException, IOException {
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.updateAndWriteAllInventorySlotsToImages();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
ImageCollector imageCollector = new ImageCollector("/home/dpapp/Desktop/RunescapeAI/TensorFlow/IronOre/");
|
||||
imageCollector.collectImages("ironOre");
|
||||
//imageCollector.collectImages("ironOre");
|
||||
imageCollector.generateInventorySlotImages();
|
||||
}
|
||||
}
|
||||
|
@ -10,17 +10,6 @@ import javax.imageio.ImageIO;
|
||||
|
||||
public class Inventory {
|
||||
|
||||
public static final int INVENTORY_OFFSET_WIDTH = 655; //top left corner of inventory, fromm top left corner of screen
|
||||
public static final int INVENTORY_OFFSET_HEIGHT = 290;
|
||||
public static final int INVENTORY_WIDTH = 820 - 649;// 820
|
||||
public static final int INVENTORY_HEIGHT = 350; // 530
|
||||
|
||||
private static final int INVENTORY_SLOT_WIDTH = 171 / 4;
|
||||
private static final int INVENTORY_SLOT_HEIGHT = 254 / 7;
|
||||
|
||||
public static final int NUM_ROWS = 4;
|
||||
public static final int NUM_COLUMNS = 7;
|
||||
|
||||
Robot robot;
|
||||
Rectangle inventoryRectangleToCapture;
|
||||
InventorySlot[][] inventorySlots;
|
||||
@ -34,13 +23,13 @@ public class Inventory {
|
||||
}
|
||||
|
||||
private void initializeInventoryRectangle() {
|
||||
inventoryRectangleToCapture = new Rectangle(INVENTORY_OFFSET_WIDTH, INVENTORY_OFFSET_HEIGHT, INVENTORY_WIDTH, INVENTORY_HEIGHT);
|
||||
inventoryRectangleToCapture = new Rectangle(Constants.INVENTORY_WINDOW_OFFSET_X, Constants.INVENTORY_WINDOW_OFFSET_Y, Constants.INVENTORY_WINDOW_WIDTH, Constants.INVENTORY_WINDOW_HEIGHT);
|
||||
}
|
||||
|
||||
private void initializeInventorySlots() {
|
||||
inventorySlots = new InventorySlot[4][7];
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 7; column++) {
|
||||
for (int row = 0; row < Constants.INVENTORY_NUM_ROWS; row++) {
|
||||
for (int column = 0; column < Constants.INVENTORY_NUM_COLUMNS; column++) {
|
||||
inventorySlots[row][column] = new InventorySlot(row, column);
|
||||
}
|
||||
}
|
||||
@ -52,23 +41,26 @@ public class Inventory {
|
||||
|
||||
public void update() throws IOException {
|
||||
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
||||
|
||||
// For test image generation only
|
||||
//ImageIO.write(image, "png", new File(getImageName()));
|
||||
|
||||
updateAllInventorySlots(image);
|
||||
}
|
||||
|
||||
// For testing only
|
||||
public void updateWithFakeImageForTests(BufferedImage testImage) throws IOException {
|
||||
updateAllInventorySlots(testImage);
|
||||
}
|
||||
|
||||
private void updateAllInventorySlots(BufferedImage image) throws IOException {
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 7; column++) {
|
||||
for (int row = 0; row < Constants.INVENTORY_NUM_ROWS; row++) {
|
||||
for (int column = 0; column < Constants.INVENTORY_NUM_COLUMNS; column++) {
|
||||
inventorySlots[row][column].updateInventorySlot(image);
|
||||
//inventorySlots[row][column].writeInventorySlotImage(image, row, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAndWriteAllInventorySlotsToImages() throws IOException {
|
||||
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
||||
writeAllInventorySlotsToImages(image);
|
||||
}
|
||||
|
||||
private void writeAllInventorySlotsToImages(BufferedImage image) throws IOException {
|
||||
for (int row = 0; row < Constants.INVENTORY_NUM_ROWS; row++) {
|
||||
for (int column = 0; column < Constants.INVENTORY_NUM_COLUMNS; column++) {
|
||||
inventorySlots[row][column].writeInventorySlotImage(image, row, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,8 +71,8 @@ public class Inventory {
|
||||
|
||||
public boolean isInventoryFull() {
|
||||
// TODO: this will fail if some unexpected item shows up
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 7; column++) {
|
||||
for (int row = 0; row < Constants.INVENTORY_NUM_ROWS; row++) {
|
||||
for (int column = 0; column < Constants.INVENTORY_NUM_COLUMNS; column++) {
|
||||
if (inventorySlots[row][column].isInventorySlotEmpty(items)) {
|
||||
return false;
|
||||
}
|
||||
@ -91,8 +83,13 @@ public class Inventory {
|
||||
|
||||
public Point getClickCoordinatesForInventorySlot(int row, int column) {
|
||||
Point centerOfInventorySlot = inventorySlots[row][column].getClickablePointWithinItemSlot();
|
||||
int x = INVENTORY_OFFSET_WIDTH + row * INVENTORY_SLOT_WIDTH + centerOfInventorySlot.x;
|
||||
int y = INVENTORY_OFFSET_HEIGHT + column * INVENTORY_SLOT_HEIGHT + centerOfInventorySlot.y;
|
||||
int x = Constants.INVENTORY_WINDOW_OFFSET_X + row * Constants.INVENTORY_SLOT_WIDTH + centerOfInventorySlot.x;
|
||||
int y = Constants.INVENTORY_WINDOW_OFFSET_Y + column * Constants.INVENTORY_SLOT_HEIGHT + centerOfInventorySlot.y;
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
// For testing only
|
||||
public void updateWithFakeImageForTests(BufferedImage testImage) throws IOException {
|
||||
updateAllInventorySlots(testImage);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ class InventoryItemsTest {
|
||||
String testingItemDirectoryPath;
|
||||
|
||||
public void initialize() throws IOException {
|
||||
System.out.println("running initialize...");
|
||||
items = new InventoryItems("/home/dpapp/Desktop/RunescapeAI/Items/");
|
||||
this.testingItemDirectoryPath = "/home/dpapp/Desktop/RunescapeAI/Tests/ItemNameRecognition/";
|
||||
}
|
||||
|
@ -39,13 +39,14 @@ public class InventorySlot {
|
||||
}
|
||||
|
||||
// For test image generation only
|
||||
/*public void writeInventorySlotImage(BufferedImage image, int row, int column) throws IOException {
|
||||
public void writeInventorySlotImage(BufferedImage image, int row, int column) throws IOException {
|
||||
System.out.println("Written inventory slot image...");
|
||||
updateInventorySlot(image);
|
||||
ImageIO.write(this.inventorySlotImage, "png", new File(getImageName(row, column)));
|
||||
}
|
||||
|
||||
// For test image generation only
|
||||
private String getImageName(int row, int column) {
|
||||
return ("/home/dpapp/Desktop/RunescapeAIPics/InventorySlots/inventorySlot_" + row + "_" + column + ".png");
|
||||
}*/
|
||||
return ("/home/dpapp/Desktop/RunescapeAI/InventorySlots/inventorySlot_" + row + "_" + column + ".png");
|
||||
}
|
||||
}
|
||||
|
@ -35,9 +35,24 @@ class InventoryTest {
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
String[][] expectedItemNames3 = {{"oakLogs", "willowLogs", "willowLogs", "willowLogs", "oakLogs", "willowLogs", "logs"},
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
String[][] expectedItemNames4 = {{"oakLogs", "willowLogs", "willowLogs", "willowLogs", "oakLogs", "willowLogs", "logs"},
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
String[][] expectedItemNames5 = {{"oakLogs", "willowLogs", "willowLogs", "willowLogs", "oakLogs", "willowLogs", "logs"},
|
||||
{"empty", "oakLogs", "empty", "logs", "willowLogs", "empty", "willowLogs"},
|
||||
{"logs", "empty", "oakLogs", "oakLogs", "empty", "oakLogs", "empty"},
|
||||
{"willowLogs", "empty", "logs", "willowLogs", "empty", "logs", "logs"}};
|
||||
testGetNameInItemInventorySlotHelper("inventory_0.png", expectedItemNames0);
|
||||
testGetNameInItemInventorySlotHelper("inventory_1.png", expectedItemNames1);
|
||||
testGetNameInItemInventorySlotHelper("inventory_2.png", expectedItemNames2);
|
||||
testGetNameInItemInventorySlotHelper("inventory_3.png", expectedItemNames2);
|
||||
testGetNameInItemInventorySlotHelper("inventory_4.png", expectedItemNames2);
|
||||
testGetNameInItemInventorySlotHelper("inventory_5.png", expectedItemNames2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,63 +0,0 @@
|
||||
import java.awt.AWTException;
|
||||
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;
|
||||
|
||||
public class WillowChopper {
|
||||
|
||||
Cursor cursor;
|
||||
CursorTask cursorTask;
|
||||
Inventory inventory;
|
||||
ObjectDetector objectDetector;
|
||||
Robot robot;
|
||||
|
||||
public WillowChopper() throws AWTException, IOException
|
||||
{
|
||||
//cursor = new Cursor();
|
||||
//cursorTask = new CursorTask();
|
||||
inventory = new Inventory();
|
||||
objectDetector = new ObjectDetector();
|
||||
robot = new Robot();
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
System.out.println("Starting ironMiner...");
|
||||
while (true) {
|
||||
String filename = "/home/dpapp/Desktop/RunescapeAI/temp/screenshot.jpg";
|
||||
BufferedImage image = captureScreenshotGameWindow();
|
||||
ImageIO.write(image, "jpg", new File(filename));
|
||||
ArrayList<Point> ironOreLocations = objectDetector.getIronOreLocationsFromImage(filename);
|
||||
System.out.println("--------------------------------\n\n");
|
||||
/*
|
||||
if (character.isCharacterEngaged()) {
|
||||
// DO NOTHING
|
||||
// do things like checking the inventory
|
||||
}
|
||||
else {
|
||||
find closest willow tree
|
||||
chop willow tree
|
||||
}
|
||||
*/
|
||||
/*inventory.update();
|
||||
if (inventory.isInventoryFull()) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
System.out.println("Inventory is full! Dropping...");
|
||||
cursorTask.optimizedDropAllItemsInInventory(cursor, inventory);
|
||||
System.out.println("Dropping took " + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds.");
|
||||
//cursorTask.dropAllItemsInInventory(cursor, inventory);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
private BufferedImage captureScreenshotGameWindow() throws IOException {
|
||||
Rectangle area = new Rectangle(103, 85, 510, 330);
|
||||
return robot.createScreenCapture(area);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user