1

I got a requirement to display only face from an image. I am trying to use only android native methods to implement this.

I can detect face from Image using the following code :

public void detectFaces() {
        Log.d("FaceDet", "Detecting faces....");
        // Convert bitmap in 556

        Bitmap tmpBmp = image.copy(Config.RGB_565, true); 

        FaceDetector faceDet = new FaceDetector(tmpBmp.getWidth(), tmpBmp.getHeight(), MAX_FACES);

        Face[] faceList = new Face[MAX_FACES];

        faceDet.findFaces(tmpBmp, faceList);

        Log.d("FaceDetLength", "Face ["+faceList.length+"]");
        // Log the result
        for (int i=0; i < faceList.length; i++) {
            Face face = faceList[i];
            Log.d("FaceDet", "Face ["+face+"]");
            if (face != null) {
                Log.d("FaceDet", "Face ["+i+"] - Confidence ["+face.confidence()+"]");
                PointF pf = new PointF();
                face.getMidPoint(pf);
                Log.d("FaceDet", "\t Eyes distance ["+face.eyesDistance()+"] - Face midpoint ["+pf+"]");
                RectF r = new RectF();
                r.left = pf.x - face.eyesDistance() / 2;
                r.right = pf.x + face.eyesDistance() / 2;
                r.top = pf.y - face.eyesDistance() / 2;
                r.bottom = pf.y + face.eyesDistance() / 2;
                rects[i] = r;
            }
        }

        this.invalidate();
    }

Now I want to crop only face from this image. How can I do this ? I have gone through the following link :

Crop Image with face detection in android

But, the code mentioned in the above link is not working for all images. How can I crop only faces from Image ? Any advice is of great help .

Community
  • 1
  • 1
Christopher Marlowe
  • 2,098
  • 6
  • 38
  • 68

0 Answers0