public abstract class FaceKey extends AbstractObjectKey
Modifier and Type | Class and Description |
---|---|
static class |
FaceKey.FaceLandmark
Facial landmark constants
|
Modifier | Constructor and Description |
---|---|
protected |
FaceKey(BinaryInput input,
BinarySerializator serializator)
Creates a new instance of FaceKey loaded from binary input.
|
protected |
FaceKey(java.lang.String locatorURI)
Creates a new FaceKey with the given the locator URI.
|
Modifier and Type | Method and Description |
---|---|
FaceKey |
clone(java.lang.String locatorURI)
Returns a copy of this key with the given locator URI.
|
FaceKey |
clone(java.lang.String locatorURI,
boolean preserveFaceLocatorExcension)
Returns a copy of this key with the given locator URI.
|
java.awt.image.BufferedImage |
drawFaceContour(java.awt.image.BufferedImage image,
int size)
Draws a face contour in the given image.
|
java.awt.Graphics2D |
drawFaceContour(java.awt.Graphics2D g,
int size)
Draws a face contour in the given graphic context.
|
java.awt.image.BufferedImage |
drawFaceLabel(java.awt.image.BufferedImage image,
java.lang.String label)
Draws a given face label at the bottom of the face chin.
|
java.awt.Graphics2D |
drawFaceLabel(java.awt.Graphics2D g,
java.lang.String label)
Draws a given face label at the bottom of the face chin.
|
java.awt.image.BufferedImage |
drawFaceLandmarkPoint(java.awt.image.BufferedImage image,
FaceKey.FaceLandmark landmark,
int size)
Draws a face landmark point in the given image.
|
java.awt.Graphics2D |
drawFaceLandmarkPoint(java.awt.Graphics2D g,
FaceKey.FaceLandmark landmark,
int size)
Draws a face landmark point in the given graphic context.
|
java.awt.image.BufferedImage |
drawFaceLandmarks(java.awt.image.BufferedImage image,
int size)
Draws all face landmark points in the given image.
|
java.awt.image.BufferedImage |
drawFaceOval(java.awt.image.BufferedImage image,
int size)
Draws a face oval in the given image.
|
java.awt.Graphics2D |
drawFaceOval(java.awt.Graphics2D g,
int size)
Draws a face oval in the given graphic context.
|
java.awt.image.BufferedImage |
extractFaceImage(java.awt.image.BufferedImage originalImage,
double enlargementFactor)
Returns the sub-image that contains the face.
|
java.awt.image.BufferedImage |
extractFaceImage(java.io.File imageDir,
double enlargementFactor)
Returns the sub-image that contains the face.
|
void |
extractFaceImage(java.io.File imageDir,
java.io.File destDir,
java.lang.String imageFormatName,
double enlargementFactor)
Extracts the sub-image that contains the face and saves it into a file.
|
java.awt.image.BufferedImage |
extractTransformedFaceImage(java.awt.image.BufferedImage image,
double scale,
double rotation,
java.awt.geom.Point2D rotationCenter,
java.awt.geom.Point2D centerTranslation,
int newWidth,
int newHeight)
Extracts the face image represented by this key from the given image.
|
java.awt.image.BufferedImage |
extractTransformedFaceImageByEyes(java.awt.image.BufferedImage image,
java.awt.geom.Point2D newLeftEyePos,
int newWidth,
int newHeight)
Extracts the face image represented by this key from the given image.
|
java.awt.image.BufferedImage |
extractTransformedFaceImageByPos(java.awt.image.BufferedImage image,
java.awt.geom.Point2D leftEye,
int newWidth,
int newHeight)
Extracts the face image represented by this key from the given image.
|
abstract int |
getCenterX()
Returns the x-coordinate (in pixels) of the face center point
in the
source image . |
abstract int |
getCenterY()
Returns the y-coordinate (in pixels) of the face center point
in the
source image . |
abstract java.awt.Shape |
getContour()
Returns the face contour in the
source image . |
java.lang.String |
getFaceIdentifierLocatorURI()
Returns the face identifier from the locatorURI as specified by the respective face key implementation.
|
abstract int |
getHeight()
Returns the face height in pixels in the
source image . |
float |
getHeightNormalizationFactor()
Returns the normalization factor for face height.
|
abstract java.awt.geom.Point2D |
getLandmarkPosition(FaceKey.FaceLandmark landmark)
Returns the position of the given face landmark.
|
abstract float |
getRollAngle()
Returns the face roll angle in degrees in the
source image . |
java.lang.String |
getSourceImageLocatorURI()
Returns the locator URI of the source image this face was extracted from.
|
abstract int |
getWidth()
Returns the face width in pixels in the
source image . |
float |
getWidthNormalizationFactor()
Returns the normalization factor for face width.
|
abstract float |
getYawAngle()
Returns the face yaw angle in degrees in the
source image . |
boolean |
intersect(FaceKey otherFaceKey,
double threshold)
Returns whether this face key has an intersection with the given face key.
|
protected static java.awt.Rectangle |
intersectRectWithImage(java.awt.image.BufferedImage image,
java.awt.Rectangle rect)
Returns the intersection of the image rectangle (i.e. its width and height)
with the given rectangle.
|
java.awt.image.BufferedImage |
loadFaceImage(java.io.File imageDir)
Loads the original image where the this face key was detected.
|
void |
saveFaceImage(java.awt.image.BufferedImage image,
java.lang.String imageFormatName,
java.io.File destDir)
Saves the given image into the
destDir as a file named
by the locator of this key. |
binarySerialize, compareTo, create, equals, getBinarySize, getKeyStringPart, getLocatorURI, hashCode, toString, write, writeData
protected FaceKey(java.lang.String locatorURI)
locatorURI
- the face image locator URIprotected FaceKey(BinaryInput input, BinarySerializator serializator) throws java.io.IOException
input
- the input to read the AbstractObjectKey fromserializator
- the serializator used to write objectsjava.io.IOException
- if there was an I/O error reading from the inputpublic java.lang.String getSourceImageLocatorURI()
locator URI
is returned by default.public java.lang.String getFaceIdentifierLocatorURI()
public final FaceKey clone(java.lang.String locatorURI) throws java.lang.CloneNotSupportedException
AbstractObjectKey
clone
in class AbstractObjectKey
locatorURI
- the new locator URI for the keyjava.lang.CloneNotSupportedException
- if there was an error cloning this objectpublic FaceKey clone(java.lang.String locatorURI, boolean preserveFaceLocatorExcension) throws java.lang.CloneNotSupportedException
locatorURI
- the new locator URI for the keypreserveFaceLocatorExcension
- if true, the given locator URI is extended with the original face identifierjava.lang.CloneNotSupportedException
- if there was an error cloning this objectpublic abstract int getCenterX()
source image
.public abstract int getCenterY()
source image
.public abstract int getWidth()
source image
.public abstract int getHeight()
source image
.public abstract float getRollAngle()
source image
.
That is the in-plane rotation of the face along the face center.
Straight face have zero roll angle.public abstract float getYawAngle()
source image
.
That is the left-right rotation of the face along the head vertical axis.
Full-frontal face have zero yaw angle.public abstract java.awt.Shape getContour()
source image
.public abstract java.awt.geom.Point2D getLandmarkPosition(FaceKey.FaceLandmark landmark) throws java.lang.NullPointerException
landmark
- the face landmark the position of which to getjava.lang.NullPointerException
- if the feature
parameter is nullpublic boolean intersect(FaceKey otherFaceKey, double threshold)
otherFaceKey
- the other face key to intersect withthreshold
- the intersection threshold, i.e. the percentage of the intersection area with respect to the face key areaspublic float getWidthNormalizationFactor()
public float getHeightNormalizationFactor()
protected static java.awt.Rectangle intersectRectWithImage(java.awt.image.BufferedImage image, java.awt.Rectangle rect)
image
- the image to use for intersectionrect
- the rectangle to use for intersectionpublic java.awt.Graphics2D drawFaceOval(java.awt.Graphics2D g, int size)
g
- the graphic context in which to drawsize
- the size of the oval line in pixelspublic java.awt.image.BufferedImage drawFaceOval(java.awt.image.BufferedImage image, int size)
image
- the image in which to drawsize
- the size of the oval line in pixelspublic java.awt.Graphics2D drawFaceContour(java.awt.Graphics2D g, int size)
g
- the graphic context in which to drawsize
- the size of the contour line in pixelspublic java.awt.image.BufferedImage drawFaceContour(java.awt.image.BufferedImage image, int size)
image
- the image in which to drawsize
- the size of the contour line in pixelspublic java.awt.Graphics2D drawFaceLandmarkPoint(java.awt.Graphics2D g, FaceKey.FaceLandmark landmark, int size)
g
- the graphic context in which to drawlandmark
- the landmark identifier the position of which to getsize
- the size of the dot in pixelspublic java.awt.image.BufferedImage drawFaceLandmarkPoint(java.awt.image.BufferedImage image, FaceKey.FaceLandmark landmark, int size)
size
-pixels wide dot.
Note that the coordinate system of the original image is assumed.image
- the image in which to drawlandmark
- the landmark identifier the position of which to getsize
- the size of the dot in pixelspublic java.awt.image.BufferedImage drawFaceLandmarks(java.awt.image.BufferedImage image, int size)
size
-pixels wide dots.
Note that the coordinate system of the original image is assumed.image
- the image in which to drawsize
- the size of the dot in pixelspublic java.awt.Graphics2D drawFaceLabel(java.awt.Graphics2D g, java.lang.String label)
g
- the graphic context in which to drawlabel
- the label to drawpublic java.awt.image.BufferedImage drawFaceLabel(java.awt.image.BufferedImage image, java.lang.String label)
image
- the image in which to drawlabel
- the label to drawpublic java.awt.image.BufferedImage loadFaceImage(java.io.File imageDir) throws java.io.IOException
getSourceImageLocatorURI()
).imageDir
- the root directory from which the detector was run;
it can be null if the locator contains valid absolute path
or relative path the the current working directoryjava.io.IOException
- if there was a problem loading the image (e.g. file was not found)public void saveFaceImage(java.awt.image.BufferedImage image, java.lang.String imageFormatName, java.io.File destDir) throws java.io.IOException
destDir
as a file named
by the locator
of this key.
This method is usually used as a final step of drawing operations sequence.image
- the image to savedestDir
- the destination directory where the image is storedimageFormatName
- a string containing the informal name of the format (e.g. "jpeg")java.io.IOException
- if there was a problem loading the image (e.g. file was not found)public java.awt.image.BufferedImage extractFaceImage(java.awt.image.BufferedImage originalImage, double enlargementFactor)
originalImage
- the original image where the face was detectedenlargementFactor
- the enlargement factor of the face bounding box;
zero means no enlargementpublic java.awt.image.BufferedImage extractFaceImage(java.io.File imageDir, double enlargementFactor) throws java.io.IOException
imageDir
directory.imageDir
- the root directory from which the detector was run;
it can be null if the locator contains valid absolute path
or relative path the the current working directoryenlargementFactor
- the enlargement factor of the face bounding box;
zero means no enlargementjava.io.IOException
- if there was a problem loading the image (e.g. file was not found)public void extractFaceImage(java.io.File imageDir, java.io.File destDir, java.lang.String imageFormatName, double enlargementFactor) throws java.io.IOException
imageDir
directory.
The face sub-image is placed into the destDir
as a file named
by the locator
of this key.imageDir
- the root directory from which the detector was run;
it can be null if the locator contains valid absolute path
or relative path the the current working directorydestDir
- the destination directory where the face sub-image is storedimageFormatName
- a string containing the informal name of the format (e.g. "jpeg")enlargementFactor
- the enlargement factor of the face bounding box;
zero means no enlargementjava.io.IOException
public java.awt.image.BufferedImage extractTransformedFaceImage(java.awt.image.BufferedImage image, double scale, double rotation, java.awt.geom.Point2D rotationCenter, java.awt.geom.Point2D centerTranslation, int newWidth, int newHeight)
image
- the original image from which to extract the facescale
- the scaling factor of the resulting facerotation
- the rotation angle of the resulting face (in radians)rotationCenter
- the point of the rotation centercenterTranslation
- the destination point where the rotationCenter will be in the new imagenewWidth
- the resulting image widthnewHeight
- the resulting image heightpublic java.awt.image.BufferedImage extractTransformedFaceImageByEyes(java.awt.image.BufferedImage image, java.awt.geom.Point2D newLeftEyePos, int newWidth, int newHeight)
image
- the original image from which to extract the facenewLeftEyePos
- the coordinates of the left eye in the resulting imagenewWidth
- the resulting image widthnewHeight
- the resulting image heightpublic java.awt.image.BufferedImage extractTransformedFaceImageByPos(java.awt.image.BufferedImage image, java.awt.geom.Point2D leftEye, int newWidth, int newHeight) throws java.lang.IllegalStateException
image
- the original image from which to extract the faceleftEye
- the coordinates of the left eye in the resulting imagenewWidth
- the resulting image widthnewHeight
- the resulting image heightjava.lang.IllegalStateException
- if this face key has neither left nor right eye landmark detected