一、安装安装dlib及OpenCV
Windows+R,输入cmd得到:
在其中输入相关命令进行安装
1、dlib
python版本为3.8
pip install dlib-19.19.0-cp38-cp38-win_amd64.whl
2、OpenCV
pip3 install opencv_python
二、绘制人脸的68个特征点
import numpy as np
import cv2
import dlib
import os
import sys
import random
# 存储位置
output_dir = './faces'
size = 64
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# 改变图片的亮度与对比度
def relight(img, light=1, bias=0):
w = img.shape[1]
h = img.shape[0]
#image = []
for i in range(0,w):
for j in range(0,h):
for c in range(3):
tmp = int(img[j,i,c]*light + bias)
if tmp > 255:
tmp = 255
elif tmp < 0:
tmp = 0
img[j,i,c] = tmp
return img
#使用dlib自带的frontal_face_detector作为我们的特征提取器
detector = dlib.get_frontal_face_detector