• 大小: 39.45MB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2024-01-29
  • 语言: Python
  • 标签:

资源简介

基于python的一个人脸识别的实例,里面包含源代码,已经经过测试,是一个很好的入门级的例子

资源截图

代码片段和文件信息

import cv2
import dlib
import numpy

import sys

PREDICTOR_PATH = “E:/home/shape_predictor_68_face_landmarks“
SCALE_FACTOR = 1
FEATHER_AMOUNT = 11

FACE_POINTS = list(range(17 68))
MOUTH_POINTS = list(range(48 61))
RIGHT_BROW_POINTS = list(range(17 22))
LEFT_BROW_POINTS = list(range(22 27))
RIGHT_EYE_POINTS = list(range(36 42))
LEFT_EYE_POINTS = list(range(42 48))
NOSE_POINTS = list(range(27 35))
JAW_POINTS = list(range(0 17))

# Points used to line up the images.
ALIGN_POINTS = (LEFT_BROW_POINTS + RIGHT_EYE_POINTS + LEFT_EYE_POINTS +
                RIGHT_BROW_POINTS + NOSE_POINTS + MOUTH_POINTS)

# Points from the second image to overlay on the first. The convex hull of each
# element will be overlaid.
OVERLAY_POINTS = [
    LEFT_EYE_POINTS + RIGHT_EYE_POINTS + LEFT_BROW_POINTS + RIGHT_BROW_POINTS
    NOSE_POINTS + MOUTH_POINTS
]

# Amount of blur to use during colour correction as a fraction of the
# pupillary distance.
COLOUR_CORRECT_BLUR_FRAC = 0.6

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(PREDICTOR_PATH)


class TooManyFaces(Exception):
    pass


class NoFaces(Exception):
    pass


def get_landmarks(im):
    rects = detector(im 1)

    if len(rects) > 1:
        raise TooManyFaces
    if len(rects) == 0:
        raise NoFaces

    return numpy.matrix([[p.x p.y] for p in predictor(im rects[0]).parts()])


def annotate_landmarks(im landmarks):
    im = im.copy()
    for idx point in enumerate(landmarks):
        pos = (point[0 0] point[0 1])
        cv2.putText(im str(idx) pos
                    fontFace=cv2.FONT_HERSHEY_script_SIMPLEX
                    fontScale=0.4
                    color=(0 0 255))
        cv2.circle(im pos 3 color=(0 255 255))
    return im


def draw_convex_hull(im points color):
    points = cv2.convexHull(points)
    cv2.fillConvexPoly(im points color=color)


def get_face_mask(im landmarks):
    im = numpy.zeros(im.shape[:2] dtype=numpy.float64)

    for group in OVERLAY_POINTS:
        draw_convex_hull(im
                         landmarks[group]
                         color=1)

    im = numpy.array([im im im]).transpose((1 2 0))

    im = (cv2.GaussianBlur(im (FEATHER_AMOUNT FEATHER_AMOUNT) 0) > 0) * 1.0
    im = cv2.GaussianBlur(im (FEATHER_AMOUNT FEATHER_AMOUNT) 0)

    return im


def transformation_from_points(points1 points2):
    “““
    Return an affine transformation [s * R | T] such that:
        sum ||s*R*p1i + T - p2i||^2
    is minimized.
    “““
    # Solve the procrustes problem by subtracting centroids scaling by the
    # standard deviation and then using the SVD to calculate the rotation. See
    # the following for more details:
    #   https://en.wikipedia.org/wiki/Orthogonal_Procrustes_problem

    points1 = points1.astype(numpy.float64)
    points2 = points2.astype(numpy.float64)

    c1 = numpy.

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-11-23 11:13  facetest1\
     目录           0  2018-11-23 19:10  facetest1\.idea\
     文件         511  2018-11-23 18:51  facetest1\.idea\facetest1.iml
     文件         197  2018-11-23 18:51  facetest1\.idea\misc.xml
     文件         270  2018-11-23 11:06  facetest1\.idea\modules.xml
     文件        9887  2018-11-23 19:10  facetest1\.idea\workspace.xml
     目录           0  2018-11-23 19:33  facetest1\fileface\
     文件        5628  2018-11-23 19:32  facetest1\fileface\face1.py
     文件        7754  2018-11-23 19:33  facetest1\fileface\face2.py
     文件           0  2018-11-23 11:13  facetest1\fileface\__init__.py
     目录           0  2018-11-23 17:27  facetest1\venv\
     目录           0  2018-09-20 20:22  facetest1\venv\Include\
     文件       45225  2017-09-17 02:38  facetest1\venv\Include\abstract.h
     文件        1099  2017-09-17 02:38  facetest1\venv\Include\asdl.h
     文件         230  2017-09-17 02:38  facetest1\venv\Include\ast.h
     文件         792  2017-09-17 02:38  facetest1\venv\Include\bitset.h
     文件         912  2017-09-17 02:38  facetest1\venv\Include\boolobject.h
     文件         922  2017-09-17 02:38  facetest1\venv\Include\bufferobject.h
     文件        1941  2017-09-17 02:38  facetest1\venv\Include\bytearrayobject.h
     文件        1152  2017-09-17 02:38  facetest1\venv\Include\bytesobject.h
     文件        2804  2017-09-17 02:38  facetest1\venv\Include\bytes_methods.h
     文件         651  2017-09-17 02:38  facetest1\venv\Include\cellobject.h
     文件        5061  2017-09-17 02:38  facetest1\venv\Include\ceval.h
     文件        3002  2017-09-17 02:38  facetest1\venv\Include\classobject.h
     文件        2930  2017-09-17 02:38  facetest1\venv\Include\cobject.h
     文件        4403  2017-09-17 02:38  facetest1\venv\Include\code.h
     文件        6171  2017-09-17 02:38  facetest1\venv\Include\codecs.h
     文件        1065  2017-09-17 02:38  facetest1\venv\Include\compile.h
     文件        1853  2017-09-17 02:38  facetest1\venv\Include\complexobject.h
     文件        2005  2017-09-17 02:38  facetest1\venv\Include\cStringIO.h
     文件        8313  2017-09-17 02:38  facetest1\venv\Include\datetime.h
............此处省略2176个文件信息

评论

共有 条评论

相关资源