파이썬 얼굴정렬 실행기

조회수 574회
import matplotlib.pyplot as plt
import matplotlib.image as img
from imutils.face_utils import FaceAligner
from imutils.face_utils import rect_to_bb
import argparse
import imutils
import dlib
import cv2
import numpy as np



img = img.imread("C:/Users/gusdn/7.jpg")
dst = cv2.detailEnhance(img,sigma_s = 10, sigma_r=0.15)

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('C:/Users/gusdn/face/shape_predictor_68_face_landmarks.dat')
fa = FaceAligner(predictor, desiredFaceWidth=256)
image = cv2.cvtColor(dst, cv2.COLOR_BGR2RGB)
image = imutils.resize(image, width=300)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
rects = detector(gray, 2)
for rect in rects:
    (x, y, w, h) = rect_to_bb(rect)
    faceOrig = imutils.resize(image[y:y + h, x:x + w], width=256)
    faceAligned = fa.align(dst, gray, rect) 




protoPath = "C:/Users/gusdn/face/deploy.prototxt.txt"
modelPath = "C:/Users/gusdn/face/res10_300x300_ssd_iter_140000.caffemodel"
detector = cv2.dnn.readNetFromCaffe(protoPath, modelPath)
predictor = dlib.shape_predictor("C:/Users/gusdn/face/shape_predictor_68_face_landmarks.dat")

fa = FaceAligner(predictor, desiredFaceWidth=256)

image = cv2.cvtColor(dst, cv2.COLOR_BGR2RGB)

image = imutils.resize(image, width=300)
cv2.imshow("image", image)
(h, w) = image.shape[:2]

rgb = image.copy()
grey = cv2.cvtColor(rgb, cv2.COLOR_BGR2GRAY)
imageBlob = cv2.dnn.blobFromImage(rgb, 1.0, (300, 300), (104.0, 177.0, 123.0), swapRB=False, crop=False)

detector.setInput(imageBlob)
detections = detector.forward()

for i in range(0, detections.shape[2]):
    confidence = detections[0, 0, i, 2]

    if confidence > 0.5:
        box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
        (startX, startY, endX, endY) = box.astype("int")

        face = image[startY:endY, startX:endX]

        r = dlib.rectangle(int(startX), int(startY), int(endX), int(endY))
        faceAligned = fa.align(rgb, grey, r)
        cv2.imshow("FACE ALIGNED {:d}".format(i), faceAligned)
k = cv2.waitKey(0)
if k == 27:
    cv2.destroyAllWindows()

얼굴 정렬 실행기 코드를 짯는데 이미지 위처럼 여러가지 창이 뜹니다 완벽하게 정렬된 얼굴만 뜨게 하려면 어떤걸 고쳐야 할까요??

  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)