Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Creating better face masks using opencv::convexHull #18

Open
alexandarZ opened this issue Dec 16, 2017 · 1 comment
Open

[Feature] Creating better face masks using opencv::convexHull #18

alexandarZ opened this issue Dec 16, 2017 · 1 comment

Comments

@alexandarZ
Copy link

Hi Mateo,

Your work is great! I have one improvement for you. Face mask could be much better extracted using convexHull. This is my code where I use the convex hull method from OpenCV library to extract face mask and results are excellent.

cv::Mat FaceSwap::getFaceMask(cv::Mat &face, std::vector<cv::Point> &facePoints)
{
    cv::Mat mask;
    mask.create(face.size(), CV_8UC1);
    mask.setTo(cv::Scalar::all(0));

    // Find convex hull
    std::vector<int> hullPtsIndex;
    cv::convexHull(facePoints, hullPtsIndex, false, false);

    // Create convex polygon based on hull points
    cv::Point2i maskPoints[68];

    for(int i=0;i<hullPtsIndex.size();i++)
    {
        maskPoints[i] = facePoints[hullPtsIndex[i]];
    }

    // Fill mask polygon
    cv::fillConvexPoly(mask, maskPoints,hullPtsIndex.size(),cv::Scalar(255));

    return mask;
}

Results:

image

@hrastnik
Copy link
Owner

This is great. I will look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants