【问题标题】:Face landmark cropping by AndroidAndroid 人脸地标裁剪
【发布时间】:2018-05-08 18:07:46
【问题描述】:

我正在尝试检测面部特征并裁剪面部特征区域。我已经使用 dlib 成功检测了界标区域,下一步是裁剪检测区域,我已经阅读了很多博客,OpenCv 的官方文档,但我无法理解裁剪区域需要做什么。

我已经在每张脸的 arrayList 中获得了地标点。但我不知道如何使用这些点裁剪图像。

我正在使用 Android。

【问题讨论】:

  • 这是我得到的: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); }
  • 如果您要显示代码,请使用提供的格式化工具编辑您的问题并将其放在那里。

标签: android opencv dlib


【解决方案1】:

我相信这就是我用箭头指出的你要找的东西。

//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;
}

【讨论】:

    猜你喜欢
    • 2019-08-27
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    • 2013-02-09
    • 2012-10-25
    • 2019-02-21
    • 2015-06-17
    • 2018-03-07
    相关资源
    最近更新 更多