tpys / face-everthing

face detection alignment recognition reconstruction ...
261 stars 102 forks source link

Face Alignment #14

Open anguoyang opened 6 years ago

anguoyang commented 6 years ago

Hi@tpys , you align the face image into 112x96, however,I need to align it into 112x112(insight face, which is similar with sphereface), so I simply changed the ReferenceWidth and ReferenceHeight into 112/112, but it seems that the aligned face is not correct(cut so much area), so it is not as accurate as InsightFace , maybe the problem is the ReferenceIDs, could you please tell me how to get the reference Points for 112x112 image? thank you.


cv::Mat align_face(const cv::Mat& src, const FaceLandmark& landmark, int width, int height) {

const int N = landmark.points_.size();
vector<cv::Point2f> detect_points;
if (N != 5) {
    detect_points = {
        landmark.points_[ReferenceID[0]],
        landmark.points_[ReferenceID[1]],
        landmark.points_[ReferenceID[2]],
        landmark.points_[ReferenceID[3]],
        landmark.points_[ReferenceID[4]],
    };
}
else {
    detect_points = landmark.points_;
}

const int ReferenceWidth = 112;
const int ReferenceHeight = 112;

**vector reference_points = {

    { 30.29459953f,  51.69630051f },
    { 65.53179932f,  51.50139999f },
    { 48.02519989f,  71.73660278f },
    { 33.54930115f,  92.3655014f },
    { 62.72990036f,  92.20410156f }
};**
for (auto& e : reference_points) {
    e.x += (width - ReferenceWidth) / 2.0f;
    e.y += (height - ReferenceHeight) / 2.0f;
}
cv::Mat tfm = get_similarity_transform(detect_points, reference_points);
cv::Mat aligned_face;
warpAffine(src, aligned_face, tfm, cv::Size(width, height));
return aligned_face;

}

lzg188 commented 6 years ago

if (ReferenceWidth == 112) wex = 8; vector reference_points = { Point2f( 30.29459953+wex, 51.69630051 ), Point2f( 65.53179932+wex, 51.50139999 ), Point2f( 48.02519989 + wex, 71.73660278 ), Point2f( 33.54930115 + wex, 92.3655014 ), Point2f( 62.72990036 + wex, 92.20410156 ) };

anguoyang commented 6 years ago

@lzg188 thank you so much!