Using saved onnx models to perform arbitrary face swap task in real time
onnxruntime==1.6.0
opencv-python==4.4.0
kivy==2.0.0
The code does face detection --> face landmark detection ---> swap face by patching corresponding triangles from face A to face B with delaunay triangulation. The onnx models used in the first two steps can be found in this github repo, one tutorial of the last step can be found here.
The code uses kivy for the simple GUI construction.
1.Download pictures of whom you would like to swap your face with to the \portrait
folder. A frontal view protrait picture will be ideal for final performance.
2.Execute faceswap_kivy.py
to start the GUI.
- Depending on your machine's acutal hardware setting, change the Camera index to use the right camera.
- The dropdown menu will contain source portrait you downloaded in the
\portrait
folder. Select one and hitStart
, you are good to go. - If multiple images are in the folder and you would like to use a different face, just clike
reset
and then re-select the one you want to use. - With a virtual camera software such as OBS Studio, you can make yourself appear as a different person on your online meetings/classes.
- You may also consider using tools such as
Pyinstaller
to package it to executable and deploy it to other machines without python installed.