Page 373 - MDP2020-3
P. 373
················································································ 명장양성프로젝트 【MDP】 과제발표회 자료집 Ⅲ | 367
print("값이 없습니다")
return None
Labels = np.asarray(Labels, dtype=np.int32)
# 모델 생성
model = cv2.face.LBPHFaceRecognizer_create()
# 학습
model.train(np.asarray(Training_Data), np.asarray(Labels))
# 학습 모델 리턴
return model
# 여러 사용자 학습
def trains():
# faces 폴더의 하위 폴더를 학습
data_path = 'faces/'
# 폴더만 색출
model_dirs = [f for f in listdir(data_path) if isdir(join(data_path, f))]
# 학습 모델 저장할 딕셔너리
models = {}
# 각 폴더에 있는 얼굴들 학습
for model in model_dirs:
print('학습 시작함 :' + model)
# 학습 시작
result = train(model)
# 학습이 안되었다면 패스!
if result is None:
print('학습 실패함 :' + model)
continue
# 학습되었으면 저장
print('학습 완료함 :' + model)
models[model] = result
# 학습된 모델 딕셔너리 리턴
return models
# 얼굴 검출
def face_detector(img, size=0.5):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)