swap_face.py 944 B

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