in lib/data/EvalWPoseDataset.py [0:0]
def face_crop(pts):
flag = pts[:,2] > 0.2
mshoulder = pts[1,:2]
rear = pts[18,:2]
lear = pts[17,:2]
nose = pts[0,:2]
center = np.copy(mshoulder)
center[1] = min(nose[1] if flag[0] else 1e8, lear[1] if flag[17] else 1e8, rear[1] if flag[18] else 1e8)
ps = []
pts_id = [0, 15, 16, 17, 18]
cnt = 0
for i in pts_id:
if flag[i]:
ps.append(pts[i,:2])
if i in [17, 18]:
cnt += 1
ps = np.stack(ps, 0)
if ps.shape[0] <= 1:
raise IOError('key points are not properly set')
if ps.shape[0] <= 3 and cnt != 2:
center = ps[-1]
else:
center = ps.mean(0)
radius = int(1.4*np.max(np.sqrt(((ps - center[None,:])**2).reshape(-1,2).sum(0))))
# radius = np.max(np.sqrt(((center[None] - np.stack([]))**2).sum(0))
# radius = int(1.0*abs(center[1] - mshoulder[1]))
center = center.astype(np.int)
x1 = center[0] - radius
x2 = center[0] + radius
y1 = center[1] - radius
y2 = center[1] + radius
return (x1, y1, x2-x1, y2-y1)