Page 271 - MDP2020-3
P. 271
················································································ 명장양성프로젝트 【MDP】 과제발표회 자료집 Ⅲ | 265
ret, frame = cap.read()
# 얼굴 검출 시도
image, face = face_detector(frame)
try:
min_score = 999 # 가장 낮은 점수로 예측된 사람의 점수
min_score_name = "" # 가장 높은 점수로 예측된 사람의 이름
# 검출된 사진을 흑백으로 변환
face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
# 위에서 학습한 모델로 예측시도
for key, model in models.items():
result = model.predict(face)
if min_score > result[1]:
min_score = result[1]
min_score_name = key
# min_score 신뢰도이고 0에 가까울수록 자신과 같다는 뜻이다.
if min_score < 500:
confidence = int(100 * (1 - min_score / 300))
if confidence > 75: # 해당 사람일 때
print(min_score_name)
faceCnt += 1
pass
else: # 해당 사람이 아닐 때
print(min_score_name + "이 아닙니다")
pass
except: # 얼굴 검출 안됨
print("얼굴 검출 실패")
pass
if faceCnt >= 30: # 버튼 닫을 때 사용
faceCnt = 0
break
cap.release()
cv2.destroyAllWindows()
def convTk(strPath, width, height):
src = cv2.imread(strPath)
src = cv2.resize(src, (width, height))
img = cv2.cvtColor(src, cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)