Page 5 of 17

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

Posted: 28 Mar 2018, 13:23
by burque505
Test One.PNG
Test One.PNG (23.66 KiB) Viewed 7138 times
Test Two.PNG
Test Two.PNG (30.08 KiB) Viewed 7138 times
Edit:
iseahound wrote:
@gameba Redownload latest version from GitHub. Vis2 is now compatable with AHK_H
Running DetectBugs.ahk, I get the following error messages using AHK_H 64-bit, 1.1.28.00:

Code: Select all

>"C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "C:\Downloads\Automation\AHK related\Vis2\DetectBugs.ahk"    
C:\Program Files\AutoHotkey\Lib\Gdip_All.ahk (66) : ==> Duplicate function definition.
     Specifically: UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
>Exit code: 2    Time: 0.4351

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

Posted: 28 Mar 2018, 23:21
by iseahound
UPDATE Added error handling code on my GitHub. Also fixed a few bugs. Given that I am unable to reproduce the "blank box" myself, I cannot tell if it has been fixed.

Thanks to all the testers, and people who are willing to respond. As always posting the error message is very helpful.

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

Posted: 28 Mar 2018, 23:29
by iseahound
@burque505 Is it possible that you have two copies of Gdip_All.ahk somewhere? I did not define a second version of UpdateLayeredWindow() I wonder if @gameba encountered this error.

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

Posted: 29 Mar 2018, 07:37
by burque505
Hi iseahound, gdip_all is in my Lib folder (i.e. C:\Program Files\Autohotkey\Lib). Removing Gdip_all.ahk from the github lib folder fixed that part! AHK_H now works, so does AHK_L, at least in theory, because I still have the "blank box."
Now I'll try the new code - oops :(
Win7 SP 64-bit, AHK_L 1.1.28.00 64-bit
Error.PNG
Error.PNG (61.88 KiB) Viewed 7091 times
Then the blank box.
That does give me a clue for spelunking in the code, thanks. Now I'm thinking that somewhere in this leptonica code segment (lines 2025-2027):

Code: Select all

            _cmd .= this.leptonica " " in " " out
            _cmd .= " " negateArg " 0.5 " performScaleArg " " scaleFactor " " ocrPreProcessing " 5 2.5 " ocrPreProcessing  " 2000 2000 0 0 0.0"
            RunWait % ComSpec " /C " _cmd,, Hide
things are going south, on my system at least. I have DPI scaled up to 125%, but the December 2017 version worked fine, so maybe that has nothing to do with it.

Thanks for staying on top of this, iseahound.

Regards,
burque505

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

Posted: 29 Mar 2018, 12:59
by iseahound
@Burque505 Do you have a non-English username? As in C:/Users/%username%

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

Posted: 29 Mar 2018, 14:36
by burque505
No, it's pretty generic English :)

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

Posted: 29 Mar 2018, 15:07
by iseahound
Does replacing

Code: Select all

RunWait % ComSpec " /C " _cmd,, Hide
with

Code: Select all

RunWait % _cmd,, Hide
fix it?

EDIT: what about this?

Code: Select all

RunWait % "cmd /C " _cmd,, Hide

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

Posted: 29 Mar 2018, 15:26
by burque505
Tried both, no luck.

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

Posted: 29 Mar 2018, 15:30
by iseahound
How about commenting out this line?

Code: Select all

         __New(language:=""){
            this.language := language
            ;this.uuid := Vis2.stdlib.CreateUUID()          ; <-- This one
            this.file := A_Temp "\Vis2_screenshot" this.uuid ".bmp"
            this.fileProcessedImage := A_Temp "\Vis2_preprocess" this.uuid ".tif"
            this.fileConvertedText := A_Temp "\Vis2_text" this.uuid ".txt"
         }

EDIT: Just to give you an idea of what I'm doing, and why this bug is so odd.
This is the preprocess function in December 2017

Code: Select all

      preprocess(f_in, f_out){
         static ocrPreProcessing := 1
         static negateArg := 2
         static performScaleArg := 1
         static scaleFactor := 3.5

         RunWait, % Vis2.Tesseract.leptonica " " f_in " " f_out " " negateArg " 0.5 " performScaleArg " " scaleFactor " " ocrPreProcessing " 5 2.5 " ocrPreProcessing  " 2000 2000 0 0 0.0", , Hide
      }
this is it today:

Code: Select all

         preprocess(in:="", out:=""){
            static ocrPreProcessing := 1
            static negateArg := 2
            static performScaleArg := 1
            static scaleFactor := 3.5

            in := (in != "") ? in : this.file
            out := (out != "") ? out : this.fileProcessedImage

            if !(FileExist(in))
               throw Exception("Input image for preprocessing not found.",, in)

            _cmd .= this.leptonica " " in " " out
            _cmd .= " " negateArg " 0.5 " performScaleArg " " scaleFactor " " ocrPreProcessing " 5 2.5 " ocrPreProcessing  " 2000 2000 0 0 0.0"
            RunWait % ComSpec " /C " _cmd,, Hide

            if !(FileExist(out))
               throw Exception("Preprocessing failed.")

            return out
         }
there has been no real changes to the function or to the underlying leptonica.exe.

EDIT #2: https://github.com/iseahound/Vis2/archive/master.zip Added even better error handling code.

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

Posted: 29 Mar 2018, 16:00
by robodesign
Iseahound. How does the accuracy of this compare to Capture2Text? Have you ever tested Capture2Text?

I'm interested in this project...

Thank you for working on this.

Best regards, Marius.

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

Posted: 29 Mar 2018, 16:02
by iseahound
@robodesign It is the same accuracy since we both use the same open source projects, tesseract and leptonica.

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

Posted: 29 Mar 2018, 16:22
by robodesign
Thanks for the quick response.

Capture2Text can automatically select regions to capture text from. For example, a text line underneath the mouse cursor.... Can this script do this as well?

Best regards, Marius.

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

Posted: 30 Mar 2018, 10:49
by burque505
Getting closer, but no luck yet. First I captured the actual _cmd string like this, and stopped execution:

Code: Select all

            fileappend, %_cmd%, Command.txt
            msgbox execute command.txt in leptonica directory
Checking in %temp%, these files were created:
Capture1.PNG
Capture1.PNG (3.81 KiB) Viewed 7018 times
Then I executed the contents of '_cmd' from the command prompt. These files were created:
Capture2.PNG
Capture2.PNG (6.18 KiB) Viewed 7018 times
So the .tif CAN be created.
I put in a 5-second delay, and processing still failed, but this time at the conversion to txt.

EDIT: Honing in on it. Changed the leptonica command to:

Code: Select all

RunWait % _cmd, ,Hide
Now the .tif file gets created in %temp%, and error is now thrown by tesseract, not leptonica.
EDIT: Also changed tesseract runwait to:

Code: Select all

RunWait % _cmd, ,Hide
Still getting tesseract error, but command runs.
EDIT: I used the same "command.txt" strategy to run tesseract in the middle of the process. Here's the result:
CaptureTess.PNG
CaptureTess.PNG (7.1 KiB) Viewed 7013 times
EDIT: The above command will run if I enclose all the parameters in quotes. Now all I need to do is figure out how to get the variables in

Code: Select all

         convert_best(in:="", out:="", fast:=0){
            in := (in) ? in : this.fileProcessedImage
            out := (out) ? out :  this.fileConvertedText
            fast := (fast) ? this.tessdata_fast : this.tessdata_best
enclosed in quotes.

Workaround: No spaces in folder names :)


Regards,
burque505

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

Posted: 30 Mar 2018, 13:50
by burque505
Can't put more than 3 images in a post, so here's a screenshot with the folder names stripped of spaces.
NoSpaces.PNG
NoSpaces.PNG (14.62 KiB) Viewed 7006 times
Win7, 64-bit no changes to script. Just made sure containing folder was named correctly.
Still trying to modify the code so it will accept spaces.
But :dance: it works for now.

Regards,
burque505

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

Posted: 30 Mar 2018, 14:26
by iseahound
burque505 wrote:enclosed in quotes.
That is a very silly mistake I made. I updated a new file, it works with spaces now. Thanks for all the hard work!

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

Posted: 30 Mar 2018, 15:00
by Himmilayah
iseahound wrote:
burque505 wrote:enclosed in quotes.
That is a very silly mistake I made. I updated a new file, it works with spaces now. Thanks for all the hard work!
I hope you can fix it for windows 10 64 bit as well

I am getting a blank box

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

Posted: 30 Mar 2018, 17:21
by burque505
Thank you, iseahound! For me, lines 2002 through 2037 are very instructive on the proper use of 'q' for quoting. Thanks for teaching me.
Spoiler

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

Posted: 30 Mar 2018, 18:54
by iseahound
burque505 wrote:Thank you, iseahound! For me, lines 2002 through 2037 are very instructive on the proper use of 'q' for quoting. Thanks for teaching me.
Spoiler
Does the latest update fix the blank box bug? If so, we can finally lay this bug to rest :D [AHK has its own escape character, but it makes the code impossible to read. Using q := Chr(34) or Chr(0x22) has the benefit of being v2 compatible as well.]

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

Posted: 30 Mar 2018, 22:56
by GeneBene
iseahound wrote:
burque505 wrote:Thank you, iseahound! For me, lines 2002 through 2037 are very instructive on the proper use of 'q' for quoting. Thanks for teaching me.
Spoiler
Does the latest update fix the blank box bug? If so, we can finally lay this bug to rest :D [AHK has its own escape character, but it makes the code impossible to read. Using q := Chr(34) or Chr(0x22) has the benefit of being v2 compatible as well.]
Win 10 64bit blank box, tested on three systems

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

Posted: 31 Mar 2018, 00:27
by iseahound
@GeneBene Did you download the latest version from https://github.com/iseahound/Vis2/archive/master.zip ? Is there an error message? I just tested Vis2 again on Windows 10 64 bit, new install.