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

Fix TIFF processing. Add tests to prevent regression in OCR for gif, jpg, jp2, tiff, webp #587

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix the TIFF to PDF conversion command. Add TIFF test.
  • Loading branch information
catileptic committed Feb 28, 2024
commit d701931c1462850bb41a7d29e1da6818543ed254
3 changes: 2 additions & 1 deletion ingestors/media/tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def ingest(self, file_path, entity):
entity.schema = model.get("Pages")
pdf_path = self.make_work_file("tiff.pdf")
self.exec_command(
"tiff2pdf", file_path, "-x", "300", "-y", "300", "-o", pdf_path
"tiff2pdf", file_path, "-n", "-j", "-x", "300", "-y", "300", "-o", pdf_path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why TIFF ingestion was previously failing with these to options enabled? It’s not obvious to me what they had an impact and why removing them fixes the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, did you figure out why only some TIFF files were affected and others not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tillprochaska added a thorough explanation in the PR description, let me know if it is informative

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanation, this was really helpful.

One follow up question: My understanding of TIFF is very limited, but as TIFF can have multiple pages etc. and apparently embed image data using other image formats, is it possible that a TIFF file contains both JPEG compressed image data as well as other data?

)
self.assert_outfile(pdf_path)

self.pdf_alternative_extract(entity, pdf_path, self.manager)
48 changes: 34 additions & 14 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def test_tesseract_ocr_regression(self):
"content": "This is text inside a GIF image",
"mime_type": "image/gif",
},
# "tiff": {
# "file": "regression_tiff.tiff",
# "content": "Debian -- Packages",
# "mime_type": "image/tiff",
# },
"tiff": {
"file": "regression_tiff.tiff",
"content": "Debian -- Packages",
"mime_type": "image/tiff",
},
"webp": {
"file": "regression_webp.webp",
"content": "Debian -- Packages",
Expand All @@ -49,18 +49,38 @@ def test_tesseract_ocr_regression(self):
for test_image_type in test_data:
fixture_path, entity = self.fixture(test_data[test_image_type]["file"])
self.manager.ingest(fixture_path, entity)
self.assertIn(
test_data[test_image_type]["content"],
entity.first("bodyText"),
f"Test failed for {test_data[test_image_type]['file']}",
)
self.assertEqual(
entity.first("mimeType"),
test_data[test_image_type]["mime_type"],

emitted_image_entities = [
x
for x in self.get_emitted()
if "mimeType" in x.properties and "image" in x.first("mimeType")
]

# Have entities been emitted with a mime type that contains "image"?
self.assertTrue(
len(emitted_image_entities) != 0,
f"Test failed for {test_data[test_image_type]['file']}",
)
image_entity = emitted_image_entities.pop()

# Is the processing status of the entity == SUCCESS?
self.assertEqual(
entity.first("processingStatus"),
image_entity.first("processingStatus"),
self.manager.STATUS_SUCCESS,
f"Test failed for {test_data[test_image_type]['file']}",
)

# Does either the bodyText prop or the indexText prop contain
# the text resulted from OCR?
try:
self.assertIn(
test_data[test_image_type]["content"],
image_entity.first("bodyText"),
f"Test failed for {test_data[test_image_type]['file']}",
)
except TypeError:
self.assertIn(
test_data[test_image_type]["content"],
image_entity.first("indexText"),
f"Test failed for {test_data[test_image_type]['file']}",
)
Loading