Vis2 - Image to Text OCR()

Post your working scripts, libraries and tools for AHK v1.1 and older
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - OCR()

06 Jan 2018, 18:13

BoBo wrote:.
I'm unable to reproduce the errors you encountered. For testing, I typically use the following procedure.

1) Add #^w:: MsgBox % OCR("Untitled - Notepad") to the script and run it.
2) Open a new notepad window.
3) Type some things in the notepad window and press #^w.

The text in notepad should be equal to what the MsgBox displays.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Vis2 - OCR()

06 Jan 2018, 19:00

iseahound wrote:
BoBo wrote:.
I'm unable to reproduce the errors you encountered. For testing, I typically use the following procedure.

1) Add #^w:: MsgBox % OCR("Untitled - Notepad") to the script and run it.
2) Open a new notepad window.
3) Type some things in the notepad window and press #^w.

The text in notepad should be equal to what the MsgBox displays.
Thx for that quick response. I'll go to bed now (01:00AM here) but will do some further testing. Stay tuned 8-)
songdg
Posts: 512
Joined: 04 Oct 2017, 20:04

Re: Vis2 - OCR()

08 Jan 2018, 04:49

iseahound wrote:
songdg wrote:If it is possible to conbine the syntax text := OCR("C:\image.png") and text := OCR([0, 0, 430, 150]) to scan an image file in specific region.
I just updated a new version on my GitHub. Redownload it please.

Code: Select all

    #include Vis2.ahk
    MsgBox % OCR("https://i.stack.imgur.com/sFPWe.png", , [0,120,999,999]) ; [x, y, width, height]
   
^ There is a blank parameter, that is for a feature I have not created yet.
Thanks,I've tried your new version,but it seems no response.And I've been installed tesseract-ocr4.0 in my pc,is that the reason.
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - OCR()

08 Jan 2018, 05:39

songdg wrote:.
Could you tell me what you are doing, and what the result is? If you have some code that is not working please show me. Otherwise the above code should work, I just double checked it.

This line of code

Code: Select all

MsgBox % OCR("https://i.stack.imgur.com/sFPWe.png", , [0,325,999,400])
should say: brown dog jumped over the lazy fox.
Last edited by iseahound on 19 Mar 2018, 01:38, edited 1 time in total.
songdg
Posts: 512
Joined: 04 Oct 2017, 20:04

Re: Vis2 - OCR()

11 Jan 2018, 02:14

iseahound wrote:
songdg wrote:.
Could you tell me what you are doing, and what the result is? If you have some code that is not working please show me. Otherwise the above code should work, I just double checked it.

This line of code

Code: Select all

MsgBox % OCR("https://i.stack.imgur.com/sFPWe.png", , [0,330,999,400])
should say: brown dog jumped over the lazy fox.
I didn't known the reason why,perhaps I should tried it on another computer.Anyway thanks!
r2997790
Posts: 71
Joined: 02 Feb 2017, 02:46

Re: Vis2 - OCR()

18 Mar 2018, 03:48

HI Everyone....

Thanks to Iseahound for this _amazing_ fucntion! Super useful.

I'm trying to get it to work with Cyrillic without any luck -- it would be ideal as I don't speak or type Russian -- but need to 'capture' some Russian text. I wouldn't know how to type the characters on the keyboard so this OCR function would be the perfect solution.

Does anyone know if it is possible for it work with foreign character sets?

I've tried to set my keyboard to Russian but when Vis2 parses the text it doesn't paste the right characters to the clipboard -- I am not sure if that is because it's trying to map to Western characters or perhaps it just doesn't recognise the text?

********************************************** Update **********************************************

I've read that Vis2 using Tesseract and I've found the Russian and Ukrainian language files to train the data here: https://github.com/tesseract-ocr/tessdata_best

But I am not sure how to 'active' these libraries / get Vis2 to use this data when analysing the image snippet.

Does anyone have any idea?

Many thanks
R
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - OCR()

19 Mar 2018, 01:24

Additional Language support added.

Using Additional Languages
Go to https://github.com/tesseract-ocr/tessdata_best and place your desired languages in bin/tessdata_best.
Go to https://github.com/tesseract-ocr/tessdata_fast and place your desired languages in bin/tessdata_fast.

Fast is used in the interactive GUI implementation, while best will be used for othe cases. See below for what I mean.

Code: Select all

#c:: OCR(, "fra")      ; French (requires fast fra.traineddata)
#x:: OCR(, "eng+fra")  ; English and French

Code: Select all

MsgBox % OCR("https://i.imgur.com/T7WMxMs.png", "rus+eng")  ; Requires best eng.traineddata and rus.traineddata.
Tested only on my computer. If there are errors, let me know the exact steps to reproduce them.


EDIT: the text you should get

Code: Select all

Да, я и дальше буду
выбирать свое чудо!

Yes, and further | will
choose my (own) miracle!
r2997790
Posts: 71
Joined: 02 Feb 2017, 02:46

Re: Vis2 - OCR() - Update: Additional Language Support

19 Mar 2018, 02:01

Thank you so much iseahound. I'm going to try it out now.... super super help and much appreciated.

Unlocks a whole new load of opportunity with this tool now!
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - OCR() - Update: Additional Language Support

19 Mar 2018, 02:05

You're welcome! Let me know - I built tesseract 4.0 on my windows machine, so there is a possibility it might not work.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Vis2 - OCR() - Update: Additional Language Support

19 Mar 2018, 09:21

Hi iseahound,
unfortunately it didn't work for me. The preview mode is showing the correct/captured area but the function didn't return any text.
I've tried several other options (see below) none of them worked/returned any text [Vis2.ahk/Gdip_All.ahk/AHK1.1.26.x/Win7].
Thx for your support :)

Code: Select all

#r::MsgBox % OCR("https://i.stack.imgur.com/sFPWe.png")
#c::MsgBox % test := OCR()
#g::Vis2.OCR.google()
#m::MsgBox % OCR("C:\Program Files\AHK\Vis2-master\sFPWe.png")
#x::MsgBox % OCR(, "eng+deu")
#k::MsgBox % test := OCR("C:\Program Files\AHK\_Kassenzettel\img20180319_12410579.png",,[0,0,932,3510])
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - OCR() - Update: Additional Language Support

19 Mar 2018, 18:55

I added a new version of tesseract.exe. It should provide Windows 7 support. However, I do not have access to a windows 7 machine, so please report back if it works.

EDIT: Fixed Vis2.OCR.google(), however, you could use, and should use OCR().google()!
I also realigned the saved to clipboard message to be above the preview text. Also, the preview text now displays the correct text copied to clipboard. There was a bug where it wasn't.
r2997790
Posts: 71
Joined: 02 Feb 2017, 02:46

Re: Vis2 - OCR() - Update: Additional Language Support

20 Mar 2018, 07:16

I didn't work for me yesterday BUT after downloading Iseahound new build overnight it now works with the foreign languages and is even more awesome then before! Thank you so much.

(I had to download new build, including Tesseract... I'm running Windows 10).
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - OCR() - Update: Additional Language Support

20 Mar 2018, 11:16

I appreciate the confirmation, r2997790. Now I'll need Bobo or another windows 7 user to report back if it works for them.

I'm glad people find my pet project to be useful.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Vis2 - OCR() - Update: Additional Language Support

20 Mar 2018, 15:19

Hi iseahound, I'm not having any luck with Win7 64-bit, AHK_L 1.1.28.00, either 32-bit or 64-bit.
I cloned the github repository and ran a script with the following code (from GitHub):

Code: Select all

#include Vis2.ahk
MsgBox % OCR("https://i.stack.imgur.com/sFPWe.png")
Only a blank message box appears. I visited the link to verify that there is text there to work on, and of course there is.
Regards,
burque505

Edit: I just ran the version from roughly December 4, 2017, and it works fine:
Capture.PNG
Capture.PNG (44.94 KiB) Viewed 6310 times
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - OCR() - Update: Additional Language Support

20 Mar 2018, 17:34

I think you need to have Microsoft Visual C++ 2017 Redistributable (x86) installed. Link: https://aka.ms/vs/15/release/vc_redist.x86.exe

It does bother me that the original executable worked on most versions of windows. I think it probably supported 2013, but I'm not sure how to target that. To be honest, I might be reaching the extent of my current ability

If this does solve the issue, let me know!
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Vis2 - OCR() - Update: Additional Language Support

20 Mar 2018, 17:42

I'm on android ATM, so can't test it before tomorrow 01:30 PM CET. Stay tuned 8-)
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Vis2 - OCR() - Update: Additional Language Support

21 Mar 2018, 07:59

Hi iseahound, I installed the C++ redistributable from the link, but no luck.
I also tried replacing the bin folder with the bin folder from the December 2017 version, still no luck.
Regards,
burque505
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Vis2 - OCR() - Update: Additional Language Support

21 Mar 2018, 09:10

Re-installed from here: https://github.com/iseahound/Vis2/archive/master.zip
But once executed, following the instructions here: https://github.com/iseahound/Vis2
... I ended up with the (kinda expected) error message about ~"[tesseract] not compatible with the system ...".
I'd guess it's (still) compiled as a 32bit executable not running on (my) Win 7 64bit with AHKU64.exe :|
Using the tesseract.exe from a few days ago is showing up empty results but won't fail during execution.

Constructive critic:
a) while the "(file in) folder structure" setup is explicitly mentioned/advised here: https://autohotkey.com/boards/viewtopic ... 89#p168389
b) ... it's shown differently here: https://github.com/iseahound/Vis2
c) ... and it extracts from the zip the same way as described in b) not as in a)
:shifty:

Question, why not already provide the file you've advised to create manually (let's name it "my.ahk") ...
  • "Create a new AHK script in the same folder as Vis2.ahk, copying the code below."

Code: Select all

   #include %A_ScriptDir%\lib\Vis2.ahk
    MsgBox % OCR("https://i.stack.imgur.com/sFPWe.png")
... within the zip-archive that gets extracted to Vis2's root folder, while Vis2.ahk itself will be hosted within the lib-folder (together with a local copy of an image and Gdip_All.ahk)
Based on that, the #Include-path within my.ahk would have been adjusted to point to Vis2.ahk in the lib-folder accordingly. All except the "capture text manually"-samples could be already part of my.ahk!
That would provide the user that "WOW"-effect right from scratch, and would decrease the number of support requests bc of errors made by the most error-prone part of scripting: me in front of the keyboard 8-)
FabXP

Re: Vis2 - OCR() - Update: Additional Language Support

21 Mar 2018, 21:30

Hello! :-)

Is there any way to use image-files as input?

I mean: Example:
I have a text with smileys in them. I'd like the OCR to translate the smiley to a special word. E.g.:

:geek: -----OCR engine-----> "[smiley-geek]"

So basically I'd like to combine image search with normal OCR. And "train" the OCR engine to translate special graphical elements to special alphanumeric sequences. In other words, I'd like to add "custom characters", which are little image files.

Can this somehow be done with this library?

Sorry for the probable quite newbish question! :roll: :oops:
Thanks for any info or help!!!!
Fab

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 120 guests