Skip to content

OCR on folder suddenly not working? #288

@ada-gianassi

Description

@ada-gianassi

This is my first issue I raise so apologies for any oversights. I've been using surya consistently over the last few days but today the same code as always started throwing me an error, I think stemming from this:

image, name, text_line = load_image(path)
Here, the code expects load_image to return three values: image, name, and text_line. However, based on the load_image function, it only returns two values:

def load_image(image_path):
    image = Image.open(image_path).convert("RGB")
    name = get_name_from_path(image_path)
    return [image], [name]

Indeed, when running

process = subprocess.run([
    "surya_ocr",
    yearbook_dir,
    "--langs", "en",
    "--debug",
    "--output_dir", "/content/drive/MyDrive"
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True)

it gives me this error:

STDERR: Traceback (most recent call last):
  File "/usr/local/bin/surya_ocr", line 8, in <module>
    sys.exit(ocr_text_cli())
             ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/surya/scripts/ocr_text.py", line 20, in ocr_text_cli
    loader = CLILoader(input_path, kwargs, highres=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/surya/scripts/config.py", line 20, in __init__
    self.load(highres)
  File "/usr/local/lib/python3.11/dist-packages/surya/scripts/config.py", line 34, in load
    images, names = load_from_folder(self.filepath, self.page_range)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/surya/input/load.py", line 59, in load_from_folder
    image, name, text_line = load_image(path)
    ^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 3, got 2)

Return code: 1

Hope this helps!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions