(self, source_image, crop_factor, is_video = False, tracking = False)
| 358 | return face_img |
| 359 | |
| 360 | def prepare_source(self, source_image, crop_factor, is_video = False, tracking = False): |
| 361 | print("Prepare source...") |
| 362 | engine = self.get_pipeline() |
| 363 | source_image_np = (source_image * 255).byte().numpy() |
| 364 | img_rgb = source_image_np[0] |
| 365 | |
| 366 | psi_list = [] |
| 367 | for img_rgb in source_image_np: |
| 368 | if tracking or len(psi_list) == 0: |
| 369 | crop_region = self.detect_face(img_rgb, crop_factor) |
| 370 | face_region, is_changed = self.calc_face_region(crop_region, get_rgb_size(img_rgb)) |
| 371 | |
| 372 | s_x = (face_region[2] - face_region[0]) / 512. |
| 373 | s_y = (face_region[3] - face_region[1]) / 512. |
| 374 | crop_trans_m = create_transform_matrix(crop_region[0], crop_region[1], s_x, s_y) |
| 375 | mask_ori = cv2.warpAffine(self.GetMaskImg(), crop_trans_m, get_rgb_size(img_rgb), cv2.INTER_LINEAR) |
| 376 | mask_ori = mask_ori.astype(np.float32) / 255. |
| 377 | |
| 378 | if is_changed: |
| 379 | s = (crop_region[2] - crop_region[0]) / 512. |
| 380 | crop_trans_m = create_transform_matrix(crop_region[0], crop_region[1], s, s) |
| 381 | |
| 382 | face_img = rgb_crop(img_rgb, face_region) |
| 383 | if is_changed: face_img = self.expand_img(face_img, crop_region) |
| 384 | i_s = self.prepare_src_image(face_img) |
| 385 | x_s_info = engine.get_kp_info(i_s) |
| 386 | f_s_user = engine.extract_feature_3d(i_s) |
| 387 | x_s_user = engine.transform_keypoint(x_s_info) |
| 388 | psi = PreparedSrcImg(img_rgb, crop_trans_m, x_s_info, f_s_user, x_s_user, mask_ori) |
| 389 | if is_video == False: |
| 390 | return psi |
| 391 | psi_list.append(psi) |
| 392 | |
| 393 | return psi_list |
| 394 | |
| 395 | def prepare_driving_video(self, face_images): |
| 396 | print("Prepare driving video...") |
no test coverage detected