def original_image_processing(filename):
    input_img = plt.imread(filename)
    trained_file = data.lbp_frontal_face_cascade_filename()

    # Initialize the detector cascade.
    detector = Cascade(trained_file)

    # Detect faces with scale factor to 1.2 and step ratio to 1
    detected = detector.detect_multi_scale(img=input_img,
                                           scale_factor=1.2,
                                           step_ratio=1,
                                           min_size=(50, 50),
                                           max_size=(200, 200))
    original_img = np.copy(input_img)
    original_img = input_img / 255
    i = 0
    for d in detected:
        i += 1
        # Obtain the face cropped from detected coordinates
        face = get_face_coordinates(d, input_img)
        print("Face -", i)
        plt.imshow(face)
        plt.show()
        blurred_face = gaussian(face, multichannel=True, sigma=8)
        print("Blurred Face -", i)
        plt.imshow(blurred_face)
        plt.show()
        resulting_image = merge_with_original(d, original_img, blurred_face)

    return resulting_image
def re():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    cwd = os.getcwd()
    print(cwd)
    os.chdir(dir_path)
    image1 = ""
    image = io.imread("somefilename.jpg")
    # Load the trained file from data
    trained_file = data.lbp_frontal_face_cascade_filename()

    # Initialize the detector cascade
    detector = Cascade(trained_file)
    detected = detector.detect_multi_scale(img=image,
                                           scale_factor=1.2,
                                           step_ratio=1,
                                           min_size=(50, 50),
                                           max_size=(100, 100))
    resulting_image = image
    for detected_face in detected:
        face = get_face(image, detected_face)
        blurred_face = gaussian(face, multichannel=True, sigma=10)
        #show_image(face)
        resulting_image = merge_blurry_face(image, detected_face, blurred_face)
    show_image(resulting_image, "Blurred faces")
    os.remove("somefilename.jpg")
    return 'Its Done!'
Beispiel #3
0
    def load_weight(self, weight_path: Path) -> Any:
        if weight_path.exists():
            # TODO: Implement loading weight file from local path
            pass
        else:
            logger.warning("No existing path was provided, using default weights")
            weight_path = skimage_data.lbp_frontal_face_cascade_filename()

        return weight_path
Beispiel #4
0
def test_detector_astronaut():

    # Load the trained file from the module root.
    trained_file = data.lbp_frontal_face_cascade_filename()

    # Initialize the detector cascade.
    detector = Cascade(trained_file)

    img = data.astronaut()

    detected = detector.detect_multi_scale(img=img,
                                           scale_factor=1.2,
                                           step_ratio=1,
                                           min_size=(60, 60),
                                           max_size=(123, 123))

    assert len(detected) == 1, 'One face should be detected.'
def test_detector_astronaut():

    # Load the trained file from the module root.
    trained_file = data.lbp_frontal_face_cascade_filename()

    # Initialize the detector cascade.
    detector = Cascade(trained_file)

    img = data.astronaut()

    detected = detector.detect_multi_scale(img=img,
                                           scale_factor=1.2,
                                           step_ratio=1,
                                           min_size=(60, 60),
                                           max_size=(123, 123))

    assert len(detected) == 1, 'One face should be detected.'
Beispiel #6
0
def face_detections(image,
                    scale_factor=1.1,
                    step_ratio=1.3,
                    min_size=(10, 10),
                    max_size=(400, 400)):
    # Load the trained file from data
    trained_file = data.lbp_frontal_face_cascade_filename()

    # Initialize the detector cascade
    detector = Cascade(trained_file)

    # Detect faces with min and max size of searching window
    detected_faces = detector.detect_multi_scale(
        img=image,
        scale_factor=scale_factor,
        step_ratio=step_ratio,
        min_size=min_size,
        max_size=max_size,
    )
    return detected_faces
Beispiel #7
0
    def fd():
        from skimage.feature import Cascade
        from skimage import data, color
        import matplotib.pyplot as plt
        from matplotlib.patches import Rectangle

        path = ''
        img = plt.imread(path)
        plt.axis('off')
        plt.imshow(img)

        train_set = data.lbp_frontal_face_cascade_filename()
        detector = Cascade(train_set)
        detected = detector.detect_multi_scale(img=img,
                                               scale_factor=1.2,
                                               step_ratio=1,
                                               min_size=(10, 10),
                                               max_size=(200, 200))
        print('Detected')

        def show_detected_face(result, detected, title="Detected Faces"):
            plt.imshow(result)
            img_desc = plt.gca()
            plt.set_cmap('gray')
            plt.title(title)
            plt.axis('off')

            for rec in detected:
                img_desc.add_patch(
                    Rectangle((rec['c'], rec['r']),
                              rec['width'],
                              rec['height'],
                              fill=False,
                              color='g',
                              line_width=3))
            plt.show()

        show_detected_face(img, detected)
leaves the clusters that have a same or bigger number of detections in them.

You should also take into account that false detections are inevitable and if
you want to have a really precise detector, you will have to train it yourself
using `OpenCV train cascade utility
<https://docs.opencv.org/2.4/doc/user_guide/ug_traincascade.html>`_.
"""

from skimage import data
from skimage.feature import Cascade

import matplotlib.pyplot as plt
from matplotlib import patches

# Load the trained file from the module root.
trained_file = data.lbp_frontal_face_cascade_filename()

# Initialize the detector cascade.
detector = Cascade(trained_file)

img = data.astronaut()

detected = detector.detect_multi_scale(img=img,
                                       scale_factor=1.2,
                                       step_ratio=1,
                                       min_size=(60, 60),
                                       max_size=(123, 123))

plt.imshow(img)
img_desc = plt.gca()
plt.set_cmap('gray')
Beispiel #9
0
#header files required
from skimage.feature import Cascade
from skimage import data
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

#Getting the image
path = ''
img = plt.imread(path)
plt.axis('off')
plt.imshow(img)

#reading the dataset for facial detection
train_set = data.lbp_frontal_face_cascade_filename()
detector = Cascade(train_set)
detected = detector.detect_multi_scale(img=img,
                                       scale_factor=1.2,
                                       step_ratio=1,
                                       min_size=(10, 10),
                                       max_size=(200, 200))


#function to draw a rectangle around the detected faces
def show_detected_face(result, detected, title='Detected Faces'):
    plt.imshow(result)
    desc = plt.gca()
    plt.set_cmap('gray')
    plt.title(title)
    plt.axis('off')
    for rec in detected:
        desc.add_patch(
leaves the clusters that have a same or bigger number of detections in them.

You should also take into account that false detections are inevitable and if
you want to have a really precise detector, you will have to train it yourself
using `OpenCV train cascade utility
<https://docs.opencv.org/doc/user_guide/ug_traincascade.html>`_.
"""

from skimage import data
from skimage.feature import Cascade

import matplotlib.pyplot as plt
from matplotlib import patches

# Load the trained file from the module root.
trained_file = data.lbp_frontal_face_cascade_filename()

# Initialize the detector cascade.
detector = Cascade(trained_file)

img = data.astronaut()

detected = detector.detect_multi_scale(img=img,
                                       scale_factor=1.2,
                                       step_ratio=1,
                                       min_size=(60, 60),
                                       max_size=(123, 123))

plt.imshow(img)
img_desc = plt.gca()
plt.set_cmap('gray')