Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in workspace - resolve_image_exif and resolve_image_as_pil if loading an external Image #838

Closed
mexthecat opened this issue Apr 13, 2022 · 3 comments

Comments

@mexthecat
Copy link
Contributor

mexthecat commented Apr 13, 2022

I got this Error Message:

...
  File "/var/scego/applications/docker/apps/python/venv/lib/python3.6/site-packages/ocrd/workspace.py", line 567, in image_from_page
    page_image_info = self.resolve_image_exif(page.imageFilename)
  File "/var/scego/applications/docker/apps/python/venv/lib/python3.6/site-packages/ocrd/workspace.py", line 405, in resolve_image_exif
    ocrd_exif = exif_from_filename(f.filename)
  File "/usr/lib/python3.6/tempfile.py", line 619, in __getattr__
    a = getattr(file, name)
AttributeError: '_io.BufferedRandom' object has no attribute 'filename'

If I try to load external Images with http for imageFilename in the page.xml

Like this:

...
<pc:Page imageFilename="http://link/to/image.jpg" imageWidth="2636" imageHeight="3781">
    <pc:ReadingOrder>
        <pc:OrderedGroup id="reading-order">
            <pc:RegionRefIndexed index="0" regionRef="region0000"/>
            <pc:RegionRefIndexed index="0" regionRef="region0001"/>
        </pc:OrderedGroup>
    </pc:ReadingOrder>
    <pc:TextRegion id="region0000">
...

I think the problem is in workspace.py on line 405

with download_temporary_file(image_url) as f:
    ocrd_exif = exif_from_filename(f.filename)

and on line 434

with download_temporary_file(image_url) as f:
    pil_image = Image.open(f.filename)

download_temporary_file is using NamedTemporaryFile - I can not see how you get filename from it.

Maybe change f.filename to f.name

@bertsky
Copy link
Collaborator

bertsky commented Apr 13, 2022

I fully agree – thanks for reporting @mexthecat!

Can you make that change into a PR and (install and) test it locally?

@bertsky
Copy link
Collaborator

bertsky commented May 5, 2022

@mexthecat your fix is in v2.33 and ocrd/all v2022-05-04 – can we close?

@mexthecat
Copy link
Contributor Author

Yes - perfect - thanx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants