python3.5 32位下载,可以安装
https://pypi.org/project/dlib/18.17.100/#files
https://www.jb51.net/softs/543679.html#downintro2
人脸检测
import sys
import os
import dlib
# import glob
import numpy as np
import cv2
import time
cap = cv2.VideoCapture(0)
# fourcc = cv2.VideoWriter_fourcc(*'XVID')
# out = cv2.VideoWriter('output.avi',fourcc, 20.0, (1280, 720))
# predictor_path = 'shape_predictor_81_face_landmarks.dat'
predictor_path = 'shape_predictor_68_face_landmarks.dat'
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
while(cap.isOpened()):
ret, frame = cap.read()
frame=cv2.resize(frame,(400,300))
# img_gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
start = time.time()
frame = cv2.flip(frame, 1)
dets = detector(frame, 0)
for k, point in enumerate(dets):
shape = predictor(frame, point)
landmarks = np.matrix([[p.x, p.y] for p in shape.parts()])
for num in range(shape.num_parts):
cv2.circle(frame, (shape.parts()[num].x, shape.parts()[num].y), 1, (0,255,0), -1)
print("time ->", time.time()-start)
cv2.imshow('frame', frame)
# out.write(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
print("q pressed")
break
cap.release()
# out.release()
cv2.destroyAllWindows()
来源:oschina
链接:https://my.oschina.net/u/4279029/blog/4273196