0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
s.azan
  • 1
  • This what i get : List landmarks = ret.getFaceLandmarks(); for (Point point : landmarks) { int pointX = (int) (point.x * resizeRatio); int pointY = (int) (point.y * resizeRatio); canvas.drawCircle(pointX, pointY, 2, mFaceLandmardkPaint); } – s.azan Nov 24 '17 at 17:54
  • Possible duplicate of [OpenCV - Cropping non rectangular region from image using C++](https://stackoverflow.com/questions/41689522/opencv-cropping-non-rectangular-region-from-image-using-c) – Dmitrii Z. Nov 24 '17 at 19:40
  • If you have code to show, please edit your question and put it there, using the formatting tools provided. – halfer Nov 25 '17 at 01:16

1 Answers1

0

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;
}
Eran Gross
  • 139
  • 3
  • 10