简体   繁体   中英

Face landmark cropping by Android

I am try to detect the face landmark and crop the face landmark area. I have successful detect the landmark area using dlib, my next step is to crop the detect area, I have read lots of blogs, official documents of OpenCv, but I am unable to understand what I need to do for cropping the area.

I have get the landmarks points in arrayList of each face. but i don't know how to crop the image using this points.

I am using Android.

I believe this what you are looking for I have pointed out with an arrow.

//This function extract data from the image and return FaceLandmarks Object
private ArrayList<FaceLandmarks> faceLandmarkDetection(Bitmap bitmap) {
     ArrayList<Point> singleFaceLandmarks = new ArrayList<>();
     ArrayList<FaceLandmarks> multipleFacesLandmarks = new ArrayList<>();
    //Calling FaceDet class loading landmarks file.
    FaceDet faceDet = new FaceDet(mTargetPath);
    //This array contain multiple faces landmarks
    //extracting the results from the image
    Bitmap rotateBitmap = rotateImage(bitmap);
    List<VisionDetRet> results = faceDet.detect(rotateBitmap);
    //Running on the image faces extracting information.
    for (VisionDetRet ret : results) {
        int rectLeft = ret.getLeft();
        int rectTop = ret.getTop();
        int rectRight = ret.getRight();
        int rectBottom = ret.getBottom();
        int imageWidth = rotateBitmap.getWidth();
        int imageHeight = rotateBitmap.getHeight();
        //We do image correction, if the face is out of the entire image frame
        if(rectRight > imageWidth){
            rectRight = imageWidth;
        }
        //We do image correction, if the face is out of the entire image frame
        if(rectBottom > imageHeight){
            rectBottom = imageHeight;
        }

 ==>           int faceWidth = rectRight - rectLeft;

 ==>           int faceHeight = rectBottom - rectTop;


 ==>            Bitmap croppedBmp = Bitmap.createBitmap(rotateBitmap, rectLeft, rectTop, faceWidth, faceHeight);
            List<VisionDetRet> improvedResults = faceDet.detect(croppedBmp);
            //This array contain single face landmarks: Get 68 landmark points
            for (VisionDetRet improvedRet : improvedResults) {
                singleFaceLandmarks = improvedRet.getFaceLandmarks();
            }
            multipleFacesLandmarks.add(new FaceLandmarks(singleFaceLandmarks));
        }




    return multipleFacesLandmarks;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM