Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

MergeAvatar.py 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  1. import cv2
  2. import numpy as np
  3. from core import imagelib
  4. from facelib import FaceType, LandmarksProcessor
  5. from core.cv2ex import *
  6. def process_frame_info(frame_info, inp_sh):
  7. img_uint8 = cv2_imread (frame_info.filename)
  8. img_uint8 = imagelib.normalize_channels (img_uint8, 3)
  9. img = img_uint8.astype(np.float32) / 255.0
  10. img_mat = LandmarksProcessor.get_transform_mat (frame_info.landmarks_list[0], inp_sh[0], face_type=FaceType.FULL_NO_ALIGN)
  11. img = cv2.warpAffine( img, img_mat, inp_sh[0:2], borderMode=cv2.BORDER_REPLICATE, flags=cv2.INTER_CUBIC )
  12. return img
  13. def MergeFaceAvatar (predictor_func, predictor_input_shape, cfg, prev_temporal_frame_infos, frame_info, next_temporal_frame_infos):
  14. inp_sh = predictor_input_shape
  15. prev_imgs=[]
  16. next_imgs=[]
  17. for i in range(cfg.temporal_face_count):
  18. prev_imgs.append( process_frame_info(prev_temporal_frame_infos[i], inp_sh) )
  19. next_imgs.append( process_frame_info(next_temporal_frame_infos[i], inp_sh) )
  20. img = process_frame_info(frame_info, inp_sh)
  21. prd_f = predictor_func ( prev_imgs, img, next_imgs )
  22. #if cfg.super_resolution_mode != 0:
  23. # prd_f = cfg.superres_func(cfg.super_resolution_mode, prd_f)
  24. if cfg.sharpen_mode != 0 and cfg.sharpen_amount != 0:
  25. prd_f = cfg.sharpen_func ( prd_f, cfg.sharpen_mode, 3, cfg.sharpen_amount)
  26. out_img = np.clip(prd_f, 0.0, 1.0)
  27. if cfg.add_source_image:
  28. out_img = np.concatenate ( [cv2.resize ( img, (prd_f.shape[1], prd_f.shape[0]) ),
  29. out_img], axis=1 )
  30. return (out_img*255).astype(np.uint8)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...