Ejemplo n.º 1
0
def crop(path="./TESTFORMICHAEL/", dest="./TestCrop/", pixel=128):
    """
    Crop all of the images in each of the folders in the root directory
    and insert those images into a folder named "crop" in each image folder.

    path (string): Root directory where image folders are located in.
    pixel (int): the output size of one dimension of the cropped images (squares).

    returns None
    """
    reject_dir = "./reject"
    # Make a reject folder
    if os.path.isdir(reject_dir) == False:
        os.mkdir(reject_dir)

    # For every person
    for p_id in os.listdir(path):
        in_dir = path + p_id
        crp_dir = dest + p_id
        err_dir = dest + p_id + "\\reject"

        # Ignore empty directories
        if not os.listdir(in_dir):
            print("Skipping empty directory")

        else:
            # Make a new folder if it doesn't exist
            if os.path.isdir(crp_dir) == False:
                os.mkdir(crp_dir)

            # Crop all the images in the folder and store them in "crop"
            ac.main(input_d=in_dir,
                    output_d=crp_dir,
                    reject_d=reject_dir,
                    fheight=pixel,
                    fwidth=pixel,
                    facePercent=90)
Ejemplo n.º 2
0
def test_main_overwrites_when_no_output(mock_crop, integration):
    mock_crop.return_value = None
    assert mock_crop.call_count == 0
    main('tests/test', None)
    assert mock_crop.call_count == 9