Page 269 - MDP2020-3
P. 269
················································································ 명장양성프로젝트 【MDP】 과제발표회 자료집 Ⅲ | 263
cv2.imshow('Face Cropper', face)
else:
print("얼굴이 검출되지 않았습니다")
pass
if count == 100:
break
cap.release()
cv2.destroyAllWindows()
print(str(count) + "장의 사진 수집을 완료했습니다")
def train(pName):
data_path = 'faces/' + pName + '/'
# 파일만 리스트로 만듬
face_pics = [f for f in listdir(data_path) if isfile(join(data_path, f))]
Training_Data, Labels = [], []
for i, files in enumerate(face_pics):
image_path = data_path + face_pics[i]
images = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# 이미지가 아니면 패스
if images is None:
continue
Training_Data.append(np.asarray(images, dtype=np.uint8))
Labels.append(i)
if len(Labels) == 0:
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/'