예제 #1
0
    def process_image(self, filename):
        try:
            image = cv2.imread(filename)
            for (idx, face) in enumerate(crop_faces(image)):
                if idx > 0 and self.arguments.verbose:
                    print('- Found more than one face!')
                    self.verify_output = True

                self.process_face(face, idx, filename)
                self.faces_detected = self.faces_detected + 1
        except Exception as e:
            print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
예제 #2
0
    def process_image(self, filename):
        try:
            image = cv2.imread(filename)
            for (idx, face) in enumerate(crop_faces(image)):
                if idx > 0 and self.arguments.verbose:
                    print('- Found more than one face!')
                    self.verify_output = True

                new_face = convert_one_image(cv2.resize(face.image, (256, 256)), self.arguments.model_dir)
                image[slice(face.y, face.y + face.h), slice(face.x, face.x + face.w)] = cv2.resize(new_face, (face.w, face.h))
                self.faces_detected = self.faces_detected + 1
            output_file = self.output_dir / Path(filename).name
            cv2.imwrite(str(output_file), image)
        except Exception as e:
            print('Failed to extract from image: {}. Reason: {}'.format(filename, e))
예제 #3
0
import cv2
import numpy
from pathlib import Path

from lib.utils import get_image_paths, get_folder
from lib.faces_detect import crop_faces
from lib.faces_process import convert_one_image

output_dir = get_folder('modified')

images_SRC = get_image_paths('original')

for fn in images_SRC:
    image = cv2.imread(fn)
    for face in crop_faces(image):
        new_face = convert_one_image(cv2.resize(face.image, (256, 256)))
        image[slice(face.y, face.y + face.h),
              slice(face.x, face.x + face.w)] = cv2.resize(
                  new_face, (face.w, face.h))

    output_file = output_dir / Path(fn).name
    cv2.imwrite(str(output_file), image)
예제 #4
0
import cv2
import numpy
from pathlib import Path

from lib.utils import get_image_paths, get_folder
from lib.faces_detect import crop_faces
from lib.faces_process import convert_one_image

output_dir = get_folder('modified')

images_SRC = get_image_paths('original')

for fn in images_SRC:
    image = cv2.imread(fn)
    for ((x, w), (y, h), face) in crop_faces(image):
        new_face = convert_one_image(cv2.resize(face, (256, 256)))
        image[slice(y, y + h), slice(x, x + w)] = cv2.resize(new_face, (w, h))

    output_file = output_dir / Path(fn).name
    cv2.imwrite(str(output_file), image)
예제 #5
0
import cv2
import numpy
from pathlib import Path

from lib.utils import get_image_paths, get_folder
from lib.faces_detect import crop_faces

output_dir = get_folder('extract')

images_SRC = get_image_paths('src')

for fn in images_SRC:
    image = cv2.imread(fn)
    for (idx, (p1, p2, img)) in enumerate(crop_faces(image)):
        final = cv2.resize(img, (256, 256))
        output_file = output_dir / Path(fn).stem
        cv2.imwrite(str(output_file) + str(idx) + Path(fn).suffix, final)