一、 本文结构
1、算法相关库的安装
2、视频中人脸识别的底库文件生成
3、视频流中人脸识别
mtcnn模型同样使用上一篇文章中已经训练好的模型
二、 算法环境搭建以及相关库安装
与上文相同,不在赘述
三、 视频中人脸识别的底库文件生成
实际上是与图片中人脸识别的底库生成思路是相同的,最后生成.pickle文件
class_video.py
# coding:utf-8
import os
import face_recognition
import pickle
# 加载mtcnn模块
# 加载mtcnn模块
from training.mtcnn_model import P_Net, R_Net, O_Net
from tools.loader import TestLoader
from detection.MtcnnDetector import MtcnnDetector
from detection.detector import Detector
from detection.fcn_detector import FcnDetector
from face_recognition.face_recognition_cli import image_files_in_folder
def net(stage):
detectors = [None, None, None]
if stage in ['pnet', 'rnet', 'onet']:
modelPath = "/home/alex/face_recognize/mtcnn_fance-recognize/main/tmp/model/pnet"
a = [b[5:-6] for b in os.listdir(modelPath) if b.startswith('pnet-') and b.endswith('.index')]
maxEpoch = max(map(int, a)) # auto match a max epoch model
modelPath = os.path.join(modelPath, "pnet-%d" % (maxEpoch))
print("Use PNet model: %s" % (modelPath))
detectors[0] = FcnDetector(P_Net, modelPath)
if stage in ['rnet', 'onet']:
modelPath = "/home/alex/face_recognize/mtcnn_fance-recognize/main/tmp/model/rnet"
a = [b[5:-6] for b in os.listdir(modelPath) if b.startswith('rnet-') and b.endswith('.index')]
maxEpoch = max(map(int, a))
modelPath = os.path.join(modelPath, "rnet-%d" % (maxEpoch))
print("Use RNet model: %s" % (modelPath))
detectors[1] = Detector(R_Net, 24, 1, modelPath)
if stage in ['onet']:
modelPath = "/home/alex/face_recognize/mtcnn_fance-recognize/main/tmp/model/onet"
a = [b[5:-6] for b in os.listdir(modelPath) if b.startswith('onet-') and b.endswith(