Face Mesh using Python Programming
5 min read
As we all know Python comes with Huge Libraries to Explore in various types
of things like Automation, Designing, Web Development Frameworks and
Hacking.
What is MESH?
Answer: Mesh is a type of material made from network of wires and threads. Manually, it's of Green Color, but you can change accordingly.
What is Face Mesh?
Answer: Face Mesh is a 3D Model of a Human Face. Actually it works with a combination of face tracker in respective software. For Eg. Spark AR Studio (By Facebook).
As a Programmer, It becomes very important to keep a track on every library
used in Python. Here I'm not saying just grab everything but as a process
you should start knowing different types of libraries as this you'll explore
python a lot.
"Python is an experiment in how much freedom programmers need. Too much freedom and nobody can read another`s code; too little and expressiveness is endangered." - Guido van Rossum
Today, We'll Create an amazing Face Mesh with Python Programming. Source
Code will be available below. Try it once and don't forget to comment down
your queries, experiences below in the comment section.
Let's get started with the Source Code to Build a Face Mesh Program.
Here, In this Program we'll need to import cv2 and import mediapipe as mp
Source Code - (Face Mesh using Python)
import cv2
import mediapipe as mp
mp_face_mesh = mp.solutions.face_mesh
face_mesh = mp_face_mesh.FaceMesh()
video=cv2.VideoCapture(0)
while True:
check, frame=video.read()
height, width, _ = frame.shape
result = face_mesh.process(frame)
# Print Result
try:
for facial_landmarks in result.multi_face_landmarks:
for i in range(0, 468):
landmrk = facial_landmarks.landmark[i]
locx = int(landmrk.x * width)
locy = int(landmrk.y * height)
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.circle(frame, (locx, locy), 1, (0, 200, 0), 0)
cv2.imshow("Image", frame)
except:
cv2.imshow("Image", frame)
key=cv2.waitKey(1)
if key==ord('q')
break
video.release()
cv2.destroyAllWindows()
Output -![]() |
Image Credits - PySource |
Wasn't it a Wonderful Module to Get started with your Projects, specially in College or doing it solo just for getting taste of creativity.
Don't Forget to Install the Following Libraries in Python at your System.
You Can Install it through Terminal via pip install mediapipeand pip install opencv-pythonThis Type of Output of Face Mesh you will get to see in Instagram Filters, But here we are getting to see a back-end of an filter.
Just Copy and Paste the Code from Above to get started
OR