mirror of
https://github.com/davpapp/PowerMiner
synced 2024-12-21 23:48:49 -05:00
Working ItemID test
This commit is contained in:
parent
ebe9970ff7
commit
9a436b2324
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/main.class
BIN
bin/main.class
Binary file not shown.
@ -2,8 +2,11 @@ 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 Inventory {
|
||||
|
||||
public static final int INVENTORY_OFFSET_WIDTH = 655; //top left corner of inventory, fromm top left corner of screen
|
||||
@ -45,9 +48,14 @@ public class Inventory {
|
||||
|
||||
public void update() throws IOException {
|
||||
BufferedImage image = robot.createScreenCapture(this.inventoryRectangleToCapture);
|
||||
ImageIO.write(image, "png", new File(getImageName()));
|
||||
updateAllInventorySlots(image);
|
||||
}
|
||||
|
||||
private String getImageName() {
|
||||
return ("/home/dpapp/Desktop/RunescapeAIPics/Tests/Inventory/inventory.png");
|
||||
}
|
||||
|
||||
public void updateWithFakeImageForTests(BufferedImage testImage) throws IOException {
|
||||
updateAllInventorySlots(testImage);
|
||||
}
|
||||
@ -56,6 +64,7 @@ public class Inventory {
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 7; column++) {
|
||||
inventorySlots[row][column].updateInventorySlot(image);
|
||||
//inventorySlots[row][column].writeInventorySlotImage(image, row, column);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -64,7 +73,7 @@ public class Inventory {
|
||||
return inventorySlots[row][column].getItemNameInInventorySlot(items);
|
||||
}
|
||||
|
||||
public boolean isInventoryFull() {
|
||||
/*public boolean isInventoryFull() {
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 7; column++) {
|
||||
if (!inventorySlots[row][column].isInventorySlotEmpty(items)) {
|
||||
@ -73,5 +82,5 @@ public class Inventory {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class InventoryItem {
|
||||
|
||||
public InventoryItem(String itemDirectoryPath, String itemName) throws IOException {
|
||||
initializeImage(itemDirectoryPath, itemName);
|
||||
this.minimumNumberOfMatchingPixels = 100;
|
||||
this.minimumNumberOfMatchingPixels = 200;
|
||||
}
|
||||
|
||||
private void initializeImage(String itemDirectoryPath, String itemName) throws IOException {
|
||||
@ -51,7 +51,7 @@ public class InventoryItem {
|
||||
int[] colors1 = getRGBValuesFromPixel(rgb1);
|
||||
int[] colors2 = getRGBValuesFromPixel(rgb2);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (Math.abs(colors1[i] - colors2[i]) > 5) {
|
||||
if (Math.abs(colors1[i] - colors2[i]) > 3) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -18,20 +18,18 @@ class InventoryItemsTest {
|
||||
|
||||
public void initialize() throws IOException {
|
||||
System.out.println("running initialize...");
|
||||
items = new InventoryItems("/home/dpapp/Desktop/RunescapeAIPics/Tests/Items/");
|
||||
items = new InventoryItems("/home/dpapp/Desktop/RunescapeAIPics/Items/");
|
||||
this.testingItemDirectoryPath = "/home/dpapp/Desktop/RunescapeAIPics/Tests/ItemNameRecognition/";
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNameOfItemFromImage() throws IOException {
|
||||
initialize();
|
||||
|
||||
for (File itemFile : items.getListOfFilesFromItemDirectory(this.testingItemDirectoryPath)) {
|
||||
if (itemFile.isFile()) {
|
||||
BufferedImage itemImage = ImageIO.read(itemFile);
|
||||
String expectedItemName = getItemNameForTest(itemFile.getName());
|
||||
assertEquals(expectedItemName, items.getNameOfItemFromImage(itemImage));
|
||||
System.out.println("Successfully recongized " + itemFile.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,14 +37,14 @@ class InventoryItemsTest {
|
||||
@Test
|
||||
public void testIsImageThisItem() throws IOException {
|
||||
initialize();
|
||||
|
||||
for (File itemFile : items.getListOfFilesFromItemDirectory(this.testingItemDirectoryPath)) {
|
||||
if (itemFile.isFile()) {
|
||||
BufferedImage itemImage = ImageIO.read(itemFile);
|
||||
String expectedItemName = getItemNameForTest(itemFile.getName());
|
||||
if (expectedItemName == "empty") continue;
|
||||
if (expectedItemName.equals("empty")) {
|
||||
continue;
|
||||
}
|
||||
assertTrue(items.isImageThisItem(itemImage, expectedItemName));
|
||||
System.out.println("Successfully recongized " + itemFile.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,13 @@ public class InventorySlot {
|
||||
public boolean isInventorySlotEmpty(InventoryItems items) {
|
||||
return ("empty" == items.getNameOfItemFromImage(this.inventorySlotImage));
|
||||
}
|
||||
|
||||
public void writeInventorySlotImage(BufferedImage image, int row, int column) throws IOException {
|
||||
updateInventorySlot(image);
|
||||
ImageIO.write(this.inventorySlotImage, "png", new File(getImageName(row, column)));
|
||||
}
|
||||
|
||||
private String getImageName(int row, int column) {
|
||||
return ("/home/dpapp/Desktop/RunescapeAIPics/InventorySlots/inventorySlot_" + row + "_" + column + ".png");
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,21 @@ class InventoryTest {
|
||||
public void testGetNameInItemInventorySlot() throws IOException, AWTException {
|
||||
initialize();
|
||||
|
||||
// TODO: add image for uploading custom image to Inventory
|
||||
BufferedImage testImage = loadBufferedImage("inventory_0.png");
|
||||
inventory.updateWithFakeImageForTests(testImage);
|
||||
assertEquals(inventory.getItemNameInInventorySlot(0, 0), "willowLogs");
|
||||
assertEquals(inventory.getItemNameInInventorySlot(3, 6), "empty");
|
||||
String[][] expectedItemNames0 = {{"willowLogs", "oakLogs", "oakLogs", "willowLogs", "willowLogs", "willowLogs", "willowLogs"},
|
||||
{"empty", "empty", "empty", "willowLogs", "willowLogs", "willowLogs", "willowLogs"},
|
||||
{"empty", "willowLogs", "logs", "logs", "empty", "willowLogs", "willowLogs"},
|
||||
{"willowLogs", "willowLogs", "willowLogs", "willowLogs", "willowLogs", "willowLogs", "empty"}};
|
||||
String[][] expectedItemNames1 = {{"oakLogs", "oakLogs", "willowLogs", "willowLogs", "willowLogs", "oakLogs", "logs"},
|
||||
{"empty", "willowLogs", "empty", "willowLogs", "logs", "empty", "logs"},
|
||||
{"oakLogs", "willowLogs", "oakLogs", "oakLogs", "runeAxe", "willowLogs", "willowLogs"},
|
||||
{"willowLogs", "logs", "logs", "oakLogs", "willowLogs", "logs", "empty"}};
|
||||
String[][] expectedItemNames2 = {{"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"}};
|
||||
testInventory("inventory_0.png", expectedItemNames0);
|
||||
testInventory("inventory_1.png", expectedItemNames1);
|
||||
testInventory("inventory_2.png", expectedItemNames2);
|
||||
}
|
||||
|
||||
public BufferedImage loadBufferedImage(String fileName) throws IOException {
|
||||
@ -36,4 +46,15 @@ class InventoryTest {
|
||||
return itemImage;
|
||||
}
|
||||
|
||||
void testInventory(String inventoryFileName, String[][] expectedItemNames) throws IOException {
|
||||
BufferedImage testImage = loadBufferedImage(inventoryFileName);
|
||||
inventory.updateWithFakeImageForTests(testImage);
|
||||
|
||||
for (int row = 0; row < 4; row++) {
|
||||
for (int column = 0; column < 7; column++) {
|
||||
assertEquals(inventory.getItemNameInInventorySlot(row, column), expectedItemNames[row][column]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public class main {
|
||||
//Inventory inventory = new Inventory();
|
||||
//inventory.update();
|
||||
Inventory inventory = new Inventory();
|
||||
inventory.update();
|
||||
//Items items = new Items("/home/dpapp/Desktop/RunescapeAIPics/Items/");
|
||||
//items.displayItems();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user