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

Built in scanner does not set image DPI #23

Closed
qcasey opened this issue Dec 12, 2020 · 8 comments
Closed

Built in scanner does not set image DPI #23

qcasey opened this issue Dec 12, 2020 · 8 comments

Comments

@qcasey
Copy link
Collaborator

qcasey commented Dec 12, 2020

Another subset of #18 I suppose. Recently paperless-ng has started using OCRmyPDF (tested w/0.9.6), which fails when trying to process an image missing DPI.

Since each image from the app's scanner would be a different size, I'm not sure there's a way to set PAPERLESS_OCR_IMAGE_DPI=<num> to make this work properly (without ruining OCR of other scanned docs). Or perhaps there is, maybe @jonaswinkler could chime in here.

Otherwise, do you know if there is there way to put DPI info with edge_detection?

Logs when uploading an image (used my PR #22 for the moment):

webserver_1  | 192.168.1.231 - casey [11/Dec/2020:19:27:21 -0800] "POST /push HTTP/1.1" 302 0 "-" "Dart/2.10 (dart:io)"
webserver_1  | 19:27:21 [Q] INFO Enqueued 1
webserver_1  | 192.168.1.231 - casey [11/Dec/2020:19:27:21 -0800] "POST /api/documents/post_document/ HTTP/1.1" 200 4 "-" "Dart/2.10 (dart:io)"
webserver_1  | 19:27:21 [Q] INFO Process-1:2 processing [crop_1852.jpeg]
webserver_1  | INFO 2020-12-11 19:27:21,522 loggers Consuming crop_1852.jpeg
webserver_1  | WARNING 2020-12-11 19:27:21,534 loggers Error while getting DPI from image /tmp/paperless/paperless-upload-ed19kd8_: 'dpi'
webserver_1  | ERROR 2020-12-11 19:27:21,538 loggers Error while consuming document crop_1852.jpeg: Cannot produce archive PDF for image /tmp/paperless/paperless-upload-ed19kd8_, no DPI information is present in this image and OCR_IMAGE_DPI is not set.
webserver_1  | 19:27:21 [Q] ERROR Failed [crop_1852.jpeg] - Cannot produce archive PDF for image /tmp/paperless/paperless-upload-ed19kd8_, no DPI information is present in this image and OCR_IMAGE_DPI is not set. : Traceback (most recent call last):
webserver_1  |   File "/usr/src/paperless/src/documents/consumer.py", line 131, in try_consume_file
webserver_1  |     document_parser.parse(self.path, mime_type)
webserver_1  |   File "/usr/src/paperless/src/paperless_tesseract/parsers.py", line 147, in parse
webserver_1  |     f"Cannot produce archive PDF for image {document_path}, "
webserver_1  | documents.parsers.ParseError: Cannot produce archive PDF for image /tmp/paperless/paperless-upload-ed19kd8_, no DPI information is present in this image and OCR_IMAGE_DPI is not set.
webserver_1  | 
webserver_1  | During handling of the above exception, another exception occurred:
webserver_1  | 
webserver_1  | Traceback (most recent call last):
webserver_1  |   File "/usr/local/lib/python3.7/site-packages/django_q/cluster.py", line 436, in worker
webserver_1  |     res = f(*task["args"], **task["kwargs"])
webserver_1  |   File "/usr/src/paperless/src/documents/tasks.py", line 72, in consume_file
webserver_1  |     override_tag_ids=override_tag_ids)
webserver_1  |   File "/usr/src/paperless/src/documents/consumer.py", line 148, in try_consume_file
webserver_1  |     raise ConsumerError(e)
webserver_1  | documents.consumer.ConsumerError: Cannot produce archive PDF for image /tmp/paperless/paperless-upload-ed19kd8_, no DPI information is present in this image and OCR_IMAGE_DPI is not set.
@bauerj
Copy link
Owner

bauerj commented Dec 12, 2020

Hmm, this sounds tricky. I didn't even know you could store DPI information in jpeg files.

Some phones do provide depth information for camera images but I think this would be overkill. In the general case we could just assume the scanned document to be of A4 size (I guess Americans use a similarly sized paper format) and use that to estimate the DPI.

Of course this would be way off if the user scans a large billboard.

@jonaswinkler
Copy link

jonaswinkler commented Dec 12, 2020

Well, this is required so that paperless can make PDF documents from images with selectable text in them (which I believe is a good thing). It needs to know how big the pages should be.

Since we're talking about paper documents, I'd just default to A4 and calculate that from the image height. This will cover about 99% of all usage.

@bauerj
Copy link
Owner

bauerj commented Dec 12, 2020

Good, then that should be simple 👍

@jonaswinkler
Copy link

jonaswinkler commented Dec 12, 2020

After some thinking, I think I'll add that calculation to paperless itself for images. If no DPI information is available, assume A4. I just tried adding an image of a document created with this Office Lens app, and it does not work.

That should make it more compatible.

@bauerj
Copy link
Owner

bauerj commented Dec 12, 2020

Sounds good, then we need less work here 😄

jonaswinkler pushed a commit to jonaswinkler/paperless-ng that referenced this issue Dec 12, 2020
@jonaswinkler
Copy link

jonaswinkler commented Dec 12, 2020

Well, that was easy.

Edit: I'm kinda amazed by how good this entire setup works with these scanner apps, OCR and text embedding and all that.

@bauerj bauerj closed this as completed Dec 12, 2020
@qcasey
Copy link
Collaborator Author

qcasey commented Dec 12, 2020

Thanks guys, that was fast

@jonaswinkler
Copy link

New release with this fix is out.

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

3 participants