Vis2 - OCR(), ImageIdentify()

Post your working scripts, libraries and tools
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

24 Mar 2018, 14:47

BoBo wrote: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") ...

... 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-)


This is good advice and I have implemented it.

Sadly, the current version of tesseract only runs on windows 10. (or windows 7 with the Microsoft Visual C++ 2015 and 2017 redistributable with x86/64-bit for each) The older version of tesseract I was using was targeting the 2008 C++ redistributable, and latest version will not compile on Visual Studio 2008. Rest assured, there are solutions but they will take time, as I will need to slowly learn many things. I will not forget Windows 7 users.
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Re: Vis2 - OCR()

24 Mar 2018, 15:30

rommmcek wrote:Any chance for diacritics on the horizon?

Yes they are now supported.

Johana wrote:Anyway to make it support ÅÄÖ an other special chars?

Done! I assume you are Swedish or Norwegian, so you can try OCR(, "swe") or OCR(, "nor") after downloading swe.traineddata and nor.traineddata from https://github.com/tesseract-ocr/tessdata_best and https://github.com/tesseract-ocr/tessdata_fast

chenzhipeng wrote:Thank you very much, iseahound , But there is some question, how to change the language if I want to use it in Chinese?

Try OCR(, "chi_sim") after downloading chi_sim.traineddata from https://github.com/tesseract-ocr/tessdata_best and https://github.com/tesseract-ocr/tessdata_fast
Place them in the bin\tessdata_best and bin\tessdata_fast folders respectively.

BoBo wrote:.

burque505 wrote:.


Works on Windows 7. I tested on a Windows Server 2008 Google Compute Instance.

Update: Smoother Animations. Should be lag free now.
burque505
Posts: 516
Joined: 22 Jan 2017, 19:37

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

25 Mar 2018, 08:42

Hi iseahound,
Sorry to report that for me with Win7, 64-bit, nothing but a blank message box for demo.ahk.
Tried with 1.1.27.07 32-bit and 64-bit, 1.1.28.00 64-bit, error message regarding GDIP with AHK_H 1.1.28.00 64-bit (that happens with many GDIP scripts).
Regards,
burque505
vikcode

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

25 Mar 2018, 14:46

burque505 wrote:Hi iseahound,
Sorry to report that for me with Win7, 64-bit, nothing but a blank message box for demo.ahk.
Tried with 1.1.27.07 32-bit and 64-bit, 1.1.28.00 64-bit, error message regarding GDIP with AHK_H 1.1.28.00 64-bit (that happens with many GDIP scripts).
Regards,
burque505

I am confirming this to be the case, tested on 2 machines win 10 64bit
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

25 Mar 2018, 15:37

Hello burque505,
I think this is a problem on your end. I tested Vis2.ahk and demo.ahk on Windows 7 (32 bit) (clean install virtual machine) and it is working fine. Both 1.1.27.08 and 1.1.27.07 (32 and 64) are working fine.
burque505
Posts: 516
Joined: 22 Jan 2017, 19:37

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

25 Mar 2018, 17:56

Hi iseahound, maybe you're right. But here's a screenshot from the December version:
Capture.PNG
Capture.PNG (44.94 KiB) Viewed 662 times

And this from today's version:
LatestVersion.PNG
LatestVersion.PNG (21.59 KiB) Viewed 662 times

Same AHK version, same computer :) , same operator.
I'll try to instrument the code a little to see what the variables are going through the process.
EDIT: Rough going, but I think on my machine at least it is croaking at HTTPRequest and req.Send(). I tried running it on XP and got a certificate error, but I suppose it was never meant to support XP.
By the way, at this website you can generate PNGs from text, which might come in handy. I used it to make sure the old version would operate on local files for me, which it does, using the standard windows filepath. Cool.
Regards,
burque505
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

25 Mar 2018, 18:46

if you could download the image at https://i.stack.imgur.com/sFPWe.png, then open cmd and run tesseract --tessdata-dir tessdata_best sFPWe.png output (in the bin folder) and copy any output data that would help me diagnose your problem!

EDIT: I saw your post edit. Is your problem solved? Using OCR(website) was a bit of a fancy decision on my part, it was truly meant to be run on local files.
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

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

25 Mar 2018, 22:12

I get a error
Image

I think Vis2 is not compatible with AHK_H v1, right?
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

25 Mar 2018, 23:30

@gameba Redownload latest version from GitHub. Vis2 is now compatable with AHK_H
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

25 Mar 2018, 23:44

Complete Changelog of Recent Changes so far:
- When releasing the Left Mouse Button, the selection is faster since it now detects if the screenshot has changed before processing.
- Ctrl + Space shows the image window when Space is pressed, not when space is released.
- Lag during image selection where the grey rectangle would stall has been eliminated.
- Using Alt+Space to check the coordinates of the grey square has now been optimized. It will no longer lag everything else.
- Additional Language support has been added.
- Tesseract has been updated to v4.0.0-beta.1. As it is a beta release, there may be issues.
- Vis2 now displays the correct tooltip size on all screen resolutions.
- The duration of the preview text on screen after selection is set at 2.5 seconds.
- When running OCR().google() or Vis2.OCR.google() it will automatically open up the webpage if it is a url.
- works on AHK_H v1
- Multiple calls to OCR(thing) can be run at the same time. You will always be limited to one instance of the graphical user interface. (However, you can run both the GUI and ahk function at the same time)
- there is the ability to crop an image using the 3rd parameter. OCR(image, "eng", [0, 0, 512, 512])
- Comparison of bitmaps now uses RtlCompareMemory() over NumGet, for super fast comparisons.
- Selecting large areas of text is now instant if the image has not changed.
- Fixed a memory leak. Redownload if you have not already.

@burque505 make sure you have a user %temp% folder as well, since the temporary images are stored there. If windows + R typing %temp% gives an error.

@vikcode Can you test the command line bin\tesseract.exe with tesseract --tessdata-dir tessdata_best sFPWe.png output with https://i.stack.imgur.com/sFPWe.png and see if that works?
Last edited by iseahound on 26 Mar 2018, 17:12, edited 1 time in total.
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

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

26 Mar 2018, 00:40

I get a bug, pls run the script below:
If the loop > 2, pBitmapOCR always get a value is 0


Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



AHK latest version
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

26 Mar 2018, 01:04

Added workaround. Bug is due to you calling pToken := Gdip_Startup() and Vis2.ahk as well. When one script calls Gdip twice, many weird bugs can occur. I suggest you use OCR([x,y,w,h]) to the screen directly, or from a file directly. Your code will run normally now.
gameba
Posts: 18
Joined: 20 Mar 2018, 12:24

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

26 Mar 2018, 01:18

iseahound wrote:Added workaround. Bug is due to you calling pToken := Gdip_Startup() and Vis2.ahk as well. When one script calls Gdip twice, many weird bugs can occur. I suggest you use OCR([x,y,w,h]) to the screen directly, or from a file directly. Your code will run normally now.


I need to identify the name of > 1.000.000 images and sort it. OCR([x,y,w,h]) does not suitable in my case.
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

26 Mar 2018, 01:36

Script updated to be fully compatible with a global pToken := Gdip_Startup(). There should be no more bugs now.
Zelna
Posts: 8
Joined: 28 Jul 2016, 09:15

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

26 Mar 2018, 05:41

Great update! Previously if I wanted my script to use both Gdip and Vis2, I had to comment out these 2 lines in Vis2:

Code: [Select all] [Download] GeSHi © Codebox Plus

Startup(){
;return Vis2.Graphics.pToken := (Vis2.Graphics.Gdip++ > 0) ? Vis2.Graphics.pToken : Gdip_Startup()
}

Shutdown(){
;return Vis2.Graphics.pToken := (--Vis2.Graphics.Gdip == 0) ? Gdip_Shutdown(Vis2.Graphics.pToken) : Vis2.Graphics.pToken
}

but now no more (provided that I use a

Code: [Select all] [Download] GeSHi © Codebox Plus

global pToken := Gdip_Startup()
in my script) :)
Also, the Ocr from hwnd (haven't tried the other types) seems much more accurate, but also slower (about 2-3 seconds). I was wondering if its because of a new Tesseract or could it be some change in Vis2 code. It's not a problem for me, just inquiring out of interest.

P.S.
When I ran Ocr the first time after downloading, my AVG antivirus stopped the cmd and scanned it thinking it might be a virus. It hasn't happened again, but I wanted to ask if it might have something to do with the fact that my Tesseract.exe and both eng.traineddata, after downloading, are slightly larger than they are on GitHub?
burque505
Posts: 516
Joined: 22 Jan 2017, 19:37

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

26 Mar 2018, 11:51

Hi iseahound, I ran the command you suggested. Here's the output:

Code: [Select all] [Download] GeSHi © Codebox Plus

[This is a lot of 12 point text to test the
ocr code and see if it works on all types
of file format.

The quick brown dog jumped over the
lazy fox. The quick brown dog jumped
over the lazy fox. The quick brown dog
jumped over the lazy fox. The quick
brown dog jumped over the lazy fox.

I do have a temp folder. I always run as admin, so maybe that's a problem for access to the temp folder - but it didn't throw an error.
I will download the newest version and see if the problem goes away. EDIT: Same problem for me, Win7 SP1, 64-bit
ferryiol

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

27 Mar 2018, 23:37

burque505 wrote:Hi iseahound, I ran the command you suggested. Here's the output:

Code: [Select all] [Download] GeSHi © Codebox Plus

[This is a lot of 12 point text to test the
ocr code and see if it works on all types
of file format.

The quick brown dog jumped over the
lazy fox. The quick brown dog jumped
over the lazy fox. The quick brown dog
jumped over the lazy fox. The quick
brown dog jumped over the lazy fox.

I do have a temp folder. I always run as admin, so maybe that's a problem for access to the temp folder - but it didn't throw an error.
I will download the newest version and see if the problem goes away. EDIT: Same problem for me, Win7 SP1, 64-bit


same exact issue in windows 10 64bit it shows a blank box
iseahound
Posts: 239
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

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

28 Mar 2018, 04:36

To everyone who is troubled by the blank box: I cannot reproduce it, so please run this script which will tell me what is going wrong:


DetectBugs.ahk

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



You should see "Success" and "Success #2" or two error messages. If Vis2 is working, you should also see test.jpg converted into text.
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

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

28 Mar 2018, 06:55

"No text file found 1+2" :cry:
Georgie Munteer

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

28 Mar 2018, 07:45

test1 no text file found test2 no text file found

Return to “Scripts and Functions”

Who is online

Users browsing this forum: binghez, cocobanana and 17 guests