Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Commit af846a2

Browse files
author
Severi Haverila
committed
crop functionality fixed
1 parent 2779e47 commit af846a2

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

src/main/java/dtos/ImageLocation.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
public class ImageLocation {
66

7-
public ImageLocation(){}
7+
public ImageLocation(){
8+
this.scaleFactor=1;
9+
this.resizeFactor=1;
10+
}
811

912

1013
public Point getTopLeft() {
@@ -47,6 +50,8 @@ public void setCenter(Point center) {
4750
}
4851

4952
public void divideCoordinatesBy(int i) {
53+
this.scaleFactor=i;
54+
5055
this.topLeft.x = this.topLeft.x/i;
5156
this.topLeft.y = this.topLeft.y/i;
5257

@@ -71,11 +76,23 @@ public double getHeight(){
7176
return this.bottomLeft.y-this.topLeft.y;
7277
}
7378

79+
public int getScaleFactor(){
80+
return this.scaleFactor;
81+
}
82+
83+
public void setResizeFactor(double resizeFactor) {
84+
this.resizeFactor=resizeFactor;
85+
}
86+
public double getResizeFactor(){
87+
return this.resizeFactor;
88+
}
7489

7590

7691
private Point topLeft;
7792
private Point topRight;
7893
private Point bottomLeft;
7994
private Point bottomRight;
8095
private Point center;
96+
private int scaleFactor;
97+
private double resizeFactor;
8198
}

src/main/java/library/AkazeImageFinder.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
public class AkazeImageFinder {
2727

2828
private static final Logger logger = LoggerFactory.getLogger(AkazeImageFinder.class);
29-
double lastResizeFactor; //TODO Severi remove this
3029

3130
public double getSceneHeight(String sceneFile) {
3231
Mat img_scene = Highgui.imread(sceneFile, Highgui.CV_LOAD_IMAGE_UNCHANGED);
@@ -64,9 +63,9 @@ public ImageLocation findImage(String queryImageFile, String sceneFile, double t
6463
Highgui.imwrite(sceneFile, resized_img_scene);
6564
img_scene = Highgui.imread(sceneFile, Highgui.CV_LOAD_IMAGE_UNCHANGED);
6665
logger.info("Image was resized, resize factor is: " + resizeFactor);
67-
lastResizeFactor = resizeFactor;
68-
} else
69-
resizeFactor = 1;
66+
} else{
67+
resizeFactor = 1;
68+
}
7069

7170
String jsonResults = null;
7271
try {
@@ -240,6 +239,7 @@ public ImageLocation findImage(String queryImageFile, String sceneFile, double t
240239
location.setBottomRight(points[2]);
241240
location.setBottomLeft(points[3]);
242241
location.setCenter(centerOriginal);
242+
location.setResizeFactor(resizeFactor);
243243

244244
return location;
245245
}
@@ -250,19 +250,15 @@ public void cropImage(ImageSearchDTO imageDto) {
250250
double width = imageDto.getImageLocation().getWidth();
251251
double height = imageDto.getImageLocation().getHeight();
252252
String scene_filename = imageDto.getScreenshotFile();
253-
254-
log("x: "+x);
255-
log("y: "+y);
256-
log("width:"+width);
257-
log("height: "+height);
258-
log("lastResizeFactor: "+lastResizeFactor);
253+
int scaleFactor = imageDto.getImageLocation().getScaleFactor();
254+
double resizeFactor = imageDto.getImageLocation().getResizeFactor();
259255

260256
Mat img_object = Highgui.imread(scene_filename);
261257

262-
int x_resized = (int) (x / lastResizeFactor);
263-
int y_resized = (int) (y / lastResizeFactor);
264-
int width_resized = (int) (width / lastResizeFactor);
265-
int height_resized = (int) (height / lastResizeFactor);
258+
int x_resized = (int) (x / resizeFactor)*scaleFactor;
259+
int y_resized = (int) (y / resizeFactor)*scaleFactor;
260+
int width_resized = (int) (width / resizeFactor)*scaleFactor;
261+
int height_resized = (int) (height / resizeFactor)*scaleFactor;
266262
Rect croppedRect = new Rect(x_resized, y_resized, width_resized, height_resized);
267263
log(img_object.toString());
268264
log(croppedRect.toString());

src/test/java/AndroidSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void mainPageTest() throws Exception {
5555

5656
AppiumCommons.hideKeyboard(driver);
5757

58-
findImageOnScreen("bitbar_logo.png");
58+
findAndCropImage("test.png");
5959
log("Success.");
6060
}
6161
}

0 commit comments

Comments
 (0)