Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class VisionRect
- Object
- VisionRect
Immutable normalized rectangle using a top-left origin. X/Y identify the
upper-left corner and width/height are fractions of the oriented input
dimensions. EMPTY represents unavailable geometry.
toBounds(int, int, int, int) converts one back to pixels for
drawing:
public void paint(Graphics g) {
super.paint(g);
g.setColor(0x34c759);
for (Barcode code : lastCodes) {
Rectangle r = code.getBounds().toBounds(this);
g.drawRect(r.getX(), r.getY(), r.getWidth(), r.getHeight(), 3);
}
}
Fields
public static final VisionRect EMPTY |
Constructors
public VisionRect(float x, float y, float width, float height) | Creates a rectangle in the oriented input image’s top-left coordinate space. |
Methods
public float getX() | |
public float getY() | |
public float getWidth() | |
public float getHeight() | |
public boolean isEmpty() | Whether this rectangle carries no geometry, which is what a backend that located a result without reporting where reports. |
public Rectangle toBounds(int x, int y, int width, int height) | Maps this normalized rectangle onto a pixel rectangle. |
public Rectangle toBounds(Component target) | Maps this normalized rectangle onto a component’s absolute on-screen bounds, which is the coordinate space a paint method draws in. |
Inherited methods
Field details
EMPTY
public static final VisionRect EMPTYConstructor details
VisionRect
public VisionRect(float x, float y, float width, float height)Parameters
xfloat- left coordinate
yfloat- top coordinate
widthfloat- non-negative rectangle width
heightfloat- non-negative rectangle height
Method details
getX
public float getX()Returns
getY
public float getY()Returns
getWidth
public float getWidth()Returns
getHeight
public float getHeight()Returns
isEmpty
public boolean isEmpty()Returns
true when the rectangle has no areatoBounds
public Rectangle toBounds(int x, int y, int width, int height)Maps this normalized rectangle onto a pixel rectangle.
The mapping stretches the whole 0..1 range across width and
height. That is correct when the destination has the same
aspect ratio as the analyzed image, which is the usual case for an
image drawn to fit. A live preview scaled with
ScaleType.CROP does not: pass the
rectangle the frame actually occupies rather than the component’s own
bounds.
Parameters
xint- left edge of the destination rectangle in pixels
yint- top edge of the destination rectangle in pixels
widthint- destination width in pixels
heightint- destination height in pixels
Returns
toBounds
public Rectangle toBounds(Component target)paint method draws in.Parameters
targetComponent- component the analyzed image is displayed in
Returns
Throws
NullPointerException- if
targetisnull