amebalabs / TRex

Copy any text on your screen, stop retyping.
https://trex.ameba.co
MIT License
1.17k stars 36 forks source link

Add OCR from file #23

Closed luckman212 closed 1 year ago

luckman212 commented 1 year ago

Trex is amazing! 🦖 🚀

My one gripe is not being able to use the command-line app to perform OCR on an image that's already on my disk.

e.g.

/Applications/TRex.app/Contents/MacOS/cli/trex --file /path/too/qrcode.png

My kludgy workaround for this is copying the image to the clipboard with impbcopy and then using the --clipboard option. But that's pretty ugly.

impbcopy /path/to/qrcode.png
/Applications/TRex.app/Contents/MacOS/cli/trex --clipboard
melonamin commented 1 year ago

Yeah, I had this in longterm to-do list for awhile now, let me work on that.

melonamin commented 1 year ago

@luckman212 give it a try please https://github.com/amebalabs/TRex/releases/tag/v1.6.0-BETA-1

luckman212 commented 1 year ago

@melonamin Hmm. It's not working for me. It does not appear to do anything... no error message, nothing is printed or copied to the clipboard. ?

example image foo

/Applications/TRex.app/Contents/MacOS/cli/trex --image-path /path/to/that.png
melonamin commented 1 year ago

Yeah, I see. Looks like #25 works but the CLI doesn't, looking into it

luckman212 commented 1 year ago

Thanks, I tried a different image with normal text in it, also didn't seem to do anything. Will stay tuned for any update!

melonamin commented 1 year ago

@luckman212 This one should work, plz try TRex.app.zip

luckman212 commented 1 year ago

@melonamin Hmm. Sorry but no, that's not working for me either... tried a regular PNG image containing text as well as a QR code. Output is nothing, nothing on console, nothing on clipboard.

melonamin commented 1 year ago

Just so you don't think I'm crazy

https://user-images.githubusercontent.com/222100/193422485-e4d417bf-8c93-45d7-9808-1f1869b5e9a6.mp4

melonamin commented 1 year ago

Ok, I tested it on another machine and it doesn't work. As usual it is the case of "works fine on my machine!". Digging.

melonamin commented 1 year ago

Hey @luckman212

So, macOS Sandboxing is a pain in the ... I've changed the cli to accept files from stdin, you can run it like this:

cat /path/to/image | /Applications/TRex.app/Contents/MacOS/cli/trex -i

Let me know if this works for you. TRex.app.zip

luckman212 commented 1 year ago

Hi @melonamin Yes, this test build works 🎉 passing the image file directly via stdin. But I want to point to a simple repo I found that does work fine taking file args directly. I didn't encounter any sandbox issues. Maybe you've already seen it: tinyocr (if not, could be useful to see how they're doing it)

melonamin commented 1 year ago

could be useful to see how they're doing it

They are not doing anything and they don't need to, since they don't ditribute a binary and ask you to build it yourself. In this case you don't have any restrictions.

In case of TRex I'm ditributing in two channels:

First one requires hardening, signing and notarization, otherwise macOS will yell at you when you try launching the app. The App Store one requires Sanboxing - which limits files access severely. You can do a whole dance with "Require Full Disk Access" permissions but I don't think it worth it.

Anyway, it is more about how it packaged and distributed.

luckman212 commented 1 year ago

I understand, forgot you are distributing on MAS as well. In that case, yes this works perfectly & thank you again for working this out!