Delaunay Triangulation for Face swapping – Opencv with Python (part 2)
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, t) pt2 = (t, t) pt3 = (t, t) 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)
This site uses Akismet to reduce spam. Learn how your comment data is processed.
- Train YOLO to detect a custom object (online with free GPU)
- YOLO object detection using Opencv with Python
- Detecting colors (Hsv Color Space) – Opencv with Python
- How to install Python 3 and Opencv 4 on Windows
- Check if two images are equal with Opencv and Python
- How to install Dlib for Python 3 on Windows
- Feature detection (SIFT, SURF, ORB) – OpenCV 3.4 with python 3 Tutorial 25
- Eye motion tracking – Opencv with Python