Beispiel #1
0
    def detect_faces(self, frame):
        global tmp
        boxes = self.locate_faces(frame)
        if len(boxes) == 0:
            return []

        # faces found
        faces = []
        now = datetime.now()

        for i, box in enumerate(boxes):
            # extract face image from frame
            face_image = self.get_face_image(frame, box)

            # get aligned image
            aligned_image = face_alignment_dlib.get_aligned_face(
                self.predictor, face_image)

            filename = now.strftime('%Y%m%d_%H%M%S.%f')[:-3] + '.png'
            pathname = os.path.join(
                "/home/ubuntu/learningFile/train/" + args.capture, filename)

            tmp += 1
            cv2.imwrite(pathname, aligned_image)
        return faces
Beispiel #2
0
    def detect_faces(self, frame, filename):
        boxes = self.locate_faces(frame)  # 박스 locate
        if len(boxes) == 0:
            return []

        # faces found
        faces = []
        # now = datetime.now()  # 필요한가?
        # str_ms = now.strftime('%Y%m%d_%H%M%S.%f')[:-3] + '-'  # 필요한가?
        str_ms = filename

        for i, box in enumerate(boxes):
            # extract face image from frame
            face_image = self.get_face_image(frame, box)  # frame에서 박스에 있는 얼굴 이미지 추출

            # get aligned image
            aligned_image = face_alignment_dlib.get_aligned_face(self.predictor, face_image)  # 얼굴 (수평) 정렬

            # compute the encoding
            height, width = aligned_image.shape[:2]
            x = int(width / 3)
            y = int(height / 3)
            box_of_face = (y, x * 2, y * 2, x)  # 이 부분은 왜 박스를 이렇게 형성?
            encoding = face_recognition.face_encodings(aligned_image, [box_of_face])[0]
            # 파라미터 값을 설정해줄 필요가 있을듯
            face = Face(str_ms + "_" + str(i) + ".png", face_image, encoding)  # 파일이름 지정하여 파일 이름과 함께 얼굴 이미지와 인코딩 데이터를 저장해주는 부분인거같은데 이부분에서 원본도 저장되게 만들수 있나?
            face.location = box  # 얼굴 위치값?
           # cv2.imwrite(str_ms + str(i) + ".r.png", aligned_image)  # cv2를 이용해서 파일 저장
            faces.append(face)  # 얼굴을 추가해주는데 어디를 위해서? 데이터값? 을 위해서인듯
        return faces
Beispiel #3
0
    def detect_faces(self, frame):
        boxes = self.locate_faces(frame)
        if len(boxes) == 0:
            return []

        # faces found
        faces = []
        now = datetime.now()
        str_ms = now.strftime('%Y%m%d_%H%M%S.%f')[:-3] + '-'

        for i, box in enumerate(boxes):
            # extract face image from frame
            face_image = self.get_face_image(frame, box)

            # get aligned image
            aligned_image = face_alignment_dlib.get_aligned_face(
                self.predictor, face_image)

            # compute the encoding
            height, width = aligned_image.shape[:2]
            x = int(width / 3)
            y = int(height / 3)
            box_of_face = (y, x * 2, y * 2, x)
            encoding = face_recognition.face_encodings(aligned_image,
                                                       [box_of_face])[0]

            face = Face(str_ms + str(i) + ".png", face_image, encoding)
            face.location = box
            cv2.imwrite(str_ms + str(i) + ".r.png", aligned_image)
            faces.append(face)
        return faces