Class VisionRect
java.lang.Object
com.codename1.ai.vision.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);
}
}
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionVisionRect(float x, float y, float width, float height) Creates a rectangle in the oriented input image's top-left coordinate space. -
Method Summary
Modifier and TypeMethodDescriptionfloatfloatgetWidth()floatgetX()floatgetY()booleanisEmpty()Whether this rectangle carries no geometry, which is what a backend that located a result without reporting where reports.toBounds(int x, int y, int width, int height) Maps this normalized rectangle onto a pixel rectangle.Maps this normalized rectangle onto a component's absolute on-screen bounds, which is the coordinate space apaintmethod draws in.
-
Field Details
-
EMPTY
-
-
Constructor Details
-
VisionRect
public VisionRect(float x, float y, float width, float height) Creates a rectangle in the oriented input image's top-left coordinate space.- Parameters:
x- left coordinatey- top coordinatewidth- non-negative rectangle widthheight- non-negative rectangle height
-
-
Method Details
-
getX
public float getX()- Returns:
- normalized left coordinate
-
getY
public float getY()- Returns:
- normalized top coordinate
-
getWidth
public float getWidth()- Returns:
- width as a fraction of oriented input width
-
getHeight
public float getHeight()- Returns:
- height as a fraction of oriented input height
-
isEmpty
public boolean isEmpty()Whether this rectangle carries no geometry, which is what a backend that located a result without reporting where reports.- Returns:
truewhen the rectangle has no area
-
toBounds
Maps this normalized rectangle onto a pixel rectangle.
The mapping stretches the whole 0..1 range across
widthandheight. 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 withScaleType.CROPdoes not: pass the rectangle the frame actually occupies rather than the component's own bounds.- Parameters:
x- left edge of the destination rectangle in pixelsy- top edge of the destination rectangle in pixelswidth- destination width in pixelsheight- destination height in pixels- Returns:
- the corresponding pixel rectangle, rounded to whole pixels
-
toBounds
Maps this normalized rectangle onto a component's absolute on-screen bounds, which is the coordinate space apaintmethod draws in.- Parameters:
target- component the analyzed image is displayed in- Returns:
- the corresponding absolute pixel rectangle
- Throws:
NullPointerException- iftargetisnull
-