face-everthing icon indicating copy to clipboard operation
face-everthing copied to clipboard

Face Alignment

Open anguoyang opened this issue 8 years ago • 2 comments

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;

**vectorcv::Point2f 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;

}

anguoyang avatar Mar 08 '18 01:03 anguoyang

if (ReferenceWidth == 112) wex = 8; vector<Point2f> 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 ) };

lzg188 avatar Apr 17 '18 09:04 lzg188

@lzg188 thank you so much!

anguoyang avatar Apr 19 '18 00:04 anguoyang