Пример #1
0
def load_landmark(filepath, mirrored=False, width=0):
    """
    Creates a shape from a file containing 2D points
    in the following format
        x1
        y1
        x2
        y2
        ...
        xn
        yn
    :param filepath: The path to the landmark file
    :param mirrored: True when reading a vertically mirrored landmark
    :param width: The image width, needed when reading a mirrored landmark
    :return: A Shape object
    """
    y_list = []
    x_list = []
    if mirrored and width == 0:
        raise ValueError("Need a nonzero width for a mirrored landmark")
    with open(filepath) as fd:
        for i, line in enumerate(fd):
            if i % 2 == 0:
                x_list.append(float(line) + width)
            else:
                y_list.append(float(line))
    return Shape.from_coordinate_lists_2d(x_list, y_list)
Пример #2
0
 def generate_shape(self, factors):
     """
     Generates a shape based on a vector of factors of size
     equal to the number of modes of the model, with element
     values between -1 and 1
     :param factors: A vector of size modes() with values
     between -1 and 1
     :return: A Shape object containing the generated shape
     """
     return Shape(
         self.mean_shape().raw() + Shape.from_collapsed_shape(self._model.generate_deviation(factors)).raw())