swap_face.py 993 B

1234567891011121314151617181920212223242526272829303132
  1. import os
  2. import time
  3. import requests
  4. from PIL import Image
  5. import threading
  6. class swap_face():
  7. def __init__(self, imgurl):
  8. self.imgurl = imgurl
  9. def run(self):
  10. name_hash = str(time.time()).replace('.','')
  11. src_img = 'FaceSwap/src_img/'+name_hash+'.jpg'
  12. sv_path = '../html/swap_save'+name_hash+'.avi'
  13. try:
  14. im = Image.open(requests.get(self.imgurl, stream=True).raw)
  15. im= im.convert("RGB")
  16. im.save(src_img)
  17. except:
  18. return '圖片錯誤'
  19. os.system('python3 FaceSwap/main_video.py --src_img '+src_img+' --video_path FaceSwap/nina_noGesture_adj.mp4 --correct_color --save_path '+sv_path)
  20. while True:
  21. print('waiting...')
  22. if os.path.exists(sv_path):
  23. break
  24. time.sleep(5)
  25. print('waiting...')
  26. return "人物生成完成 at : www.choozmo.com:8168/swap_save/"+name_hash+".avi"