当前位置:网站首页>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()边栏推荐
- "Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.1 data operation_ Learning thinking and exercise answers
- Leetcode question brushing record | 27_ Removing Elements
- th:include的使用
- leetcode 869. Reordered Power of 2 | 869. Reorder to a power of 2 (state compression)
- Beaucoup d'enfants ne savent pas grand - chose sur le principe sous - jacent du cadre orm, non, ice River vous emmène 10 minutes à la main "un cadre orm minimaliste" (collectionnez - le maintenant)
- JVM memory and garbage collection-3-object instantiation and memory layout
- Literature reading and writing
- Analysis ideas after discovering that the on duty equipment is attacked
- 鱼和虾走的路
- WPF custom realistic wind radar chart control
猜你喜欢

Xmeter newsletter 2022-06 enterprise v3.2.3 release, error log and test report chart optimization

Talk about the realization of authority control and transaction record function of SAP system

leetcode 869. Reordered Power of 2 | 869. 重新排序得到 2 的幂(状态压缩)

Yolov5 Lite: ncnn+int8 deployment and quantification, raspberry pie can also be real-time

科普 | 什么是灵魂绑定代币SBT?有何价值?

How does the bull bear cycle and encryption evolve in the future? Look at Sequoia Capital

Semantic segmentation | learning record (4) expansion convolution (void convolution)

实现前缀树

入侵检测——Uniscan

Learn CV two loss function from scratch (1)
随机推荐
数据链路层及网络层协议要点
Ml backward propagation
文盘Rust -- 给程序加个日志
1385:团伙(group)
Alo who likes TestMan
Opengl/webgl shader development getting started guide
"Hands on learning in depth" Chapter 2 - preparatory knowledge_ 2.2 data preprocessing_ Learning thinking and exercise answers
COMSOL --- construction of micro resistance beam model --- final temperature distribution and deformation --- addition of materials
Ncnn+int8+yolov4 quantitative model and real-time reasoning
Ml self realization / logistic regression / binary classification
LeetCode精选200道--数组篇
cv2-drawline
力争做到国内赛事应办尽办,国家体育总局明确安全有序恢复线下体育赛事
云原生应用开发之 gRPC 入门
入侵检测——jsql
A comprehensive and detailed explanation of static routing configuration, a quick start guide to static routing
Clickhouse principle analysis and application practice "reading notes (8)
2022年5月互联网医疗领域月度观察
JVM memory and garbage collection-3-runtime data area / heap area
Unity 射线与碰撞范围检测【踩坑记录】