• 大小: 12.77MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-30
  • 语言: Python
  • 标签: python  dlib  

资源简介

python dlib库,训练人脸的68个特征点检测器。包含数据集,源码。详细可以参考我的博客:http://blog.csdn.net/hongbin_xu/article/details/78511923

资源截图

代码片段和文件信息

# coding: utf-8

#   This example program shows how to use dlib‘s implementation of the paper:
#   One Millisecond Face Alignment with an Ensemble of Regression Trees by
#   Vahid Kazemi and Josephine Sullivan CVPR 2014

import os
import cv2
import dlib
import glob

current_path = os.getcwd()
faces_path = current_path + ‘/examples/faces‘

# 训练部分
# 参数设置
options = dlib.shape_predictor_training_options()
options.oversampling_amount = 300
options.nu = 0.05
options.tree_depth = 2
options.be_verbose = True

# 导入打好了标签的xml文件
training_xml_path = os.path.join(faces_path “training_with_face_landmarks.xml“)
# 进行训练,训练好的模型将保存为predictor.dat
dlib.train_shape_predictor(training_xml_path “predictor.dat“ options)
# 打印在训练集中的准确率
print “\nTraining accuracy:{0}“.format(dlib.test_shape_predictor(training_xml_path “predictor.dat“))

# 导入测试集的xml文件
testing_xml_path = os.path.join(faces_path “testing_with_face_landmarks.xml“)
# 打印在测试集中的准确率
print “\Testing accuracy:{0}“.format(dlib.test_shape_predictor(testing_xml_path “predictor.dat“))

# 测试部分
predictor = dlib.shape_predictor(“predictor.dat“)
detector = dlib.get_frontal_face_detector()
print(“Showing detections and predictions on the images in the faces folder...“)
for f in glob.glob(os.path.join(faces_path “*.jpg“)):
print(“Processing file: {}“.format(f))
img = cv2.imread(f)
img2 = cv2.cvtColor(img cv2.COLOR_BGR2GRAY)
dets = detector(img2 1)
print(“Number of faces detected: {}“.format(len(dets)))
for index face in enumerate(dets):
print(‘face {}; left {}; top {}; right {}; bottom {}‘.format(index face.left() face.top() face.right() face.bottom()))

# left = face.left()
# top = face.top()
# right = face.right()
# bottom = face.bottom()
# cv2.rectangle(img (left top) (right bottom) (0 255 0) 3)
# cv2.namedWindow(f cv2.WINDOW_AUTOSIZE)
# cv2.imshow(f img)

shape = predictor(img face)
# print(shape)
# print(shape.num_parts)
for index pt in enumerate(shape.parts()):
print(‘Part {}: {}‘.format(index pt))
pt_pos = (pt.x pt.y)
cv2.circle(img pt_pos 2 (255 0 0) 1)
#print(type(pt))
#print(“Part 0: {} Part 1: {} ...“.format(shape.part(0) shape.part(1)))
cv2.namedWindow(f cv2.WINDOW_AUTOSIZE)
cv2.imshow(f img)

cv2.waitKey(0)
cv2.destroyAllWindows()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-11-12 14:34  train_shpe_detector\
     目录           0  2017-11-12 14:23  train_shpe_detector\examples\
     目录           0  2017-11-02 21:02  train_shpe_detector\examples\faces\
     文件       89619  2017-11-02 21:02  train_shpe_detector\examples\faces\2007_007763.jpg
     文件       41770  2017-11-02 21:02  train_shpe_detector\examples\faces\2008_001009.jpg
     文件       65344  2017-11-02 21:02  train_shpe_detector\examples\faces\2008_001322.jpg
     文件       92641  2017-11-02 21:02  train_shpe_detector\examples\faces\2008_002079.jpg
     文件       91349  2017-11-02 21:02  train_shpe_detector\examples\faces\2008_002470.jpg
     文件       79316  2017-11-02 21:02  train_shpe_detector\examples\faces\2008_002506.jpg
     文件       93821  2017-11-02 21:02  train_shpe_detector\examples\faces\2008_004176.jpg
     文件      110034  2017-11-02 21:02  train_shpe_detector\examples\faces\2008_007676.jpg
     文件       79462  2017-11-02 21:02  train_shpe_detector\examples\faces\2009_004587.jpg
     文件      648373  2017-11-02 21:02  train_shpe_detector\examples\faces\bald_guys.jpg
     文件      175216  2017-11-02 21:02  train_shpe_detector\examples\faces\dogs.jpg
     文件        4166  2017-11-02 21:02  train_shpe_detector\examples\faces\image_metadata_stylesheet.xsl
     文件        1879  2017-11-02 21:02  train_shpe_detector\examples\faces\testing.xml
     文件       71586  2017-11-02 21:02  train_shpe_detector\examples\faces\testing_with_face_landmarks.xml
     文件        1445  2017-11-02 21:02  train_shpe_detector\examples\faces\training.xml
     文件       51828  2017-11-02 21:02  train_shpe_detector\examples\faces\training_with_face_landmarks.xml
     文件    16601169  2017-11-12 15:23  train_shpe_detector\predictor.dat
     文件        2425  2017-11-12 14:50  train_shpe_detector\train_shpe_detector.py

评论

共有 条评论