clcarwin / sphereface_pytorch

A PyTorch Implementation of SphereFace.
MIT License
714 stars 172 forks source link

alignment(src_img, src_pts) function ? #50

Open Ontheway361 opened 4 years ago

Ontheway361 commented 4 years ago

def alignment(src_img,src_pts): of = 2 ref_pts = [ [30.2946+of, 51.6963+of],[65.5318+of, 51.5014+of], [48.0252+of, 71.7366+of],[33.5493+of, 92.3655+of],[62.7299+of, 92.2041+of] ] crop_size = (96+of2, 112+of2)

s = np.array(src_pts).astype(np.float32)
r = np.array(ref_pts).astype(np.float32)

tfm = get_similarity_transform_for_cv2(s, r)
face_img = cv2.warpAffine(src_img, tfm, crop_size)
return face_img

Is there any information or reason for the fixed ref_pts ? why we picked those values ?

Ontheway361 commented 4 years ago

I wonder ref_pts was calculated by following way: step -1. ave_pts = np.mean(all_landmarks_in_casia, axis=0), where all_landmarks_in_casia.shape=(N, 10); step -2. norm_pts = ave_pts / 250, where casia_img.shape = (250, 250) step -3. ref_pts = norm_pts.reshape(-1, 2) * np.array([96, 112]) Then, we can get following result: array([[37.4707173 , 48.19678096], [57.53267604, 47.69648029], [47.40494149, 63.3143305 ], [38.90172655, 74.50723587], [56.77106886, 74.12000792]]) Absolutely, It was different with the ref_pts in which alignment function region.

Ontheway361 commented 4 years ago

@clcarwin, Looking forward to your reply!