Applying face-swapping logic

We will pass both the input images as arguments to the swapper method. Here img1 is the image with face/s, and will be pasted onto the body/ies in img2. In general, img2 contains the body/ies with faces, but the body will not be seen in the result. As a first step, we begin by feeding the method with the matrix values of both images along with all the point vectors (facial key points) calculated using dlib. We will get the warped image of img2 shown as follows:

//faceswapper.cppMat img1Warped = img2.clone();//convert Mat to float data typeimg1.convertTo(img1, CV_32F);img1Warped.convertTo(img1Warped, CV_32F);Mat img11 = img1, img22 = img2;img11.convertTo(img11, CV_8UC3);img22.convertTo(img22, CV_8UC3);
CV_8UC3 ...

Get Machine Learning Projects for Mobile Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.