improved drop thread

This commit is contained in:
davpapp 2018-03-21 04:56:48 -04:00
parent 8839f97456
commit 381ff01b53
16 changed files with 6398 additions and 21 deletions

1599
hs_err_pid20751.log Normal file

File diff suppressed because it is too large Load Diff

1602
hs_err_pid20788.log Normal file

File diff suppressed because it is too large Load Diff

1594
hs_err_pid20827.log Normal file

File diff suppressed because it is too large Load Diff

1511
hs_err_pid30157.log Normal file

File diff suppressed because it is too large Load Diff

View File

@ -16,13 +16,13 @@ public class CameraCalibrator {
} }
public void rotateUntilObjectFound(ObjectDetector objectDetector, String objectNameToLookFor) throws Exception { public void rotateUntilObjectFound(ObjectDetector objectDetector, String objectNameToLookFor) throws Exception {
BufferedImage screenCapture = objectDetector.captureScreenshotGameWindow(); BufferedImage screenCapture = ImageCapturer.captureScreenshotGameWindow();
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.40); ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.40);
ArrayList<DetectedObject> detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor); ArrayList<DetectedObject> detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor);
while (detectedObjectsToLookFor.size() < targetNumberOfDetectedObjects) { while (detectedObjectsToLookFor.size() < targetNumberOfDetectedObjects) {
randomlyRotateKeyboard(); randomlyRotateKeyboard();
screenCapture = objectDetector.captureScreenshotGameWindow(); screenCapture = ImageCapturer.captureScreenshotGameWindow();
detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.40); detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.40);
detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor); detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor);
} }

View File

@ -178,7 +178,7 @@ public class Cursor {
for (CursorPoint cursorPoint : cursorPathToFollow.getCursorPathPoints()) { for (CursorPoint cursorPoint : cursorPathToFollow.getCursorPathPoints()) {
Point translatedPointToClick = new Point(cursorPoint.x + startingPoint.x, cursorPoint.y + startingPoint.y); Point translatedPointToClick = new Point(cursorPoint.x + startingPoint.x, cursorPoint.y + startingPoint.y);
robotMouseMove(translatedPointToClick); robotMouseMove(translatedPointToClick);
Thread.sleep(cursorPoint.delay); Thread.sleep(Math.abs(cursorPoint.delay));
} }
} }

View File

@ -53,6 +53,18 @@ public class CursorTask {
return clickedCoordinates; return clickedCoordinates;
} }
public Point hoverOverDropOption(Cursor cursor, Point coordinatesToHoverOver, int column) throws Exception {
Point offsetCoordinatesToHoverOver = coordinatesToHoverOver;
if (column < 6) {
offsetCoordinatesToHoverOver.y += DROP_OFFSET;
}
else {
offsetCoordinatesToHoverOver.y = DROP_BOTTOM_ROW;
}
System.out.println("foudn where to click...");
return cursor.moveCursorToCoordinatesWithRandomness(offsetCoordinatesToHoverOver, 13, 2); //(offsetCoordinatesToLeftClick, 13, 10, 6);
}
public Point leftClickDropOption(Cursor cursor, Point coordinatesToLeftClick, int column) throws Exception { public Point leftClickDropOption(Cursor cursor, Point coordinatesToLeftClick, int column) throws Exception {
Point offsetCoordinatesToLeftClick = coordinatesToLeftClick; Point offsetCoordinatesToLeftClick = coordinatesToLeftClick;
if (column < 6) { if (column < 6) {

View File

@ -5,16 +5,20 @@ public class DropperThread implements Runnable {
Thread dropperThread; Thread dropperThread;
Point clickLocation; Point clickLocation;
Cursor cursor; Cursor cursor;
CursorTask cursorTask;
public DropperThread(Point clickLocation, Cursor cursor) { public DropperThread(Point clickLocation, Cursor cursor, CursorTask cursorTask) {
this.clickLocation = clickLocation; this.clickLocation = clickLocation;
this.cursor = cursor; this.cursor = cursor;
this.cursorTask = cursorTask;
} }
@Override @Override
public void run() { public void run() {
try { try {
cursor.moveAndRightlickAtCoordinatesWithRandomness(clickLocation, 15, 15); cursor.moveAndRightlickAtCoordinatesWithRandomness(clickLocation, 15, 8);
Thread.sleep(Randomizer.nextGaussianWithinRange(30, 70));
cursorTask.hoverOverDropOption(cursor, clickLocation, 0);
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();

View File

@ -54,7 +54,9 @@ public class IronMiner {
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
int count = 0; int count = 0;
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 93) { int worldHops = 0;
while (((System.currentTimeMillis() - startTime) / 1000.0 / 60) < 105) {
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,7 +69,7 @@ public class IronMiner {
DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres); DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres);
if (closestIronOre != null) { if (closestIronOre != null) {
Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40)); //Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10); cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
int ironOreInInventory = inventory.getFirstIronOreInInventory(); int ironOreInInventory = inventory.getFirstIronOreInInventory();
@ -79,19 +81,18 @@ public class IronMiner {
int ironOreInInventoryColumn = ironOreInInventory % 7; int ironOreInInventoryColumn = ironOreInInventory % 7;
int ironOreInInventoryRow = ironOreInInventory / 7; int ironOreInInventoryRow = ironOreInInventory / 7;
Point clickLocation = inventory.getClickCoordinatesForInventorySlot(ironOreInInventoryRow, ironOreInInventoryColumn); Point rightClickItemClickLocation = inventory.getClickCoordinatesForInventorySlot(ironOreInInventoryRow, ironOreInInventoryColumn);
TrackerThread trackerThread = new TrackerThread(screenCapture, closestIronOre, objectDetector); TrackerThread trackerThread = new TrackerThread(screenCapture, closestIronOre, objectDetector);
trackerThread.start(); trackerThread.start();
DropperThread dropperThread = new DropperThread(clickLocation, cursor); DropperThread dropperThread = new DropperThread(rightClickItemClickLocation, cursor, cursorTask);
dropperThread.start(); dropperThread.start();
trackerThread.waitTillDone(); trackerThread.waitTillDone();
dropperThread.waitTillDone(); dropperThread.waitTillDone();
Point rightClickLocation = cursor.getCurrentCursorPoint(); cursor.leftClickCursor();
cursorTask.leftClickDropOption(cursor, rightClickLocation, 0);
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") >= numberOfOresInInventoryBefore) { if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") >= numberOfOresInInventoryBefore) {
miningSuccess = true; miningSuccess = true;
@ -111,7 +112,11 @@ public class IronMiner {
System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess); System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
printMiningStats(count, startTime); printMiningStats(count, startTime);
hopWorldsIfMiningSuccessRateIsLow(miningSuccess); boolean worldHopped = hopWorldsIfMiningSuccessRateIsLow(miningSuccess);
if (worldHopped) {
worldHops++;
}
System.out.println("worldHops: " + worldHops);
} }
} }
} }
@ -144,7 +149,7 @@ public class IronMiner {
}*/ }*/
private void dropInventoryIfCloseToFull() throws Exception { private void dropInventoryIfCloseToFull() throws Exception {
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") > 15) { if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") > 12) {
inventory.dropAllItemsOfType("ironOre", cursorTask, cursor); inventory.dropAllItemsOfType("ironOre", cursorTask, cursor);
Thread.sleep(Randomizer.nextGaussianWithinRange(1104, 1651)); Thread.sleep(Randomizer.nextGaussianWithinRange(1104, 1651));
} }

View File

@ -32,12 +32,17 @@ class ObjectTrackerTest {
@Test @Test
void testObjectTrackingWithAllVideosInDirectory() throws Exception { void testObjectTrackingWithAllVideosInDirectory() throws Exception {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
String videoDirectory = "/home/dpapp/Videos/"; String videoDirectory = "/home/dpapp/Videos/";
for (File video : getListOfFilesFromDirectory(videoDirectory)) { //createPresentationGraphics(videoDirectory, "gameplay-2018-03-19_05.50.27.mp4");
createPresentationGraphics(videoDirectory, "mining_guild_inv.mp4");
/*for (File video : getListOfFilesFromDirectory(videoDirectory)) {
if (video.isFile()) { if (video.isFile()) {
testObjectTrackingInVideo(videoDirectory, video.getName()); testObjectTrackingInVideo(videoDirectory, video.getName());
} }
} }*/
} }
public File[] getListOfFilesFromDirectory(String videoDirectoryPath) { public File[] getListOfFilesFromDirectory(String videoDirectoryPath) {
@ -45,6 +50,42 @@ class ObjectTrackerTest {
return videoDirectory.listFiles(); return videoDirectory.listFiles();
} }
void createPresentationGraphics(String videoDirectory, String videoFileName) throws Exception {
VideoCapture video = new VideoCapture(videoDirectory + videoFileName);
ObjectDetector objectDetector = new ObjectDetector();
Mat frame = new Mat();
boolean frameReadSuccess = video.read(frame);
int counter = 0;
while (video.read(frame)) {
counter++;
if (counter % 2 == 0) {
//counter++;
continue;
}
BufferedImage screencapture = Mat2BufferedImage(frame);
Graphics g = screencapture.getGraphics();
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(Mat2BufferedImage(frame), 0.30);
for (DetectedObject detectedObject : detectedObjects) {
Rect2d boundingBox = detectedObject.getBoundingRect2d();
if (objectDetector.isObjectPresentInBoundingBoxInImage(detectedObjects, boundingBox, "ironOre")) {
g.setColor(new Color(0, 255, 0));
}
else if (objectDetector.isObjectPresentInBoundingBoxInImage(detectedObjects, boundingBox, "ore")) {
g.setColor(new Color(255, 0, 0));
}
else {
g.setColor(new Color(255, 255, 255));
}
g.drawRect((int) (boundingBox.x * 735 / 510), (int) boundingBox.y, (int) (boundingBox.width * 685 / 510), (int) boundingBox.height);
}
System.out.println(counter);
ImageIO.write(screencapture, "jpg", new File(videoDirectory + "/mining_guild_inv/frame_" + videoFileName + counter + ".jpg"));
//counter++;
}
}
void testObjectTrackingInVideo(String videoDirectory, String videoFileName) throws Exception { void testObjectTrackingInVideo(String videoDirectory, String videoFileName) throws Exception {
VideoCapture video = new VideoCapture(videoDirectory + videoFileName); VideoCapture video = new VideoCapture(videoDirectory + videoFileName);
@ -69,15 +110,24 @@ class ObjectTrackerTest {
while (video.read(frame)) { while (video.read(frame)) {
BufferedImage screencapture = Mat2BufferedImage(frame); BufferedImage screencapture = Mat2BufferedImage(frame);
//Graphics g = screencapture.getGraphics(); Graphics g = screencapture.getGraphics();
for (int i = 0; i < objectTrackers.size(); i++) { for (int i = 0; i < objectTrackers.size(); i++) {
objectTrackers.get(i).update(frame, boundingBoxes.get(i)); objectTrackers.get(i).update(frame, boundingBoxes.get(i));
boolean trackingSuccess = objectTrackers.get(i).update(frame, boundingBoxes.get(i)); boolean trackingSuccess = objectTrackers.get(i).update(frame, boundingBoxes.get(i));
assertTrue(trackingSuccess); //assertTrue(trackingSuccess);
//g.drawRect((int) boundingBoxes.get(i).x, (int) boundingBoxes.get(i).y, (int) boundingBoxes.get(i).width, (int) boundingBoxes.get(i).height); if (objectDetector.isObjectPresentInBoundingBoxInImage(detectedObjects, boundingBoxes.get(i), "ironOre")) {
g.setColor(new Color(0, 255, 0));
} }
ImageIO.write(screencapture, "jpg", new File(videoDirectory + "/frame_" + videoFileName + counter + ".jpg")); else if (objectDetector.isObjectPresentInBoundingBoxInImage(detectedObjects, boundingBoxes.get(i), "ironOre")) {
g.setColor(new Color(255, 0, 0));
}
else {
g.setColor(new Color(255, 255, 255));
}
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"));
counter++; counter++;
} }
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.