An OpenCV Based application that allows you to swap faces between 2 images with OpenCV and dlib.
You can try out the Application Here
FaceSwap is an application that leverages computer vision techniques to swap faces between images. It uses OpenCV for image processing and Dlib for face detection and landmark prediction.
- Face Detection: Accurately detects faces in the source and target images using Dlib.
- Landmark Prediction: Identifies key facial landmarks for precise face alignment and swapping.
- Face Swapping: Seamlessly swaps faces between images using advanced image processing techniques.
- Color Correction: Ensures the swapped face blends naturally with the target image.
- Face Detection: Dlib is used to detect faces in both the source and target images.
- Landmark Detection: Facial landmarks are identified to facilitate accurate alignment.
- Face Alignment: The source face is aligned to match the orientation and size of the target face.
- Seamless Cloning: The aligned face is seamlessly cloned onto the target image using OpenCV's seamlessClone function.
python main.py --src imgs/test6.jpg --dst imgs/test7.jpg --out results/output6_7.jpg --correct_color
Source | Destination | Result |
---|---|---|
python main.py --src imgs/test6.jpg --dst imgs/test7.jpg --out results/output6_7_2d.jpg --correct_color --warp_2d
Source | Destination | Result |
---|---|---|
pip install -r requirements.txt
- OpenCV 3:
conda install opencv
(If you have conda/anaconda)
Note: See requirements.txt for more details.
git clone https://github.com/wuhuikai/FaceSwap.git
python main.py ...
Note: Run python main.py -h for more details.
python main_video.py --src_img imgs/test7.jpg --show --correct_color --save_path {*.avi}
python main_video.py --src_img imgs/test7.jpg --video_path {video_path} --show --correct_color --save_path {*.avi}
To run this project locally, follow these steps:
-
Clone the Repository
git clone https://github.com/yourusername/FaceSwap.git cd FaceSwap
-
Install Dependencies Make sure you have the following dependencies installed:
- Python 3.7+
- OpenCV
- Dlib
You can use the provided
requirements.txt
file to install the dependencies:pip install -r requirements.txt
-
Install Dlib In case the dblib installation is not working through
requirements.txt
, download the dblib wheel file from here Ensure you have the Dlib wheel file in your project directory:pip install dlib-19.24.1-cp311-cp311-win_amd64.whl
To use the FaceSwap application, follow these steps:
-
Run the Application
streamlit run app.py
-
Upload Images
- Upload the source image (the face to be swapped).
- Upload the target image (the image where the face will be swapped).
-
View and Download the Result
- The swapped face will be displayed on the right.
- Use the download button to save the output image.
From | To |
---|---|