Vis2 - Image to Text OCR()

Post your working scripts, libraries and tools
paulpma
Posts: 19
Joined: 08 Sep 2018, 22:05

Re: Vis2 - Image to Text OCR()

16 Sep 2018, 01:43

Hi, Iseahound,

Speaking of accuracy, I was thinking of using blacklist and creating two different ocr()'s. One for alpha and one for numeric. Is there a blacklist function like whitelist?

Thank you.
iseahound
Posts: 460
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Vis2 - Image to Text OCR()

24 Nov 2018, 19:04

Update: There is some heavy development going on at the moment. Going forward, there will be less of a dependence on Tesseract. Just a reminder that this project is not dead.
robodesign
Posts: 519
Joined: 30 Sep 2017, 03:59
Facebook: marius.sucan
GitHub: mariussucan
Location: Romania
Contact:

Re: Vis2 - Image to Text OCR()

26 Nov 2018, 14:49

Very good to hear this!

Good luck and thank you for developing it further.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
My home page.
User avatar
hasantr
Posts: 268
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Vis2 - Image to Text OCR()

27 Nov 2018, 03:22

Hi, I like this work very much. Thank you.
My English is not good.

I don't understand how to run this function from a macro I created.

I want to send the coordinates and copy the text. But how.

Thanks.
User avatar
adegard
Posts: 77
Joined: 24 Nov 2017, 05:58
GitHub: adegard

Re: Vis2 - Image to Text OCR()

27 Nov 2018, 04:14

iseahound wrote:
24 Nov 2018, 19:04
Update: There is some heavy development going on at the moment. Going forward, there will be less of a dependence on Tesseract. Just a reminder that this project is not dead.
I tried the tool and it gives excellent result. I hope new development could reduce package size (24 Mo)and dependences
Thank you so much!
User avatar
Frosti
Posts: 258
Joined: 27 Oct 2017, 14:30
GitHub: Ixiko

Re: Vis2 - Image to Text OCR()

03 Jan 2019, 14:33

Hello Iseahound, I like your tesseract wrapper and I'am watching your progress since month's. I'am using your library for some experiments with pdf files.
I missed a solution to use my own leptonica and tesseract directory's. More than about 3 times I changed your Vis2.ahk file at this position to the path's I use.

Code: Select all


      class Tesseract {

         static leptonica := A_ScriptDir "\bin\leptonica_util\leptonica_util.exe"
         static tesseract := A_ScriptDir "\bin\tesseract\tesseract.exe"
         static tessdata_best := A_ScriptDir "\bin\tesseract\tessdata_best"
         static tessdata_fast := A_ScriptDir "\bin\tesseract\tessdata_fast"

Today I just wanted to write a function in the hope that you find this useful. The function will write's the path of tesseract, tessdata and leptonica_util to an .ini file.
If someone want to use tesseract from your repository the function will write and read relative path's. So you can leave a ready made .ini file in your \lib directory of your repository.
Is this file is deleted or some key are deleted or missed, my function will ask for it.

This is an ini-file with relative paths:

Code: Select all

[leptonica]
exePath=\bin\leptonica_util\leptonica_util.exe
[tesseract]
exePath=\bin\tesseract\tesseract.exe
data_best=\bin\tesseract\tessdata_best
tessdata_fast=\bin\tesseract\tessdata_fast
Part1:

Code: Select all


      class Tesseract {

         static leptonica     		:= Vis2.stdlib.paths("leptonica")
         static tesseract     		:= Vis2.stdlib.paths("tesseract")
         static tessdata_best	    := Vis2.stdlib.paths("tessdata_best")
         static tessdata_fast		:= Vis2.stdlib.paths("tessdata_fast")

           ...

Part2:

Code: Select all

   class stdlib {

           ...
   
      ; for user customable paths to leptonica and tesseract
       paths(toWhat){
                      
			static lastdir
			
            If Instr(toWhat, "leptonica")
            {
					 IniRead, leptonica, % A_ScriptDir "\lib\Vis2.ini", leptonica, exePath
					 If ( (leptonica="ERROR") or !InStr(leptonica, "leptonica_util.exe") )
					 {
						   Vis2.Graphics.Subtitle.Render("You have not specified a path to leptonica_util.exe.`nPlease select the file now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
						   again:=1
						   While (again=1)
						   {
								 FileSelectFile, leptonica,, C:, Please select leptonica.exe, *.exe
								 If InStr(leptonica, "leptonica_util.exe")
										  again=0
						   }
						   If Instr(leptonica, A_ScriptDir)
						   		 leptonica:= StrReplace(leptonica, A_ScriptDir)
						   IniWrite, % leptonica, % A_ScriptDir "\lib\Vis2.ini", leptonica, exePath
						   If ErrorLevel
								 throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
					 }

					 lastDir:= Vis2.stdlib.GetParentDir(leptonica)
					 return SubStr(leptonica, 1, 1) = "\" ? A_ScriptDir . leptonica : leptonica
            }
			
            If Instr(toWhat, "tesseract")
            {
					 IniRead, tesseract, % A_ScriptDir "\lib\Vis2.ini", tesseract, exePath
					 If ( (tesseract="ERROR") or !InStr(tesseract, "tesseract.exe") )
					 {
						   Vis2.Graphics.Subtitle.Render("You have not specified a path to tesseract.exe.`nPlease select the file now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
						   again:=1
						   While (again=1)
						   {
								 FileSelectFile, tesseract,, % lastDir, Please select tesseract.exe, *.exe
								 If InStr(tesseract, "tesseract.exe")
												again=0
						   }
						   If Instr(tesseract, A_ScriptDir)
						   		 tesseract:= StrReplace(tesseract, A_ScriptDir)
						   IniWrite, % tesseract, % A_ScriptDir "\lib\Vis2.ini", tesseract, exePath
							If ErrorLevel
								 throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
					 }
					 lastDir:= Vis2.stdlib.GetParentDir(tesseract)
					 return SubStr(tesseract, 1, 1) = "\" ? A_ScriptDir . tesseract : tesseract
            }
			
            If Instr(toWhat, "tessdata_best")
            {
					 IniRead, tessdata_best, % A_ScriptDir "\lib\Vis2.ini", tesseract, data_best
					 If (tessdata_best="ERROR") 
					 {
						   Vis2.Graphics.Subtitle.Render("You have not specified a path to tessdata_best.`nPlease select the path now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
						   again:=1
						   While (again=1)
						   {
								 FileSelectFolder, tessdata_best, % lastDir, 2, Please select path to tessdata_best
								 again:=ErrorLevel
						   }
						   If Instr(tessdata_best, A_ScriptDir)
						   		 tessdata_best:= StrReplace(tessdata_best, A_ScriptDir)
						   IniWrite, % tessdata_best, % A_ScriptDir "\lib\Vis2.ini", tesseract, data_best
						   If ErrorLevel
							  throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
					 }
					 lastDir:= Vis2.stdlib.GetParentDir(tessdata_best)
					 return SubStr(tessdata_best, 1, 1) = "\" ? A_ScriptDir . tessdata_best : tessdata_best
            }
			
            If Instr(toWhat, "tessdata_fast") 
            {
					 IniRead, tessdata_fast, % A_ScriptDir "\lib\Vis2.ini", tesseract, tessdata_fast
					 If (tessdata_fast="ERROR")
					 {
						   Vis2.Graphics.Subtitle.Render("You have not specified a path to tessdata_fast.`nPlease select the path now!", "t7000 xCenter y5% p1.35% c88EAB6 r8", "s2.23% cBlack")
						   again:=1
						   While (again=1)
						   {
								 FileSelectFolder, tessdata_fast, % lastDir, 2, Please select path to tessdata_fast
								 again:=ErrorLevel
						   }
						   If Instr(tessdata_fast, A_ScriptDir)
						   		 tessdata_fast:= StrReplace(tessdata_fast, A_ScriptDir)
						   IniWrite, % tessdata_fast, % A_ScriptDir "\lib\Vis2.ini",  tesseract, tessdata_fast
						   If ErrorLevel
							  throw Exception("Can not write to ini file!",, A_ScriptDir "\lib\Vis2.ini")
					 }
					 return SubStr(tessdata_fast, 1, 1) = "\" ? A_ScriptDir . tessdata_fast : tessdata_fast
            }
           
      }
   
	  ; small RegEx function to get parent dir from a given string
	  GetParentDir(Dir){                                                                                                    	
			Return RegExReplace(Dir, "\\[^\\]+$")
	  }
   
   }

   class Text {
blue83
Posts: 41
Joined: 11 Apr 2018, 06:38

Re: Vis2 - Image to Text OCR()

03 Feb 2019, 03:06

Hi,

First, Iseahound this is a beautiful tool, thank you for that.

Second, is there a way to find coordinate position of string that I am searching for.

Usually there is only one unique string, but somethimes there are few of them on same page.
blue83
Posts: 41
Joined: 11 Apr 2018, 06:38

Re: Vis2 - Image to Text OCR()

03 Feb 2019, 07:36

And one more question is how to increase limit of characters to be able read the whole picture from once?

For now I only get part of the page as a result.
automatLife84
Posts: 23
Joined: 11 Jan 2019, 18:42

Re: Vis2 - Image to Text OCR()

18 Mar 2019, 04:33

hi, i'm tryng to use it, after download ai have runned demo.ahk but i have the following error.

i use SciTE4AutoHotkey
Version 3.0.06.01
Attachments
errore_vis2.png
errore_vis2.png (67.16 KiB) Viewed 1724 times
gregster
Posts: 2946
Joined: 30 Sep 2013, 06:48

Re: Vis2 - Image to Text OCR()

18 Mar 2019, 04:52

automatLife84 wrote:
18 Mar 2019, 04:33
hi, i'm tryng to use it, after download ai have runned demo.ahk but i have the following error.
The syntax for the directive is #include ...
(copy/paste error )
automatLife84
Posts: 23
Joined: 11 Jan 2019, 18:42

Re: Vis2 - Image to Text OCR()

18 Mar 2019, 05:51

Sorry for the distraction error.
with the #include directive the error persists
Attachments
errore_vis2.png
errore_vis2.png (67.43 KiB) Viewed 1689 times
gregster
Posts: 2946
Joined: 30 Sep 2013, 06:48

Re: Vis2 - Image to Text OCR()

18 Mar 2019, 07:27

automatLife84 wrote:
18 Mar 2019, 05:51
with the #include directive the error persists
Since the error message doesn't say "Function library not found.", but "not ... recognized action", my best guess is that your AHK version is ancient, pre-2011.
The used syntax with <...> was introduced in [v1.0.90+], September 2010. If that's the case, either update or use one of the older syntax alternatives.
automatLife84
Posts: 23
Joined: 11 Jan 2019, 18:42

Re: Vis2 - Image to Text OCR()

18 Mar 2019, 08:06

i have update the directive code like this
#include %A_ScriptDir%\lib\Vis2.ahk

but i have the same error :(
automatLife84
Posts: 23
Joined: 11 Jan 2019, 18:42

Re: Vis2 - Image to Text OCR()

18 Mar 2019, 11:46

i have unistall and reinstalled ahk + scite and now work
thanks
automatLife84
Posts: 23
Joined: 11 Jan 2019, 18:42

Re: Vis2 - Image to Text OCR()

19 Mar 2019, 03:52

thanks for this great script.
it's possible when whe put Screen Coordinates as an Array to display a rectangle box to display te selection Coordinates
text:= OCR([0, 100, 200, 150])

thanks in advance
0x00
Posts: 79
Joined: 22 Jan 2019, 13:12

Re: Vis2 - Image to Text OCR()

19 Mar 2019, 20:42

Love this lib, but I use GNU aspell http://aspell.net to filter the output to have little to no misspellings or errors, just thought you'd want to consider integrating it, or functionality similar to further refining the output of tesseract. It's free, command line, open source & supports multiple languages though, but maybe you could even use COM to use the office spell checker, anyway, just suggestions & thanks for this brilliant wrapper :salute:
iseahound
Posts: 460
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Vis2 - Image to Text OCR()

19 Mar 2019, 21:56

Currently working on a Graphics library to help display important information. Thanks everyone for using this!
automatLife84
Posts: 23
Joined: 11 Jan 2019, 18:42

Re: Vis2 - Image to Text OCR()

21 Mar 2019, 09:21

i love this lib, it save my life.. it's possible to return the Screen Coordinates of a searched text ?
slovakia
Posts: 21
Joined: 12 Apr 2017, 09:33

Re: Vis2 - Image to Text OCR()

10 Jun 2019, 22:41

Some computer when run error with this code :
---------------------------
demo.ahk
---------------------------
Error at line 42 in #include file "C:\Users\admin\Desktop\Vis2-master\Lib\JSON.ahk".

Line Text: JSON.Functor
Error: Unknown class.

The program will exit.
---------------------------
OK
---------------------------
how can i Fixit
Evaexe
Posts: 1
Joined: 22 Jun 2019, 03:38

Re: Vis2 - Image to Text OCR()

22 Jun 2019, 03:46

Hello mate !
Just a litte question,

How can i get x,y and width and Height ?

Do you know a software where i can draw an array and it get back the vallues ?


Thanks,

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 56 guests