Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

IsADirectoryError: [Errno 21] Is a directory: How to use Pathlib correctly

image_folder = Path("path_to_image_folder")

def get_preprocessed_image(image_path: pathlib.Path) -> PIL.Image.Image:
    with image_path.open("rb") as image_input:
        return PIL.Image.open(io.BytesIO(pyabbyy.preprocess(image_input.read())))


def preprocess_image_folder_(image_folder: pathlib.Path) -> None:
    for image_path in tqdm.tqdm(list(image_folder.rglob("*.pdf"))):
        get_preprocessed_image(image_path).save(image_path)

pyabbyy.initialize_engine(
        "h8KSSy98TGLEint",
        "path_to_activation_token",
        "password",
        "path_to_profile.ini",
)

# Press the green button in the gutter to run the script.
if __name__ == '__main__':

    get_preprocessed_image(image_folder)

What is to be altered here? I want to preprocess folder of images. It is using ABBYY service.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Please include the full traceback of the error, to make it easier to see the issue for us.
My guess would be that you are calling get_preprocessed_image on image_folder, but that function expects a path to an image, not a folder.
Instead, call the other function:

if __name__ == '__main__':

    preprocess_image_folder_(image_folder)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading