Exemple #1
0
def read_and_crop_cv2_img(path):
    '''
    Read color images
    :param path: Path to image
    :return: Only returns color images
    '''
    img = cv2.imread(path, -1)

    if img is not None:
        if len(img.shape) != 3:
            return None

        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    '''bbs = cnn_face_detector(img, 1)
    if len(bbs) > 0:
        r = bbs[0].rect
        x = int(r.left())
        y = int(r.top())
        right = int(r.right())
        bottom = int(r.bottom())
        #y, right, bottom, x = bbs[0]
        bb = x, y, (right - x), (bottom - y)
        img = face_utils.crop_face_with_bb(img, bb)'''

    bbs = face_recognition.face_locations(img)
    if len(bbs) > 0:
        y, right, bottom, x = bbs[0]
        bb = x, y, (right - x), (bottom - y)
        img = face_utils.crop_face_with_bb(img, bb)
    return img
Exemple #2
0
    def _img_morph(self, img, expresion):
        bbs = face_recognition.face_locations(img)
        if len(bbs) > 0:
            y, right, bottom, x = bbs[0]
            bb = x, y, (right - x), (bottom - y)
            face = face_utils.crop_face_with_bb(img, bb)
            face = face_utils.resize_face(face)
        else:
            face = face_utils.resize_face(img)

        morphed_face = self._morph_face(face, expresion)

        return morphed_face
Exemple #3
0
    def _img_morph(self, img, expresion):
        bbs = face_recognition.face_locations(img)
        if len(bbs) > 0:
            y, right, bottom, x = bbs[0]
            bb = x, y, (right - x), (bottom - y)
            face = face_utils.crop_face_with_bb(img, bb)
            face = face_utils.resize_face(face)
        else:
            face = face_utils.resize_face(img)

        morphed_face = self._morph_face(face, expresion)

        return morphed_face
Exemple #4
0
    def modify_face(self, img, expresion):
        # get face part
        bbs = face_recognition.face_locations(img)
        if len(bbs) > 0:
            y, right, bottom, x = bbs[0]
            bb = x, y, (right - x), (bottom - y)
            face = face_utils.crop_face_with_bb(img, bb)
            face = face_utils.resize_face(face)
        else:
            face = face_utils.resize_face(img)  # 128x128

        # modify face by expression
        morphed_face = self._morph_face(face, expresion)

        return morphed_face
Exemple #5
0
    def _img_morph(self, img, expression):
        bbs = face_recognition.face_locations(img)
        if len(bbs) > 0:
            y, right, bottom, x = bbs[0]
            bb = x, y, (right - x), (bottom - y)
            face = face_utils.crop_face_with_bb(img, bb)
            face = face_utils.resize_face(face)
        else:
            face = face_utils.resize_face(img)

        img_cond = self.find_disriminator_regression(face)
        print('from discriminator: ', img_cond)

        morphed_face = self._morph_face(face, expression, img_cond)

        return morphed_face