def genLandmarkMap(landmarks, shape=[39, 39]):
'''Generate landmark map according to landmarks.
Input params:
landmarks: K x 2 float
shape: H x W
Output:
landmarkMap: H x W x K binary map. For each H x W
map, there's only one location nearest to the landmark
location filled with 1, else 0.'''
landmarks = landmarks.reshape((-1, 2))
landmarkMap = np.zeros(shape + [len(landmarks)])
for (i, landmark) in enumerate(landmarks):
x = int(np.around(landmark[0] * shape[1]))
y = int(np.around(landmark[1] * shape[0]))
landmarkMap[y, x, i] = 1
return landmarkMap
评论列表
文章目录