# 版本python3
# 建议使用anconda + pycharm 进行前期配置环境,比较简单
# 安装教程请自行百度很简单
# Python 3 利用 Dlib 实现人脸 68个 特征点的标定
import numpy as np
import cv2
import dlib
from PIL import Image
import os
# 人脸识别以及截取图片保存
def recognition(img_path, outputimagepath):
beforeimage = Image.open(img_path)
beforew, beforeh = beforeimage.size # 获的图像原始尺寸
detector = dlib.get_frontal_face_detector() # 创建一个容器
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat') # 加载一个自带的分类器
img = cv2.imread(img_path) # 使用python-opencv读取图片
img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 使图片转化为灰度图片
rects = detector(img_grey, 0) # 返回信息
for i in range(len(rects)):
landmarks = np.matrix([[p.x, p.y] for p in predictor(img_grey, rects[i]).parts()]) # 获取点的坐标
for idx, point in enumerate(landmarks):
pos = (point[0, 0], point[0, 1]) # 68点的坐标
w, h =
Python基于人脸特征识别根据指定点批量截图
最新推荐文章于 2023-03-02 18:24:52 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)