Delaunay Triangulation for Face swapping – Opencv with Python (part 2)
by
Sergio Canu
Face swapping, Tutorials
We’re going to see in this tutorial how to split the face into triangles using Delaunay Triangulation.
Why are we splitting the face into triangles?
For face swapping this is the best approach to use, we split both the faces into triangles and then we swap the triangles in the corrispondent region.
# Delaunay triangulation rect = cv2.boundingRect(convexhull) subdiv = cv2.Subdiv2D(rect) subdiv.insert(landmarks_points) triangles = subdiv.getTriangleList() triangles = np.array(triangles, dtype=np.int32) for t in triangles: pt1 = (t[0], t[1]) pt2 = (t[2], t[3]) pt3 = (t[4], t[5]) cv2.line(img, pt1, pt2, (0, 0, 255), 2) cv2.line(img, pt2, pt3, (0, 0, 255), 2) cv2.line(img, pt1, pt3, (0, 0, 255), 2)

Hi there, I’m the founder of Pysource.
I’m a Computer Vision Consultant, developer and Course instructor.
I help Companies and Freelancers to easily and efficiently build Computer Vision Software.

Learn to build Computer Vision Software easily and efficiently.
This is a FREE Workshop where I'm going to break down the 4 steps that are necessary to build software to detect and track any object.
Sign UP for FREE