Skip to content

Commit

Permalink
test for #686
Browse files Browse the repository at this point in the history
  • Loading branch information
kba committed Apr 26, 2021
1 parent 0a34771 commit 076ef5c
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 0 deletions.
Binary file added tests/data/sample-features/foo0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/sample-features/foo1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/sample-features/foo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/sample-features/foo3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/sample-features/foo4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/sample-features/foo5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/data/sample-features/foo6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions tests/data/sample-features/image_features.page.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PcGts xmlns="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15 http://schema.primaresearch.org/PAGE/gts/pagecontent/2013-07-15/pagecontent.xsd" pcGtsId="PAGE_0017_PAGE">
<Metadata>
<Creator>OCR-D</Creator>
<Created>2016-09-20T11:09:27.041+02:00</Created>
<LastChange>2018-04-25T17:44:49.605+01:00</LastChange>
</Metadata>
<Page imageFilename="foo0.png" imageWidth="1457" imageHeight="2083" type="content">
<AlternativeImage filename="foo1.png" comments="binarized"/>
<AlternativeImage filename="foo2.png" comments="dewarped,cropped"/>
<AlternativeImage filename="foo3.png" comments="cropped,binarized"/>
<AlternativeImage filename="foo4.png" comments="cropped,dewarped,binarized,despeckled,deskewed"/>
<AlternativeImage filename="foo5.png" comments="cropped,dewarped,despeckled"/>
<Border><Coords points="101,232 932,232 932,1794 101,1794"/></Border>
</Page>
</PcGts>
56 changes: 56 additions & 0 deletions tests/data/sample-features/mets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<mets:mets xmlns:mets="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/version17/mets.v1-7.xsd http://www.loc.gov/mix/v10 http://www.loc.gov/standards/mix/mix10/mix10.xsd">
<mets:metsHdr CREATEDATE="2021-04-26T13:16:13.397420">
<mets:agent TYPE="OTHER" OTHERTYPE="SOFTWARE" ROLE="CREATOR">
<mets:name>ocrd/core v2.23.3</mets:name>
</mets:agent>
</mets:metsHdr>
<mets:dmdSec ID="DMDLOG_0001">
<mets:mdWrap MDTYPE="MODS">
<mets:xmlData>
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3">
</mods:mods>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:amdSec ID="AMD">
</mets:amdSec>
<mets:fileSec>
<mets:fileGrp USE="FOO">
<mets:file MIMETYPE="application/vnd.prima.page+xml" ID="foo0">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="image_features.page.xml"/>
</mets:file>
<mets:file MIMETYPE="image/png" ID="foo1">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="foo1"/>
</mets:file>
<mets:file MIMETYPE="image/png" ID="foo2">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="foo2"/>
</mets:file>
<mets:file MIMETYPE="image/png" ID="foo3">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="foo3"/>
</mets:file>
<mets:file MIMETYPE="image/png" ID="foo4">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="foo4"/>
</mets:file>
<mets:file MIMETYPE="image/png" ID="foo5">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="foo5"/>
</mets:file>
<mets:file MIMETYPE="image/png" ID="foo6">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="foo6"/>
</mets:file>
</mets:fileGrp>
</mets:fileSec>
<mets:structMap TYPE="PHYSICAL">
<mets:div TYPE="physSequence">
<mets:div TYPE="page" ID="page1">
<mets:fptr FILEID="foo0"/>
<mets:fptr FILEID="foo1"/>
<mets:fptr FILEID="foo2"/>
<mets:fptr FILEID="foo3"/>
<mets:fptr FILEID="foo4"/>
<mets:fptr FILEID="foo5"/>
<mets:fptr FILEID="foo6"/>
</mets:div>
</mets:div>
</mets:structMap>
</mets:mets>
10 changes: 10 additions & 0 deletions tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,16 @@ def test_image_from_page_basic(self):
img, info, exif = ws.image_from_page(pcgts.get_Page(), page_id='PHYS_0017')
self.assertEquals(info['features'], 'binarized,clipped')

def test_image_feature_selectoro(self):
with pushd_popd('tests/data/sample-features'):
ws = self.resolver.workspace_from_url('mets.xml')
with open('image_features.page.xml', 'r') as f:
pcgts = parseString(f.read().encode('utf8'), silence=True)
img, info, exif = ws.image_from_page(pcgts.get_Page(), page_id='page1', feature_selector='dewarped')
self.assertEquals(info['features'], 'cropped,dewarped,binarized,despeckled,deskewed')
img, info, exif = ws.image_from_page(pcgts.get_Page(), page_id='page1', feature_selector='dewarped', feature_filter='binarized')
self.assertEquals(info['features'], 'cropped,dewarped,despeckled')

def test_downsample_16bit_image(self):
with pushd_popd(tempdir=True) as tempdir:
with gzip_open(join(dirname(__file__), 'data/OCR-D-IMG_APBB_Mitteilungen_62.0002.tif.gz'), 'rb') as gzip_in:
Expand Down

0 comments on commit 076ef5c

Please sign in to comment.