dlib win32

此生再无相见时 提交于 2020-08-12 18:16:07

 

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()



 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!