Vis2 - Image to Text OCR()

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

Re: Vis2 - Image to Text OCR()

09 Jun 2022, 22:11

Not clear what you mean. This is my guess as to what you want:

Code: Select all

buf := ImagePutBuffer([100, 100, 200, 200]) ; Read from screen
if buf.PixelSearch(0xFF0000) ; Search for red pixel
   OCR(buf) ; Send Bitmap
buf := "" ; cleanup
Actually if you are talking about a window in the background try:

Code: Select all

buf := ImagePutBuffer({window: "Untitled - Notepad", crop:[0,0,150,100]) ; width: 150, height: 100
if buf.PixelSearch(0xFF0000) ; Search for red pixel
   OCR(buf) ; Send Bitmap
buf := "" ; cleanup
Using ImagePutBuffer is highly efficient as it only does window capture once. Also, Vis2 now uses ImagePut anyways lol. It's like 10x better than what Vis2 was previously using.

Supported Inputs: https://github.com/iseahound/ImagePut/wiki/Input-Types-&-Output-Functions#input-types
User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Re: Vis2 - Image to Text OCR()

10 Jun 2022, 08:00

iseahound wrote:
09 Jun 2022, 22:11
Not clear what you mean. This is my guess as to what you want:

Code: Select all

buf := ImagePutBuffer([100, 100, 200, 200]) ; Read from screen
if buf.PixelSearch(0xFF0000) ; Search for red pixel
   OCR(buf) ; Send Bitmap
buf := "" ; cleanup
Actually if you are talking about a window in the background try:

Code: Select all

buf := ImagePutBuffer({window: "Untitled - Notepad", crop:[0,0,150,100]) ; width: 150, height: 100
if buf.PixelSearch(0xFF0000) ; Search for red pixel
   OCR(buf) ; Send Bitmap
buf := "" ; cleanup
Using ImagePutBuffer is highly efficient as it only does window capture once. Also, Vis2 now uses ImagePut anyways lol. It's like 10x better than what Vis2 was previously using.

Supported Inputs: https://github.com/iseahound/ImagePut/wiki/Input-Types-&-Output-Functions#input-types
Yes, this is exactly what I want. Thank you for your interest. :bravo: Also, I'm typing using Google translate. I am sorry for this.
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - Image to Text OCR()

11 Jun 2022, 00:48

There is an excellent guide on ImagePut in chinese here: https://www.autoahk.com/archives/37246
fiendhunter
Posts: 141
Joined: 24 Jul 2019, 15:27

Re: Vis2 - Image to Text OCR()

11 Jun 2022, 07:07

@iseahound
Hi. Thanks for this OCR, works well. I want to set coordinates from window instead of screen. But I cannot find about coordmode. maybe i missed it. if you can give me tip, ı'd be happy.

Code: Select all

buf := ImagePutBuffer([182,190, 200, 20]) ; the coords from screen, want to set coords for a spesific window
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - Image to Text OCR()

12 Jun 2022, 09:02

Yes the updated syntax as mentioned above is

Code: Select all

OCR({window: "Untitled - Notepad", crop:[0,0,500,500]})
or just OCR("Untitled - Notepad") depending on your use case
fiendhunter
Posts: 141
Joined: 24 Jul 2019, 15:27

Re: Vis2 - Image to Text OCR()

12 Jun 2022, 21:20

iseahound wrote:
12 Jun 2022, 09:02
Yes the updated syntax as mentioned above is

Code: Select all

OCR({window: "Untitled - Notepad", crop:[0,0,500,500]})
or just OCR("Untitled - Notepad") depending on your use case
is crop:[0,0,500,500] x,y,w,h ? it picks wierd rectangle.

input:

Code: Select all

MsgBox % OCR({window: "Notepad1", crop:[183,196, 200, 11]}) ; it output left half of screen. [x0,y0,w1000,h1079]
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - Image to Text OCR()

12 Jun 2022, 23:30

Crop fails and gives you the full image when it does. Is your window title Notepad1? Try using ahk_class instead
fiendhunter
Posts: 141
Joined: 24 Jul 2019, 15:27

Re: Vis2 - Image to Text OCR()

13 Jun 2022, 03:13

iseahound wrote:
12 Jun 2022, 23:30
Crop fails and gives you the full image when it does. Is your window title Notepad1? Try using ahk_class instead
yes, its a test exe named Notepad1 not a real notepad.
Attachments
test.jpg
test.jpg (5.34 KiB) Viewed 4266 times
maxkill
Posts: 173
Joined: 11 Apr 2016, 13:03

Re: Vis2 - Image to Text OCR()

22 Jun 2022, 19:43

Guys as someone already asked but didn't get answered I also wonder same thing kind of.

How can I search to right side of mouse at edge of screen a small rectangle (positioned slightly above and below mousepointer) and translate image there to text?
Find Jesus to be saved. Repent (stop all sinning), believe (the gospel) and get baptised to be saved.
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - Image to Text OCR()

24 Jun 2022, 07:59

If you're searching next to the mouse pointer maybe you can try:

Code: Select all

#c::
CoordMode, Mouse, Screen
MouseGetPos x, y
OCR([x, y, 100, 300]) ; Depends on your font size 
return
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Vis2 - Image to Text OCR()

27 Jun 2022, 10:06

Any one know how to run this from another script.

Include doesn't work.

I would like to call this from another script to use the values optained from clipboard using vis2.

Any ideas?
ahk7
Posts: 591
Joined: 06 Nov 2013, 16:35

Re: Vis2 - Image to Text OCR()

27 Jun 2022, 13:31

I have the following runocr.ahk script in the same folder as the vis2 files, and I simply assigned a hotkey to Run path-to\runocr.ahk now I can do one OCR to the clipboard, after that the scripts exits but text is on the clipboard - If I need to do it again I run it, so no need to include or keep things in memory, just run each time you need it.

Code: Select all

#NoEnv
SetBatchLines, -1
ocr()
Sleep 750
DllCall("SystemParametersInfo", "uInt",0x57, "uInt",0, "uInt",0, "uInt",0) ; RestoreCursor() ; just to be safe
Sleep 100
ExitApp
#include path-to-your-folder\vis2\lib\Vis2.ahk
maxkill
Posts: 173
Joined: 11 Apr 2016, 13:03

Re: Vis2 - Image to Text OCR()

27 Jun 2022, 15:36

@iseahound
Thanks. But it needs to be the same x axis rectangle box every time but the y axis changes according to mouse position like you showed.. and save to clipboard after the image in rectangle is made into the text
Find Jesus to be saved. Repent (stop all sinning), believe (the gospel) and get baptised to be saved.
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - Image to Text OCR()

27 Jun 2022, 19:49

Same thing, really.

Code: Select all

#c::
CoordMode, Mouse, Screen
MouseGetPos x, y
OCR([500, y, 100, 300]).clipboard() ; Depends on your font size. Fix x-axis to 500.
return
maxkill
Posts: 173
Joined: 11 Apr 2016, 13:03

Re: Vis2 - Image to Text OCR()

28 Jun 2022, 16:20

@iseahound
Very cool thanks a lot, will try make it work. Just a thought, your op (--> talking about GITHUB link instructions) says put your script into the same folder as Vis2 but that didn't work. It would be easier to understand if it said extract folder in zip, then put script into that folder (not the Vis2 ahk folder) with the instructions at top to point to the Vis2 ahk. I think it should say 'put the script into same folder as Vis2-master' not the file to be clear.

edit; Dropped the moving axis search box found a way to get the static data instead so reading that now works nicely

It was very tricky to actually get the static search box since the command to get the coordinates for it was set to alt space, which when pressed activates a menu for virtually all folders and apps resulting in aborting the coordinates fetching. I had to literally film the screen to catch a glimps of the coordinates and then replay the video to type them down. It worked though so I'm good :wave: thanks for this helps a lot!

Code: Select all

;search box that is static
#include <Vis2>

f2::
OCR([796, 1, 70, 26]).clipboard() 
return

;Use this to set the size and place for the data 
f7::
   windowx:=558
    windowy:=-23
    windowh:=108
    windoww:=306
    WinGetActiveTitle, Title
    WinActivate, %Title%
    WinRestore, %Title%    
    WinMove, %Title%, , windowx, windowy, windoww, windowh
return

;use this to get the coordinates of the data above that is to be read 
F1::
	WinGetActiveStats, winT, winW, winH, winX, winY
	MsgBox, % "Title of active window:`n" winT "`n`nCoords start at:`nx" winX ", y" winY "`n`nWidth x Height:`n" winW " x " winH
return

;slim the window up
f6::
tog := (!tog)
If (tog)
	WinSet, Style, -0xC00000, A
Else
	WinSet, Style, +0xC00000, A
return
Last edited by maxkill on 30 Jun 2022, 07:31, edited 1 time in total.
Find Jesus to be saved. Repent (stop all sinning), believe (the gospel) and get baptised to be saved.
Krd
Posts: 405
Joined: 10 Mar 2020, 02:46

Re: Vis2 - Image to Text OCR()

30 Jun 2022, 04:42

ahk7
So things may happen inside same folder as VIS2?

I don't like it tis way as you suddenly have several places to put scripts in.
ahk7
Posts: 591
Joined: 06 Nov 2013, 16:35

Re: Vis2 - Image to Text OCR()

30 Jun 2022, 08:32

@Krd No, why would I copy vis2 everywhere? Like I said I RUN A SCRIPT TO START IT, just like you would run Notepad or any other program or other script. Vis2 just works on its own - you can include it but no need to.

Example, you have a vis2 folder only once - somewhere like so:
C:\Scripts\vis2\
C:\Scripts\vis2\demo.ahk
C:\Scripts\vis2\README.md
C:\Scripts\vis2\test.jpg
C:\Scripts\vis2\RunOcr.ahk ; this is the script I posted above - amend the #include vis2.ahk of course
C:\Scripts\vis2\bin\
C:\Scripts\vis2\lib\
You don't edit any vis2 related files at all/ever.

Assuming you have an always running mainscript here:
C:\Scripts\MainScript\AlwaysRunning.ahk
You add a hotkey

Code: Select all

#o::Run C:\Scripts\vis2\RunOcr.ahk
Bob's your uncle.

If you don't have a script always running simply add the "Run" hotkey to any script where you want to make use of OCR
User avatar
vSky
Posts: 80
Joined: 30 May 2022, 10:13

Re: Vis2 - Image to Text OCR()

01 Jul 2022, 14:29

Hi @iseahound ,

I made an automation program using this library and I want to put it up for sale on a local site. I read an article about licensing processes that prevent commercial use, even if it's publicly shared. I have no information about transactions made for commercial use. Is there a valid licensing process for this library? I did not see any information about this in the github content with the topic you opened. Briefly; Is there a problem in selling an application that contains this library? I would be glad if you give information in this regard. Thank you.
iseahound
Posts: 1582
Joined: 13 Aug 2016, 21:04
Contact:

Re: Vis2 - Image to Text OCR()

02 Jul 2022, 18:08

Sure, I have no problems with that. All I ask is that credit is given, and that if I release a AutoHotkey v2 compatible version of this library, you'll need to ask again :)
User avatar
Vis
Posts: 3
Joined: 30 May 2022, 09:02

Re: Vis2 - Image to Text OCR()

03 Jul 2022, 10:21

An amazing tool for what I need it for. Question, is it possible to both send the text extracted from OCR([coords]) to a file? Or would I just need another function that reads from clipboard and does that?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 125 guests