Page 886 - 3-3
P. 886
xy_arrs.append((x,y,x+w,y+h))
# 얼굴 이미지를 저장
crop_imgs.append(ori_frame[y:y+h,x:x+w])
#label text and roi
for i in range(len(crop_imgs)):
# 얼굴 영역의 대한 정보를 읽음
xmin,ymin,xmax,ymax = xy_arrs[i]
# 얼굴 이미지를 읽음
crop_img = crop_imgs[i]
# 얼굴 이미지를 원본 이미지 색상으로 컬러 변환
crop_img = cv2.cvtColor(crop_img,cv2.COLOR_RGB2BGR)
# 학습된 graph 에 넣기 위해 numpy variable 로 변환
image_array = np.asarray(crop_img)
# 얼굴 이미지를 넣고 결과 도출
predictions = sess.run(softmax_tensor,{'DecodeJpeg:0':image_array})
#softmax 결과 중 가장 높은 확률의 index 를 가져옴
top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
# 해당 얼굴이 등록된 얼굴이 아닐 경우 얼굴인식 수행
if label_lines[top_k[0]] == "NONE":
continue
# 등록된 얼굴의 이름을 저장
detection_name = label_lines[top_k[0]]
# 얼굴 영역 사각형 출력
cv2.rectangle(frame,(xmin,ymin),(xmax,ymax),(0,255,0),2)
# 얼굴이 누구인지, % 출력
cv2.putText(frame, "%s:
%.2f%%"%(label_lines[top_k[0]],predictions[0][top_k[0]]*100),
(xmin,ymin-2),cv2.FONT_HERSHEY_SIMPLEX,1.0,(0,255,0),2)
# 두개의 코드는 MDP 때 보여드리기 위해 코드 추가
# 이미지 출력
cv2.imshow("Show",frame)
# 입력이 들어올때까지 대기
cv2.waitKey(0)
# 등록되지 않은 얼굴일 경우 빠져나옴
if detection_name != "NONE":
break
# 재검사를 위해 배열 초기화
crop_imgs=[]
xy_arrs=[]
#show
cv2.imshow("Show",frame)
#1ms delay
key=cv2.waitKey(1)
#q 를 입력하면 종료
if key & 0xFF == ord('q'):
- 886 -