Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class Face
- Object
- Face
Portable face observation.
Euler angles are expressed in degrees. Bounds and landmark points use
the normalized, top-left-origin coordinate space defined by
VisionRect and VisionPoint.
Not every backend fills in every field. getSmilingProbability()
and getTrackingId() return a negative value when the backend does
not expose them – Apple Vision reports neither – and a landmark the
backend could not locate is absent from the map. Test for those rather than
assuming a complete observation.
FaceDetector detector = new FaceDetector();
detector.process(VisionImage.encoded(jpeg)).ready(faces -> {
for (Face face : faces) {
Rectangle box = face.getBounds().toBounds(photoLabel);
if (face.getSmilingProbability() > 0.7f) {
Log.p("smiling face at " + box);
}
}
}).except(error -> Log.e(error));
Constructors
Methods
Inherited methods
Constructor details
Face
public Face(VisionRect bounds, Map<String, VisionPoint> landmarks, float yaw, float pitch, float roll, float smilingProbability, int trackingId)Parameters
boundsVisionRect- face bounds in the oriented image coordinate space
landmarksMap<String, VisionPoint>- named feature points, defensively copied
yawfloat- horizontal Euler angle in degrees
pitchfloat- vertical Euler angle in degrees
rollfloat- in-plane Euler angle in degrees
smilingProbabilityfloat- smile confidence, or a negative value when unavailable
trackingIdint- stable streaming id, or a negative value when unavailable
Face
public Face(VisionRect bounds, Map<String, VisionPoint> landmarks, float yaw, float pitch, float roll, float smilingProbability, int trackingId, VisionMetadata metadata)Parameters
boundsVisionRect- face bounds in the oriented image coordinate space
landmarksMap<String, VisionPoint>- named feature points, defensively copied
yawfloat- horizontal Euler angle in degrees
pitchfloat- vertical Euler angle in degrees
rollfloat- in-plane Euler angle in degrees
smilingProbabilityfloat- smile confidence, or a negative value when unavailable
trackingIdint- stable streaming id, or a negative value when unavailable
metadataVisionMetadata- backend details, or
null
Method details
getBounds
public VisionRect getBounds()Returns
getLandmark
public VisionPoint getLandmark(String name)Looks up one named landmark.
A landmark the backend could not locate is absent rather than present
at a meaningless position, so a null return means “not found in
this face”, not “unsupported”.
Parameters
nameString- one of the
FaceLandmarksconstants
Returns
null when the
backend did not report itgetLandmarks
public Map<String, VisionPoint> getLandmarks()Returns
getYaw
public float getYaw()Returns
getPitch
public float getPitch()Returns
getRoll
public float getRoll()Returns
getSmilingProbability
public float getSmilingProbability()Returns
getTrackingId
public int getTrackingId()Returns
getMetadata
public VisionMetadata getMetadata()Returns
null when manually constructed