1 #ifndef FACE_SWAP_FACE_SWAP_H 2 #define FACE_SWAP_FACE_SWAP_H 4 #include "face_swap/cnn_3dmm_expr.h" 5 #include "face_swap/basel_3dmm.h" 6 #include "face_swap/face_renderer.h" 9 #include <opencv2/core.hpp> 12 #include <sfl/sequence_face_landmarks.h> 13 #include <sfl/utilities.h> 16 #include <face_seg/face_seg.h> 35 FaceSwap(
const std::string& landmarks_path,
const std::string& model_3dmm_h5_path,
36 const std::string& model_3dmm_dat_path,
const std::string& reg_model_path,
37 const std::string& reg_deploy_path,
const std::string& reg_mean_path,
38 bool generic =
false,
bool with_expr =
true,
bool with_gpu =
true,
39 int gpu_device_id = 0);
49 const std::string& seg_deploy_path);
62 bool setSource(
const cv::Mat& img,
const cv::Mat& seg = cv::Mat());
66 bool setTarget(
const cv::Mat& img,
const cv::Mat& seg = cv::Mat());
95 bool preprocessImages(
const cv::Mat& img,
const cv::Mat& seg,
96 std::vector<cv::Point>& landmarks, std::vector<cv::Point>& cropped_landmarks,
97 cv::Mat& cropped_img, cv::Mat& cropped_seg, cv::Rect& bbox = cv::Rect());
111 void generateTexture(
const Mesh& mesh,
const cv::Mat& img,
const cv::Mat& seg,
112 const cv::Mat& vecR,
const cv::Mat& vecT,
const cv::Mat& K,
113 cv::Mat& tex, cv::Mat& uv);
126 cv::Mat generateTextureCoordinates(
const Mesh& mesh,
const cv::Size& img_size,
127 const cv::Mat& vecR,
const cv::Mat& vecT,
const cv::Mat& K);
137 cv::Mat blend(
const cv::Mat& src,
const cv::Mat& dst,
138 const cv::Mat& dst_seg = cv::Mat());
141 std::shared_ptr<sfl::SequenceFaceLandmarks> m_sfl;
142 std::unique_ptr<CNN3DMMExpr> m_cnn_3dmm_expr;
143 std::unique_ptr<Basel3DMM> m_basel_3dmm;
144 std::unique_ptr<FaceRenderer> m_face_renderer;
145 std::unique_ptr<face_seg::FaceSeg> m_face_seg;
150 Mesh m_src_mesh, m_dst_mesh;
151 cv::Mat m_vecR, m_vecT, m_K;
153 cv::Mat m_tgt_cropped_img, m_tgt_cropped_seg;
154 cv::Mat m_target_img, m_target_seg;
155 cv::Rect m_target_bbox;
158 cv::Mat m_source_img;
159 cv::Mat m_src_cropped_img, m_src_cropped_seg;
160 cv::Mat m_tgt_rendered_img;
161 std::vector<cv::Point> m_src_cropped_landmarks;
162 std::vector<cv::Point> m_tgt_cropped_landmarks;
163 cv::Mat m_src_vecR, m_src_vecT, m_src_K;
164 std::vector<cv::Point> m_src_landmarks, m_tgt_landmarks;
167 cv::Mat debugSource();
168 cv::Mat debugTarget();
170 cv::Mat debugSourceMesh();
171 cv::Mat debugTargetMesh();
172 cv::Mat debugMesh(
const cv::Mat& img,
const cv::Mat& seg,
173 const cv::Mat& uv,
const Mesh& mesh,
174 const cv::Mat& vecR,
const cv::Mat& vecT,
const cv::Mat& K);
175 cv::Mat debugSourceLandmarks();
176 cv::Mat debugTargetLandmarks();
177 cv::Mat debugRender();
182 #endif // FACE_SWAP_FACE_SWAP_H void setSegmentationModel(const std::string &seg_model_path, const std::string &seg_deploy_path)
Set segmentation model.
Definition: face_swap.h:20
cv::Mat swap()
Transfer the face from the source image onto the face in the target image.
const Mesh & getTargetMesh() const
Get the 3D reconstruced mesh of the target face.
bool setTarget(const cv::Mat &img, const cv::Mat &seg=cv::Mat())
Set target image and segmentation.
void clearSegmentationModel()
Clear previously set segmentation model.
bool isSegmentationModelInit()
Check whether the segmentation model is initialized.
Represents a 3D renderable shape.
Definition: basel_3dmm.h:13
Definition: basel_3dmm.h:9
const Mesh & getSourceMesh() const
Get the 3D reconstruced mesh of the source face.
FaceSwap(const std::string &landmarks_path, const std::string &model_3dmm_h5_path, const std::string &model_3dmm_dat_path, const std::string ®_model_path, const std::string ®_deploy_path, const std::string ®_mean_path, bool generic=false, bool with_expr=true, bool with_gpu=true, int gpu_device_id=0)
Construct FaceSwap instance.
bool setSource(const cv::Mat &img, const cv::Mat &seg=cv::Mat())
Set source image and segmentation.