コード例 #1
0
 def _draw_square(self, position: Point, color: Color):
     (ix, iy) = position.get()
     x = ix * SQUARE_SIZE
     y = iy * SQUARE_SIZE
     pg.draw.rect(self._screen, color.value,
                  pg.Rect(x + 1, y + 1, SQUARE_SIZE - 2, SQUARE_SIZE - 2))
コード例 #2
0
class FrontalFace:
    def __init__(self):
        self.guideline_point = None
        self.middle = None
        self.chin = None
        self.nose_center = None
        self.cheekbone = SymmetryPoint()
        self.cheek = SymmetryPoint()
        self.mouth = SymmetryPoint()
        self.nose = SymmetryPoint()
        self.outer_eye = SymmetryPoint()
        self.inner_eye = SymmetryPoint()
        self.malar = SymmetryPoint()
        self.angles = Angles()

    @staticmethod
    def __calculate_malar(outer_eye, mouth, nose, cheekbone):
        malar_eye_line = Line(outer_eye, mouth)
        malar_nose_line = Line(nose, cheekbone)
        return intersects(malar_eye_line, malar_nose_line)

    def calculate_additional(self):
        self.middle = Point(
            (self.inner_eye.left.x + self.inner_eye.right.x) / 2,
            (self.inner_eye.left.y + self.inner_eye.right.y) / 2)

        self.malar.left = FrontalFace.__calculate_malar(
            self.outer_eye.left, self.mouth.left, self.nose.left,
            self.cheekbone.left)
        self.malar.right = FrontalFace.__calculate_malar(
            self.outer_eye.right, self.mouth.right, self.nose.right,
            self.cheekbone.right)

    def to_dict(self):
        return {
            # "guideline_point": self.guideline_point.get(),
            "middle": self.middle.get(),
            "chin": self.chin.get(),
            "nose_center": self.nose_center.get(),
            "inner_eye_left": self.inner_eye.left.get(),
            "inner_eye_right": self.inner_eye.right.get(),
            "outer_eye_left": self.outer_eye.left.get(),
            "outer_eye_right": self.outer_eye.right.get(),
            "cheekbone_left": self.cheekbone.left.get(),
            "cheekbone_right": self.cheekbone.right.get(),
            "nose_left": self.nose.left.get(),
            "nose_right": self.nose.right.get(),
            "cheek_left": self.cheek.left.get(),
            "cheek_right": self.cheek.right.get(),
            "mouth_left": self.mouth.left.get(),
            "mouth_right": self.mouth.right.get(),
            "malar_left": self.malar.left.get(),
            "malar_right": self.malar.right.get()
        }

    def from_dict(self, d):
        # self.guideline_point = Point.from_array(d["guideline_point"])
        self.middle = Point.from_array(d["middle"])
        self.chin = Point.from_array(d["chin"])
        self.nose_center = Point.from_array(d["nose_center"])
        self.cheekbone.left = Point.from_array(d["cheekbone_left"])
        self.cheekbone.right = Point.from_array(d["cheekbone_right"])
        self.cheek.left = Point.from_array(d["cheek_left"])
        self.cheek.right = Point.from_array(d["cheek_right"])
        self.mouth.left = Point.from_array(d["mouth_left"])
        self.mouth.right = Point.from_array(d["mouth_right"])
        self.nose.left = Point.from_array(d["nose_left"])
        self.nose.right = Point.from_array(d["nose_right"])
        self.inner_eye.left = Point.from_array(d["inner_eye_left"])
        self.inner_eye.right = Point.from_array(d["inner_eye_right"])
        self.outer_eye.left = Point.from_array(d["outer_eye_left"])
        self.outer_eye.right = Point.from_array(d["outer_eye_right"])
        self.malar.left = Point.from_array(d["malar_left"])
        self.malar.right = Point.from_array(d["malar_right"])

    def __str__(self):
        d = self.to_dict()
        for key in d:
            d[key] = d[key].get()
        return str(d)

    def get_angles(self):
        self.angles.calculate(self)
        return self.angles

    def get_proportions(self):
        return Proportions(self.angles)