当前位置:网站首页>Face key point detection Dlib
Face key point detection Dlib
2022-07-08 02:21:00 【So come on】
1、 Image recognition
Be careful :
1. dlib.get_frontal_face_detector( ) Get face detector
2. dlib.shape_predictor( ) Predict face key points
Face key point model , Download address :
# 1 Add to Library
import cv2
import matplotlib.pyplot as plt
import dlib
# 2 Read a picture
image = cv2.imread("Tom.jpeg")
# 3 Call the face detector
detector = dlib.get_frontal_face_detector()
# 4 Load prediction key model (68 A key point )
# Face key point model , Download address :
# http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2.
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
# 5 Gray scale conversion
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# 6 Face detection
faces = detector(gray, 1)
# 7 loop , Traverse every face , Draw a rectangle and key points for the face
for face in faces: #(x, y, w, h)
# 8 Draw rectangle
cv2.rectangle(image, (face.left(), face.top()), (face.right(), face.bottom()), (0,255,0), 2)
# 9 Predict the key points
shape = predictor(image, face)
# 10 Get the key coordinates
for pt in shape.parts():
# Get the abscissa and ordinate
pt_position = (pt.x, pt.y)
# 11 Draw key coordinates
cv2.circle(image, pt_position, 1, (255, 0, 0), -1)# -1 fill ,2 Represent size
# 12 Show the whole rendering
plt.imshow(image)
plt.axis("off")
plt.show()
2、 Computer camera recognition
# 1 Add to Library
import cv2
import dlib
# 2 Turn on the camera
capture = cv2.VideoCapture(0)
# 3 Get face detector
detector = dlib.get_frontal_face_detector()
# 4 Get the face key detection model
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
while True:
# 5 Read the video stream
ret, frame = capture.read()
# 6 Gray scale conversion
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# 7 Face detection
faces = detector(gray, 1)
# 8 Draw rectangular boxes and keys for each face
for face in faces:
# 8.1 Draw rectangle
cv2.rectangle(frame, (face.left(), face.top()), (face.right(), face.bottom()), (0,255,0), 3)
# 8.2 Key detected
shape = predictor(gray, face) #68 A key point
# 8.3 Get the coordinates of the key points
for pt in shape.parts():
# The coordinates of each point
pt_position = (pt.x, pt.y)
# 8.4 Draw key points
cv2.circle(frame, pt_position, 3, (255,0,0), -1)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# 9 According to the effect
cv2.imshow("face detection landmark", frame)
capture.release()
cv2.destroyAllWindows()
边栏推荐
- Popular science | what is soul binding token SBT? What is the value?
- 鱼和虾走的路
- 力扣4_412. Fizz Buzz
- 喜欢测特曼的阿洛
- Yolov5 lite: how to speed up the Yolo model on CPU?
- See how names are added to namespace STD from cmath file
- Spock单元测试框架介绍及在美团优选的实践_第四章(Exception异常处理mock方式)
- Industrial Development and technological realization of vr/ar
- VIM use
- Learn CV two loss function from scratch (3)
猜你喜欢
2022年5月互联网医疗领域月度观察
Introduction to grpc for cloud native application development
Thread deadlock -- conditions for deadlock generation
C language -cmake cmakelists Txt tutorial
Yolov5 Lite: yolov5, which is lighter, faster and easy to deploy
线程死锁——死锁产生的条件
《通信软件开发与应用》课程结业报告
UFS Power Management 介绍
Unity 射线与碰撞范围检测【踩坑记录】
喜欢测特曼的阿洛
随机推荐
Introduction to Microsoft ad super Foundation
Why did MySQL query not go to the index? This article will give you a comprehensive analysis
Yolo fast+dnn+flask realizes streaming and streaming on mobile terminals and displays them on the web
WPF custom realistic wind radar chart control
Nanny level tutorial: Azkaban executes jar package (with test samples and results)
[knowledge map] interpretable recommendation based on knowledge map through deep reinforcement learning
Deep understanding of cross entropy loss function
Give some suggestions to friends who are just getting started or preparing to change careers as network engineers
实现前缀树
Learn CV two loss function from scratch (2)
Little knowledge about TXE and TC flag bits
JVM memory and garbage collection-3-runtime data area / method area
Alo who likes TestMan
Leetcode question brushing record | 27_ Removing Elements
JVM memory and garbage collection -4-string
Analysis ideas after discovering that the on duty equipment is attacked
Yolov5 Lite: experiment and thinking of repovgg re parameterization on the industrial landing of Yolo
For friends who are not fat at all, nature tells you the reason: it is a genetic mutation
A comprehensive and detailed explanation of static routing configuration, a quick start guide to static routing
Coreldraw2022 download and install computer system requirements technical specifications