swap_face.py 915 B

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