Face Detection using Dlib
Dlib is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real-world problems. It is used in both industry and academia in various domains, including robotics, embedded devices, mobile phones, and large high-performance computing environments. Dlib's open source licensing allows you to use it in any application, free of charge.
Dlib can incredibly find 68 different facial landmark points including chin and jawline, eyebrows, nose, eyes, and lips. We can extract exact facial area based on those landmark points beyond rough face detection
pip install dlib
import cv2
import dlib
cap = cv2.VideoCapture(0)
hog_face_detector = dlib.get_frontal_face_detector()
dlib.facelandmark = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
while True:
_,frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = hog_face_detector(gray)
for face in faces:
face_landmarks=dlib.facelandmark(gray, face)
for n in range (0,68):
x= face_landmarks.part(n).x
y=face_landmarks.part(n).y
cv2.circle(frame , (x,y),1,(0,255,0),1)
cv2.imshow("face_landmarks", frame)
if cv2.waitKey(1)==ord("q"):
break
cap.release()
cv2.destroyAllWindows()
Dat file link:
https://drive.google.com/file/d/1fwC5KrqPJQKTJdS9YDZ79-e5oDwa7egS/view?usp=sharing
output :


Nice
ReplyDeleteAmazing
ReplyDeleteGreat
ReplyDelete