Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support convert from UpperLeft, Center in BoundingBoxUtils #15

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ private static RectF convertOneBoundingBox(
case BOUNDARIES:
return convertFromBoundaries(values, coordinateType, height, width);
case UPPER_LEFT:
return convertFromUpperLeft(values, coordinateType, height, width);
case CENTER:
// TODO(b/150824448): convertFrom{UpperLeft, Center}
throw new IllegalArgumentException("BoundingBox.Type " + type + " is not yet supported.");
return convertFromCenter(values, coordinateType, height, width);
}
throw new IllegalArgumentException("Cannot recognize BoundingBox.Type " + type);
}
Expand All @@ -197,6 +197,42 @@ private static RectF convertFromBoundaries(
}
}

private static RectF convertFromUpperLeft(
float[] values, CoordinateType coordinateType, int height, int width) {
if (coordinateType == CoordinateType.PIXEL) {
float left = values[0];
float top = values[1];
float w = values[2];
float h = values[3];

return new RectF(
am15h marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: New line here is not needed.

left, top, left+w, top+h);
} else {
return new RectF(
values[0] * width, values[1] * height, (float) width, (float) height);
am15h marked this conversation as resolved.
Show resolved Hide resolved
}
}

private static RectF convertFromCenter(
float[] values, CoordinateType coordinateType, int height, int width) {
if (coordinateType == CoordinateType.PIXEL) {
float centerX = values[0];
float centerY = values[1];
float w = values[2];
float h = values[3];

float left = centerX - w/2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add spaces around operator /.

float top = centerY - h/2;
float right = centerX + w/2;
float bottom = centerX + h/2;

return new RectF(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: New line is not needed.

left, top, right, bottom);
} else {
throw new IllegalArgumentException("BoundingBox.Type Center is not supported with CoordinateType CoordinateType.RATIO");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, it looks like able to be supported - perhaps leave a TODO here if you don't want to put all in one PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will just add it here. Please confirm if with CoordinateType.RATIO, centerX = values[0] * width, centerY = values[1] * height . What will values[2], values[3] depict? (as we will be using height and width from parameters)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xunkai55 Thanks for reviewing, I have made other changes, please check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values[2] and [3] represent the relative width and height of the bounding box. So the height and width of the box should be values[2] * width, or imageWidth as I commented in another thread.

}
}

// Private constructor to prevent initialization.
private BoundingBoxUtil() {}
}