Class VisionPoint

java.lang.Object
com.codename1.ai.vision.VisionPoint

public final class VisionPoint extends Object

Immutable point in a normalized, top-left-origin coordinate space. X grows right and Y grows down; 0 and 1 correspond to image edges, independent of source pixel dimensions.

toPoint(int, int, int, int) converts one back to pixels for drawing:

public void paint(Graphics g) {
    super.paint(g);
    g.setColor(0xff3b30);
    for (Face face : lastFaces) {
        VisionPoint eye = face.getLandmark(FaceLandmarks.LEFT_EYE);
        if (eye != null) {
            Point p = eye.toPoint(this);
            g.fillArc(p.getX() - 8, p.getY() - 8, 16, 16, 0, 360);
        }
    }
}
  • Constructor Summary

    Constructors
    Constructor
    Description
    VisionPoint(float x, float y)
    Creates a point in the oriented input image's top-left coordinate space.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
     
    float
     
    toPoint(int x, int y, int width, int height)
    Maps this normalized point onto a pixel rectangle.
    Maps this normalized point onto a component's absolute on-screen bounds, which is the coordinate space a paint method draws in.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VisionPoint

      public VisionPoint(float x, float y)
      Creates a point in the oriented input image's top-left coordinate space.
      Parameters:
      x - horizontal coordinate
      y - vertical coordinate
  • Method Details

    • getX

      public float getX()
      Returns:
      horizontal coordinate normalized to the oriented input width
    • getY

      public float getY()
      Returns:
      downward vertical coordinate normalized to input height
    • toPoint

      public Point toPoint(int x, int y, int width, int height)

      Maps this normalized point 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:
      x - left edge of the destination rectangle in pixels
      y - top edge of the destination rectangle in pixels
      width - destination width in pixels
      height - destination height in pixels
      Returns:
      the corresponding pixel position, rounded to the nearest pixel
    • toPoint

      public Point toPoint(Component target)
      Maps this normalized point onto a component's absolute on-screen bounds, which is the coordinate space a paint method draws in.
      Parameters:
      target - component the analyzed image is displayed in
      Returns:
      the corresponding absolute pixel position
      Throws:
      NullPointerException - if target is null