| ImageEn, unit iexHelperFunctions |
|
TIEBitmapHelper.CropToFace
Declaration
function CropToFace(Padding: Double = 0.4; Headroom: Double = 0.2; AspectRatio: Double = 0; ExtendBeyondImage: Boolean = False; FillColor: TColor = -1; MinScore: Double = 0.8): Boolean;
Description
Crops the image to the main (largest) face. Useful for profile pictures, thumbnails and ID photos.
Returns True if a face was found and the image was cropped. If no face is found, the image is not changed.
| Parameter | Description |
| Padding | Space added on every side of the face, as a fraction of the face size. E.g. 0.4 adds 40% of the face width to the left and right, and 40% of the face height above and below. The face box runs from the forehead to the chin |
| Headroom | Additional space above the face (for the hair), as a fraction of the face height |
| AspectRatio | Width / height of the result, e.g. 1 for square, 0.75 for a 3:4 portrait. 0 keeps the shape of the padded face box. The box is enlarged around its center to reach the ratio |
| ExtendBeyondImage | If False, the crop is moved (and if needed reduced) to stay within the image. If True, the crop keeps the face centered and areas outside the image are filled with FillColor |
| FillColor | Color of areas outside the image when ExtendBeyondImage is True. -1 uses the background color, clNone makes them transparent (see Crop) |
| MinScore | The minimum detection score for a face (0 to 1) |
Note:
◼You must add the iexHelperFunctions unit to your uses clause
◼Delphi/C++ 2005 or newer is required to use helper classes
◼To crop to a face without changing the image, use
DetectFaces or
alignFace
◼Face detection requires
IEVision. You will need to
register it before calling the method
Demo
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
Examples
// Make a square profile picture
if ImageEnView1.IEBitmap.CropToFace( 0.5, 0.2, 1 ) then
begin
ImageEnView1.Proc.Resample( 256, 256, rfLanczos3 );
ImageEnView1.IO.SaveToFile( 'D:\Profile.jpg' );
end;
// Crop the image to a square around the main face
ImageEnView1.IEBitmap.CropToFace( 0.4, 0.2, 1, False, clWhite );
ImageEnView1.Update();