def run():
    parser = argparse.ArgumentParser(description='Choose the model')
    parser.add_argument('-model', default="HOG")
    args = parser.parse_args()

    cuda = torch.device('cuda')
    poser = MorphRotateCombinePoser256Param6(
        morph_module_spec=FaceMorpherSpec(),
        morph_module_file_name="data/face_morpher.pt",
        rotate_module_spec=TwoAlgoFaceRotatorSpec(),
        rotate_module_file_name="data/two_algo_face_rotator.pt",
        combine_module_spec=CombinerSpec(),
        combine_module_file_name="data/combiner.pt",
        device=cuda)

    if args.model == "HOG":
        face_detector = dlib.get_frontal_face_detector()
    else:
        cnn_face_detection_model = face_recognition_models.cnn_face_detector_model_location(
        )
        face_detector = dlib.cnn_face_detection_model_v1(
            cnn_face_detection_model)

    landmark_locator = dlib.shape_predictor(
        "data/shape_predictor_68_face_landmarks.dat")

    video_capture = cv2.VideoCapture(0)

    master = Tk()
    PuppeteerApp(master, poser, face_detector, landmark_locator, video_capture,
                 cuda, args.model)
    master.mainloop()
Exemplo n.º 2
0
 def __init__(self):
     self.torch_device = cuda
     self.poser = MorphRotateCombinePoser256Param6(
         morph_module_spec=FaceMorpherSpec(),
         morph_module_file_name="../data/face_morpher.pt",
         rotate_module_spec=TwoAlgoFaceRotatorSpec(),
         rotate_module_file_name="../data/two_algo_face_rotator.pt",
         combine_module_spec=CombinerSpec(),
         combine_module_file_name="../data/combiner.pt",
         device=cuda)
     # self.face_detector = dlib.get_frontal_face_detector()
     # self.landmark_locator = dlib.shape_predictor("../data/shape_predictor_68_face_landmarks.dat")
     self.head_pose_solver = HeadPoseSolver()
     self.pose_size = len(self.poser.pose_parameters())
Exemplo n.º 3
0
            posed_image = self.poser.pose(self.source_image,
                                          self.current_pose).detach().cpu()
            numpy_image = rgba_to_numpy_image(posed_image[0])
            numpy_image = cv2.cvtColor(numpy_image, cv2.COLOR_BGR2RGB)
            #pil_image = PIL.Image.fromarray(np.uint8(np.rint(numpy_image * 255.0)), mode='RGBA')

            return numpy_image


if __name__ == "__main__":
    cuda = torch.device('cuda')
    poser = MorphRotateCombinePoser256Param6(
        morph_module_spec=FaceMorpherSpec(),
        morph_module_file_name="data/face_morpher.pt",
        rotate_module_spec=TwoAlgoFaceRotatorSpec(),
        rotate_module_file_name="data/two_algo_face_rotator.pt",
        combine_module_spec=CombinerSpec(),
        combine_module_file_name="data/combiner.pt",
        device=cuda)

    face_detector = dlib.get_frontal_face_detector()
    landmark_locator = dlib.shape_predictor(
        "data/shape_predictor_68_face_landmarks.dat")
    pp = PuppeteerApp("data/illust/vladimir_putin_PNG29.png", poser,
                      face_detector, landmark_locator, cuda)
    video_capture = cv2.VideoCapture(0)

    while True:
        ret, frame = video_capture.read()
        posed = pp.update_image(frame)