바뀜

둘러보기로 가기 검색하러 가기
641 바이트 추가됨 ,  2021년 10월 1일 (금) 16:29
20번째 줄: 20번째 줄:     
=== 얼굴 입력하기 ===
 
=== 얼굴 입력하기 ===
분류할 얼굴을 입력한다.<syntaxhighlight lang="python">
+
분류할 얼굴을 특정 디렉터리 안에 그림파일로 넣고, 이들의 특징을 담은 넘파이 배열을 descs.npy에 저장한다.
for name, img_path in img_paths.items():
+
 
    img_bgr = cv2.imread(img_path)
+
이는 최초에 얼굴에 대해 교육할 때만 사용한다.<syntaxhighlight lang="python">
    img_rgb = cv2.cvtColor(img_bgrk, cv2.COLOR_BGR2RGB)  # 나중에 이거 빼보자.
+
def educate():
   
+
    import os
    _, shape = find_face(img_rgb)
+
    path_dir = 'C:\\Users\\id843\\PycharmProjects\\AI_practice\\img\\to_recognize\\'
    descs[name] = encode_face(img_rgb, img_shapes)[0]
+
    img_list = os.listdir(path_dir)
      
+
    people = {}
np.save('img/descs.npy', descs)
+
    for name in img_list:
print(descs)
+
        img_bgr = cv2.imread(path_dir + name)
 +
        name = name.split('.')[0] # 확장자를 쳐내고 앞의 이름만 따온다.
 +
 
 +
        face = detector(img_bgr)[0]  # 얼굴 하나만 받는다.
 +
        dlib_shape = predictor(img_bgr, face)  # 특징점을 리턴받는다.
 +
        face_descriptor = facerec.compute_face_descriptor(img_bgr, dlib_shape)
 +
        people[name] = np.array(face_descriptor) # 연산을 위해 배열로 저장.
 +
 
 +
     np.save('img\descs.npy', people)
 
</syntaxhighlight>
 
</syntaxhighlight>
 
=== 함수정의 ===
 
=== 함수정의 ===
40번째 줄: 48번째 줄:  
|얼굴의 특징점을 찾아 배열로 반환한다.
 
|얼굴의 특징점을 찾아 배열로 반환한다.
 
|<syntaxhighlight lang="python">
 
|<syntaxhighlight lang="python">
def detect_faces(img):
+
def recognize_faces(img):
 +
    '''얼굴의 특징점을 찾아 기존의 기억된 인물들과 대조한다'''
 
     faces = detector(img, 1)
 
     faces = detector(img, 1)
 
     if len(faces) == 0:
 
     if len(faces) == 0:
66번째 줄: 75번째 줄:  
     if not ret:  # 잘 찍히면 ret은 True를 반환한다.
 
     if not ret:  # 잘 찍히면 ret은 True를 반환한다.
 
         break  # 프레임이 없다면 종료.
 
         break  # 프레임이 없다면 종료.
     detect_faces(img)
+
     recognize_faces(img)
 
     cv2.imshow('window', img)  # 창에 해당하는 이미지를 띄운다.
 
     cv2.imshow('window', img)  # 창에 해당하는 이미지를 띄운다.
 
     cv2.waitKey(1)  # 이게 있어야 창이 제대로 열린다.
 
     cv2.waitKey(1)  # 이게 있어야 창이 제대로 열린다.
 
</syntaxhighlight>
 
</syntaxhighlight>
 
[[분류:딥러닝 트레킹]]
 
[[분류:딥러닝 트레킹]]
익명 사용자

둘러보기 메뉴