def _parse_marker_size(marker_size, points): if marker_size is None: from menpo.shape import PointCloud pc = PointCloud(points, copy=False) # This is the way that mayavi automatically computes the scale factor in # case the user passes scale_factor = 'auto'. We use it for both the # marker_size as well as the numbers_size. xyz_min, xyz_max = pc.bounds() x_min, y_min, z_min = xyz_min x_max, y_max, z_max = xyz_max distance = np.sqrt(((x_max - x_min)**2 + (y_max - y_min)**2 + (z_max - z_min)**2) / (4 * pc.n_points**0.33)) if distance == 0: marker_size = 1 else: marker_size = 0.1 * distance return marker_size
def _parse_marker_size(marker_size, points): if marker_size is None: from menpo.shape import PointCloud pc = PointCloud(points, copy=False) # This is the way that mayavi automatically computes the scale factor in # case the user passes scale_factor = 'auto'. We use it for both the # marker_size as well as the numbers_size. xyz_min, xyz_max = pc.bounds() x_min, y_min, z_min = xyz_min x_max, y_max, z_max = xyz_max distance = np.sqrt(((x_max - x_min) ** 2 + (y_max - y_min) ** 2 + (z_max - z_min) ** 2) / (4 * pc.n_points ** 0.33)) if distance == 0: marker_size = 1 else: marker_size = 0.1 * distance return marker_size
def crop_face(img, boundary=50, group=None, shape=(256, 256), order=1): pc = img.landmarks[group].lms nan_points = np.any(np.isnan(pc.points).reshape(-1, 2), 1) pc = PointCloud(pc.points[~nan_points, :]) min_indices, max_indices = pc.bounds(boundary=boundary) h = max_indices[0] - min_indices[0] w = max_indices[1] - min_indices[1] pad = abs(w - h) try: index = 1 - int(w > h) min_indices[index] -= int(pad / 2.) max_indices[index] += int(pad / 2.) + int(pad) % 2 img = img.crop(min_indices, max_indices, constrain_to_boundary=True) except Exception as e: print("Exception in crop_face", e) img = img.resize(shape, order=order) return img