nicooprat / alfred-ocr

Take a snapshot and recognize text
MIT License
65 stars 7 forks source link

Leptonica Error in fopenReadStream: file not found: #14

Open mmroczka opened 7 months ago

mmroczka commented 7 months ago

Ok, I've got a weird one for you. Not super sure if this is a local error or something new. When I OCR something, I get an error in the notification rather than translated text. It looks like:

Leptonica Error in fopenReadStream: file not found: ocr_snapshot.png
Leptonica Error in findFileFormat: image file not found: /tmp/ocr_snapshot.png
Leptonica Error in fopenReadStream: file not found: ‰PNG
Leptonica Error in pixRead: image file not found: ‰PNG
Image file ‰PNG cannot be read!
Error during processing.

Seems to have started when I upgraded to from Alfred 4 to 5. I doubled checked that tesseract works on its own and that screencapture works on its own. Running screencapture -i /tmp/ocr_snapshot.png successfully creates an image successfully, but when I try the tesseract command it gives the same output. It appears tesseract can't see the tmp file? I modified the script to create the file in ~/Downloads but I'm not sure why tesseract wouldn't have the permissions but screencapture would. Any ideas?

The full debug log in Alfred is below for reference:

[19:14:02.981] OCR[Keyword] Processing complete
[19:14:02.982] OCR[Keyword] Passing output '' to Run Script
[19:14:05.918] OCR[Run Script] Processing complete
[19:14:05.919] OCR[Run Script] Passing output 'Leptonica Error in fopenReadStream: file not found: ocr_snapshot.png
Leptonica Error in findFileFormat: image file not found: /tmp/ocr_snapshot.png
Leptonica Error in fopenReadStream: file not found: ‰PNG
Leptonica Error in pixRead: image file not found: ‰PNG
Image file ‰PNG cannot be read!
Error during processing.
' to Copy to Clipboard
[19:14:05.921] OCR[Run Script] Passing output 'Leptonica Error in fopenReadStream: file not found: ocr_snapshot.png
Leptonica Error in findFileFormat: image file not found: /tmp/ocr_snapshot.png
Leptonica Error in fopenReadStream: file not found: ‰PNG
Leptonica Error in pixRead: image file not found: ‰PNG
Image file ‰PNG cannot be read!
Error during processing.
' to Post Notification
[19:15:35.285] OCR[Keyword] Processing complete
[19:15:35.293] OCR[Keyword] Passing output '' to Run Script
[19:15:39.251] OCR[Run Script] Processing complete
[19:15:39.252] OCR[Run Script] Passing output 'Leptonica Error in fopenReadStream: file not found: ocr_snapshot.png
Leptonica Error in findFileFormat: image file not found: /tmp/ocr_snapshot.png
Leptonica Error in fopenReadStream: file not found: ‰PNG
Leptonica Error in pixRead: image file not found: ‰PNG
Image file ‰PNG cannot be read!
Error during processing.
' to Copy to Clipboard
[19:15:39.261] OCR[Run Script] Passing output 'Leptonica Error in fopenReadStream: file not found: ocr_snapshot.png
Leptonica Error in findFileFormat: image file not found: /tmp/ocr_snapshot.png
Leptonica Error in fopenReadStream: file not found: ‰PNG
Leptonica Error in pixRead: image file not found: ‰PNG
Image file ‰PNG cannot be read!
Error during processing.
' to Post Notification
nicooprat commented 7 months ago

Hi,

I won't have time to debug this, can you check which version you have? It's still working for me with:

$ tesseract -v

tesseract 5.3.2
 leptonica-1.82.0
  libgif 5.2.1 : libjpeg 8d (libjpeg-turbo 2.1.5.1) : libpng 1.6.40 : libtiff 4.5.1 : zlib 1.2.11 : libwebp 1.3.1 : libopenjp2 2.5.0
 Found NEON
 Found libarchive 3.6.2 zlib/1.2.11 liblzma/5.4.1 bz2lib/1.0.8 liblz4/1.9.4 libzstd/1.5.4
 Found libcurl/8.1.2 SecureTransport (LibreSSL/3.3.6) zlib/1.2.11 nghttp2/1.45.1

Im still on Mac OS Monterey though (12.7.1).

You may want to ask the question on the Alfred forum too: https://www.alfredforum.com/topic/12006-ocr-extract-text-from-snapshot/

lvqq commented 7 months ago

I encountered the same problem. It could be due to the system permissions of the /tmp directory when under multi-user operating systems. Changing the path in the script to this could solve my issue: image

And I am on Mac OS 14.1.1 my tesseract version is:

$ tesseract -v
tesseract 5.3.3
 leptonica-1.84.0
  libgif 5.2.1 : libjpeg 8d (libjpeg-turbo 3.0.0) : libpng 1.6.40 : libtiff 4.6.0 : zlib 1.2.12 : libwebp 1.3.2 : libopenjp2 2.5.0
 Found NEON
 Found libarchive 3.7.2 zlib/1.2.12 liblzma/5.4.4 bz2lib/1.0.8 liblz4/1.9.4 libzstd/1.5.5
 Found libcurl/8.1.2 SecureTransport (LibreSSL/3.3.6) zlib/1.2.12 nghttp2/1.55.1
qnblackcat commented 7 months ago

I encountered the same problem. It could be due to the system permissions of the /tmp directory when under multi-user operating systems. Changing the path in the script to this could solve my issue: image

And I am on Mac OS 14.1.1 my tesseract version is:

$ tesseract -v
tesseract 5.3.3
 leptonica-1.84.0
  libgif 5.2.1 : libjpeg 8d (libjpeg-turbo 3.0.0) : libpng 1.6.40 : libtiff 4.6.0 : zlib 1.2.12 : libwebp 1.3.2 : libopenjp2 2.5.0
 Found NEON
 Found libarchive 3.7.2 zlib/1.2.12 liblzma/5.4.4 bz2lib/1.0.8 liblz4/1.9.4 libzstd/1.5.5
 Found libcurl/8.1.2 SecureTransport (LibreSSL/3.3.6) zlib/1.2.12 nghttp2/1.55.1

Can confirm this works, use ~/tmp/... is better IMO

paulrudy commented 5 months ago

Can confirm this works, use ~/tmp/... is better IMO

The original /tmp allowed for the periodic cleaning by MacOS of temporary files. I wanted to keep that behavior. So, since /tmp is a symlink to /private/tmp, I made a ~/tmp a symlink: ln -s /private/tmp ~/tmp.

(And updated the /tmp references to ~/tmp in the bash script.)

This works. I'm not too familiar with all the ins and outs of permissions, but for whatever reason, it seems to be the permissions of the symlink (permissions of MacOS's /tmp vs permissions of the ~/tmp I created) that make the difference, since both symlinks point to the same private/tmp folder.