improved drop thread
This commit is contained in:
parent
8839f97456
commit
381ff01b53
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
|
@ -16,13 +16,13 @@ public class CameraCalibrator {
|
|||
}
|
||||
|
||||
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> detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor);
|
||||
while (detectedObjectsToLookFor.size() < targetNumberOfDetectedObjects) {
|
||||
randomlyRotateKeyboard();
|
||||
screenCapture = objectDetector.captureScreenshotGameWindow();
|
||||
screenCapture = ImageCapturer.captureScreenshotGameWindow();
|
||||
detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.40);
|
||||
detectedObjectsToLookFor = objectDetector.getObjectsOfClassInList(detectedObjects, objectNameToLookFor);
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ public class Cursor {
|
|||
for (CursorPoint cursorPoint : cursorPathToFollow.getCursorPathPoints()) {
|
||||
Point translatedPointToClick = new Point(cursorPoint.x + startingPoint.x, cursorPoint.y + startingPoint.y);
|
||||
robotMouseMove(translatedPointToClick);
|
||||
Thread.sleep(cursorPoint.delay);
|
||||
Thread.sleep(Math.abs(cursorPoint.delay));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,18 @@ public class CursorTask {
|
|||
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 {
|
||||
Point offsetCoordinatesToLeftClick = coordinatesToLeftClick;
|
||||
if (column < 6) {
|
||||
|
|
|
@ -5,16 +5,20 @@ public class DropperThread implements Runnable {
|
|||
Thread dropperThread;
|
||||
Point clickLocation;
|
||||
Cursor cursor;
|
||||
CursorTask cursorTask;
|
||||
|
||||
public DropperThread(Point clickLocation, Cursor cursor) {
|
||||
public DropperThread(Point clickLocation, Cursor cursor, CursorTask cursorTask) {
|
||||
this.clickLocation = clickLocation;
|
||||
this.cursor = cursor;
|
||||
this.cursorTask = cursorTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
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) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -54,7 +54,9 @@ public class IronMiner {
|
|||
long startTime = System.currentTimeMillis();
|
||||
|
||||
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();
|
||||
ArrayList<DetectedObject> detectedObjects = objectDetector.getObjectsInImage(screenCapture, 0.30);
|
||||
ArrayList<DetectedObject> ironOres = objectDetector.getIronOres(detectedObjects);
|
||||
|
@ -67,7 +69,7 @@ public class IronMiner {
|
|||
DetectedObject closestIronOre = getClosestObjectToCharacter(ironOres);
|
||||
|
||||
if (closestIronOre != null) {
|
||||
Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
|
||||
//Thread.sleep(Randomizer.nextGaussianWithinRange(20, 40));
|
||||
cursor.moveAndLeftClickAtCoordinatesWithRandomness(closestIronOre.getCenterForClicking(), 10, 10);
|
||||
|
||||
int ironOreInInventory = inventory.getFirstIronOreInInventory();
|
||||
|
@ -79,19 +81,18 @@ public class IronMiner {
|
|||
int ironOreInInventoryColumn = 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.start();
|
||||
|
||||
DropperThread dropperThread = new DropperThread(clickLocation, cursor);
|
||||
DropperThread dropperThread = new DropperThread(rightClickItemClickLocation, cursor, cursorTask);
|
||||
dropperThread.start();
|
||||
|
||||
trackerThread.waitTillDone();
|
||||
dropperThread.waitTillDone();
|
||||
|
||||
Point rightClickLocation = cursor.getCurrentCursorPoint();
|
||||
cursorTask.leftClickDropOption(cursor, rightClickLocation, 0);
|
||||
cursor.leftClickCursor();
|
||||
|
||||
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") >= numberOfOresInInventoryBefore) {
|
||||
miningSuccess = true;
|
||||
|
@ -111,7 +112,11 @@ public class IronMiner {
|
|||
System.out.println("Ores in inventory: " + numberOfOresInInventoryBefore + ". Mining success? " + miningSuccess);
|
||||
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 {
|
||||
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") > 15) {
|
||||
if (inventory.getNumberOfItemsOfTypeInInventory("ironOre") > 12) {
|
||||
inventory.dropAllItemsOfType("ironOre", cursorTask, cursor);
|
||||
Thread.sleep(Randomizer.nextGaussianWithinRange(1104, 1651));
|
||||
}
|
||||
|
|
|
@ -32,12 +32,17 @@ class ObjectTrackerTest {
|
|||
|
||||
@Test
|
||||
void testObjectTrackingWithAllVideosInDirectory() throws Exception {
|
||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
||||
|
||||
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()) {
|
||||
testObjectTrackingInVideo(videoDirectory, video.getName());
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public File[] getListOfFilesFromDirectory(String videoDirectoryPath) {
|
||||
|
@ -45,6 +50,42 @@ class ObjectTrackerTest {
|
|||
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 {
|
||||
VideoCapture video = new VideoCapture(videoDirectory + videoFileName);
|
||||
|
||||
|
@ -69,15 +110,24 @@ class ObjectTrackerTest {
|
|||
while (video.read(frame)) {
|
||||
BufferedImage screencapture = Mat2BufferedImage(frame);
|
||||
|
||||
//Graphics g = screencapture.getGraphics();
|
||||
Graphics g = screencapture.getGraphics();
|
||||
for (int i = 0; i < objectTrackers.size(); i++) {
|
||||
objectTrackers.get(i).update(frame, boundingBoxes.get(i));
|
||||
boolean trackingSuccess = objectTrackers.get(i).update(frame, boundingBoxes.get(i));
|
||||
assertTrue(trackingSuccess);
|
||||
|
||||
//g.drawRect((int) boundingBoxes.get(i).x, (int) boundingBoxes.get(i).y, (int) boundingBoxes.get(i).width, (int) boundingBoxes.get(i).height);
|
||||
//assertTrue(trackingSuccess);
|
||||
|
||||
if (objectDetector.isObjectPresentInBoundingBoxInImage(detectedObjects, boundingBoxes.get(i), "ironOre")) {
|
||||
g.setColor(new Color(0, 255, 0));
|
||||
}
|
||||
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 + "/frame_" + videoFileName + counter + ".jpg"));
|
||||
ImageIO.write(screencapture, "jpg", new File(videoDirectory + "/mining_guild_inv/frame_" + videoFileName + counter + ".jpg"));
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
|
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