1 原理
1.1 通过userId新建档案
- 上传1-N张人脸数据
- 截取图片中的人脸(部分图片),转为灰度,并保存
- 通过OpenCV训练模型,生成yam训练文件
1.2 人脸对比
- 截取图片中的人脸(部分图片),转为灰度
- 根据训练文件进行人脸对比,如果大于80,则保存头像,并重新训练
- 返回数据结果
2 公共模块
2.1 config.py 配置文件
import sys
__trainer__path = sys.path[2] + '/face_trainer'
__FaceStore__path = sys.path[2] + '/faceStore'
__NetCache__path = sys.path[2] + '/cache'
2.2 WosDownload.pyy
import config
import os
import datetime
import requests
import time
import random
def main(URI):
images = []
if URI == '':
print("ERR: URI is null", URI)
return False
if not isinstance(URI, list):
images.append(URI)
else:
images = URI
date = datetime.date.today()
path = config.__NetCache__path + '/' + str(date.year) + '/' + str(date.month) + '/' + str(date.day)
isExists = os.path.exists(path)
if not isExists:
os.makedirs(path)
downloadStatus = []
for image in images:
suffix = image.split(".")
while True:
filename = str(int(time.time())) + '-' + str(random.randint(10000, 99999)) + '.' + suffix[len(suffix) - 1]
filePath = path + '/' + filename
if not os.path.exists(filePath):
break
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (HTML, like Gecko) '
'Chrome/84.0.4147.105 Safari/537.36 '
}
r = requests.get(image, headers=headers, stream=True)
if r.status_code == 200:
open(filePath, 'wb').write(r.content)
downloadStatus.append(filePath)
else:
downloadStatus.append(False)
return downloadStatus
专栏文章目录