AndroidFaceCropper

repository·master·Indexed 19 days ago

https://github.com/lafosca/androidfacecropper

A library for automatically cropping faces from Android Bitmaps or drawable resources. It provides the FaceCropper class to extract cropped images and offers configuration options for maximum face count, minimum face size, margins, and debug overlays.

Tokens
415
Snippets
2
Records
3
Agent score
16%

What's inside androidfacecropper

  1. Use FaceCropper to crop faces from a Bitmap or Drawable

    master

    To automatically crop faces from an image, instantiate the FaceCropper class and call getCroppedImage(). The getCroppedImage method accepts either a Bitmap object or an int representing a drawable resource ID.

    FaceCropper mFaceCropper = new FaceCropper();
    // Using a Bitmap
    mFaceCropper.getCroppedImage(sourceBitmap);
    
    // Or using a drawable resource ID
    mFaceCropper.getCroppedImage(R.drawable.my_image);
  2. Configure FaceCropper behavior

    master

    You can fine-tune the face detection and cropping logic using the following configuration methods:

    • setMaxFaces(int faces): Sets the maximum number of faces to be recognized.
    • setFaceMinSize(int faceMinSize): Sets the minimum face size in pixels.
    • setFaceMarginPx(int faceMarginPx): Sets the margin in pixels to be applied to each side of the cropped face.
    • setEyeDistanceFactorMargin(float eyeDistanceFactorMargin): Sets a multiplier based on the distance between the detected eyes to adjust the crop area.
    • setDebug(boolean debug): Enables drawing red circles over detected faces for debugging purposes.
  3. Get a debug image with detected face overlays

    master

    To visualize the detection process, use getFullDebugImage(Bitmap bitmap). This returns a version of the original, non-cropped image where detected faces are painted with red circles and the calculated cropped areas are painted in green.

    Bitmap debugBitmap = mFaceCropper.getFullDebugImage(originalBitmap);