Skip to content

Commit

Permalink
Clamp gameImageRoiRect to lowResGameImage correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
efokschaner committed Jan 9, 2016
1 parent 3ab75d0 commit c1eed75
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,28 @@ public GameState getGameStateFromImage(Bitmap b) {
int largestTileWidth = 144;
// buffer selected to add around half a tile of padding around the image.
int buffer = (int) (0.5 * globalScaleFactor * largestTileWidth);
int gameImageRoiRectX = Math.max(tilesBoundingRect.x - buffer, 0);
int gameImageRoiRectY = Math.max(tilesBoundingRect.y - buffer, 0);
final Rect gameImageRoiRect = new Rect(
Math.max(tilesBoundingRect.x - buffer, 0),
Math.max(tilesBoundingRect.y - buffer, 0),
Math.min(tilesBoundingRect.width + 2 * buffer, lowResBinaryGameImage.width() - tilesBoundingRect.x + buffer),
Math.min(tilesBoundingRect.height + 2 * buffer, lowResBinaryGameImage.height() - tilesBoundingRect.y + buffer));
gameImageRoiRectX,
gameImageRoiRectY,
Math.min(tilesBoundingRect.width + 2 * buffer, lowResBinaryGameImage.width() - gameImageRoiRectX),
Math.min(tilesBoundingRect.height + 2 * buffer, lowResBinaryGameImage.height() - gameImageRoiRectY));

final Rect tilesBoundingRectRelativeToGameRoiRect = new Rect(
tilesBoundingRect.x - gameImageRoiRect.x,
tilesBoundingRect.y - gameImageRoiRect.y,
tilesBoundingRect.width,
tilesBoundingRect.height);

if(DEBUG) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}

Mat gameImageRoi = new Mat(lowResBinaryGameImage, gameImageRoiRect);
if (DEBUG) {
Debug.sendMatrix(gameImageRoi);
Expand Down

0 comments on commit c1eed75

Please sign in to comment.